Skip to content

Commit

Permalink
Merge pull request #19 from niftykit-inc/winter-presale-wallet
Browse files Browse the repository at this point in the history
adds presale wallet with input
  • Loading branch information
jcurbelo authored Aug 18, 2022
2 parents 8c50398 + 563e097 commit 1dc4f45
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export namespace Components {
"mintQuantity": string;
"mintText": string;
"openModal": () => Promise<void>;
"presaleConnect": boolean;
/**
* Winter Project Id
*/
Expand Down Expand Up @@ -231,6 +232,7 @@ declare namespace LocalJSX {
"mintText"?: string;
"onClose"?: (event: CustomEvent<boolean>) => void;
"onSuccess"?: (event: CustomEvent<any>) => void;
"presaleConnect"?: boolean;
/**
* Winter Project Id
*/
Expand Down
4 changes: 4 additions & 0 deletions src/components/nk-winter-checkout/nk-winter-checkout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
nk-loading {
margin-top: 5px;
}

.wallet-address-value {
margin-bottom: 10px;
}
78 changes: 58 additions & 20 deletions src/components/nk-winter-checkout/nk-winter-checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class NKWinterCheckout {
*/
@Prop() projectId!: string;

@Prop() presaleConnect: boolean = false;
@Prop() walletAddress: string = null;
@Prop() email: string = null;
@Prop() mintQuantity: string = null;
Expand All @@ -43,6 +44,7 @@ export class NKWinterCheckout {
@State() extraMintParams: Record<string, string | number | string[] | undefined> = null;
@State() priceFunctionParams: Record<string, string | number | string[] | undefined> = null;
@State() disabled = false;
@State() presale = false;

@Event() close: EventEmitter<boolean>;
@Event() success: EventEmitter;
Expand Down Expand Up @@ -109,9 +111,24 @@ export class NKWinterCheckout {
);
};

const WalletAddress = () => {
if (!this.presale || this.presaleConnect) {
return null;
}
return (
<div part="wallet-address-container" class="wallet-address">
<div part="wallet-address-label" class="wallet-address-label">
Wallet Address
</div>
<input part="wallet-address-input" class="wallet-address-value" value={this.walletAddress} onInput={(e: any) => (this.walletAddress = e.target.value)} />
</div>
);
};

return (
<Host>
<NkMsg />
<WalletAddress />
<div part="wallet-btn-container" class="mdc-touch-target-wrapper">
<button
onClick={() => this.openModal()}
Expand All @@ -134,32 +151,52 @@ export class NKWinterCheckout {
async openModal(): Promise<void> {
this.loading = true;
try {
const presale = await this.drop.presaleActive();
if (presale) {
const providers = this.getProviders();
// creates new drop with signer
this.drop = await Dropkit.create(this.apikey, this.dev, providers);
if (this.isMobile() && this.drop.ethInstance?.on) {
this.drop.ethInstance.on('chainChanged', async () => {
this.msg = { error: false, text: 'Switching networks...' };
window.location.reload();
});
if (this.presale) {
if (this.presaleConnect) {
await this.startPresaleFromSigner();
} else {
await this.startPresaleFromInput();
}
const proof = await this.drop.generateProofV2();
if (proof.message) {
throw new Error(proof.message); // not part of presale
}
this.walletAddress = this.drop.walletAddress;
this.extraMintParams = {
allowed: proof.allowed,
merkleProof: proof.proof,
};
}
this.isOpen = true;
} catch (e) {
this.loading = false;
this.msg = { error: true, text: e.message };
}
this.isOpen = true;
}

private async startPresaleFromSigner(): Promise<void> {
const providers = this.getProviders();
// creates new drop with signer
this.drop = await Dropkit.create(this.apikey, this.dev, providers);
if (this.isMobile() && this.drop.ethInstance?.on) {
this.drop.ethInstance.on('chainChanged', async () => {
this.msg = { error: false, text: 'Switching networks...' };
window.location.reload();
});
}
const proof = await this.drop.generateProofV2();
if (proof.message) {
throw new Error(proof.message); // not part of presale
}
this.walletAddress = this.drop.walletAddress;
this.extraMintParams = {
allowed: proof.allowed,
merkleProof: proof.proof,
};
}

private async startPresaleFromInput(): Promise<void> {
this.drop.walletAddress = this.walletAddress;
const proof = await this.drop.generateProofV2();
if (proof.message) {
throw new Error(proof.message); // not part of presale
}
this.walletAddress = this.drop.walletAddress;
this.extraMintParams = {
allowed: proof.allowed,
merkleProof: proof.proof,
};
}

private async initDrop(): Promise<void> {
Expand All @@ -180,6 +217,7 @@ export class NKWinterCheckout {
this.disabled = true;
throw new Error('Sale is not active');
}
this.presale = await this.drop.presaleActive();
}
} catch (e) {
this.msg = { error: true, text: e.message };
Expand Down
12 changes: 8 additions & 4 deletions src/components/nk-winter-checkout/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
| `erc1155Video` | `erc-1-1-5-5-video` | | `string` | `null` |
| `mintQuantity` | `mint-quantity` | | `string` | `null` |
| `mintText` | `mint-text` | | `string` | `'Mint With Card'` |
| `presaleConnect` | `presale-connect` | | `boolean` | `false` |
| `projectId` _(required)_ | `project-id` | Winter Project Id | `string` | `undefined` |
| `projectTitle` | `project-title` | | `string` | `null` |
| `walletAddress` | `wallet-address` | | `string` | `null` |
Expand Down Expand Up @@ -44,10 +45,13 @@ Type: `Promise<void>`

## Shadow Parts

| Part | Description |
| ------------------------ | ----------- |
| `"wallet-btn-container"` | |
| `"winter-btn"` | |
| Part | Description |
| ---------------------------- | ----------- |
| `"wallet-address-container"` | |
| `"wallet-address-input"` | |
| `"wallet-address-label"` | |
| `"wallet-btn-container"` | |
| `"winter-btn"` | |


## Dependencies
Expand Down

0 comments on commit 1dc4f45

Please sign in to comment.