Skip to content

Commit 0d7728e

Browse files
committed
show 2 steps for airdrop
1 parent 7a1767e commit 0d7728e

File tree

5 files changed

+51
-29
lines changed

5 files changed

+51
-29
lines changed

apps/dashboard/src/@/analytics/report.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ export function reportAssetCreationFailed(
374374
| "deploy-contract"
375375
| "set-claim-conditions"
376376
| "mint-tokens"
377-
| "airdrop-tokens";
377+
| "airdrop-tokens"
378+
| "approve-airdrop-tokens";
378379
}
379380
),
380381
) {

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/create-token-page-impl.tsx

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -176,34 +176,23 @@ export function CreateTokenAssetPage(props: {
176176
const account = getAccount(gasless);
177177
const contract = getDeployedContract({ chain: values.chain });
178178

179-
const totalAmountToAirdrop = values.airdropAddresses.reduce(
180-
(acc, recipient) => acc + BigInt(recipient.quantity),
181-
0n,
182-
);
183-
184-
// approve entrypoint to spend tokens
185-
186179
try {
187-
const entrypoint = await getDeployedEntrypointERC20({
180+
const airdropTx = await distributeToken({
188181
chain: contract.chain,
189182
client: props.client,
190-
});
191-
192-
if (!entrypoint) {
193-
throw new Error("Entrypoint not found");
194-
}
195-
196-
const approvalTx = approve({
197-
amountWei: toWei(totalAmountToAirdrop.toString()),
198-
contract: contract,
199-
spender: entrypoint.address,
183+
contents: values.airdropAddresses.map((recipient) => ({
184+
amount: BigInt(recipient.quantity),
185+
recipient: recipient.address,
186+
})),
187+
tokenAddress: contract.address,
200188
});
201189

202190
await sendAndConfirmTransaction({
203191
account,
204-
transaction: approvalTx,
192+
transaction: airdropTx,
205193
});
206194
} catch (e) {
195+
console.error(e);
207196
const errorMessage = parseError(e);
208197

209198
reportAssetCreationFailed({
@@ -212,27 +201,44 @@ export function CreateTokenAssetPage(props: {
212201
error: errorMessage,
213202
step: "airdrop-tokens",
214203
});
215-
216204
throw e;
217205
}
206+
}
207+
208+
async function approveAirdropTokens(params: {
209+
values: CreateAssetFormValues;
210+
gasless: boolean;
211+
}) {
212+
const { values, gasless } = params;
213+
const account = getAccount(gasless);
214+
const contract = getDeployedContract({ chain: values.chain });
215+
216+
const totalAmountToAirdrop = values.airdropAddresses.reduce(
217+
(acc, recipient) => acc + BigInt(recipient.quantity),
218+
0n,
219+
);
218220

219221
try {
220-
const airdropTx = await distributeToken({
222+
const entrypoint = await getDeployedEntrypointERC20({
221223
chain: contract.chain,
222224
client: props.client,
223-
contents: values.airdropAddresses.map((recipient) => ({
224-
amount: BigInt(recipient.quantity),
225-
recipient: recipient.address,
226-
})),
227-
tokenAddress: contract.address,
225+
});
226+
227+
if (!entrypoint) {
228+
throw new Error("Entrypoint not found");
229+
}
230+
231+
const approvalTx = approve({
232+
amountWei: toWei(totalAmountToAirdrop.toString()),
233+
contract: contract,
234+
spender: entrypoint.address,
228235
});
229236

230237
await sendAndConfirmTransaction({
231238
account,
232-
transaction: airdropTx,
239+
transaction: approvalTx,
233240
});
234241
} catch (e) {
235-
console.error(e);
236242
const errorMessage = parseError(e);
237243

238244
reportAssetCreationFailed({
@@ -241,6 +247,7 @@ export function CreateTokenAssetPage(props: {
241247
error: errorMessage,
242248
step: "airdrop-tokens",
243249
});
250+
244251
throw e;
245252
}
246253
}
@@ -252,6 +259,7 @@ export function CreateTokenAssetPage(props: {
252259
createTokenFunctions={{
253260
airdropTokens,
254261
deployContract,
262+
approveAirdropTokens,
255263
}}
256264
onLaunchSuccess={(params) => {
257265
createTokenOnUniversalBridge({

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/create-token-page.client.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type CreateTokenFunctions = {
2828
contractAddress: string;
2929
}>;
3030
airdropTokens: (values: CreateTokenFunctionsParams) => Promise<void>;
31+
approveAirdropTokens: (values: CreateTokenFunctionsParams) => Promise<void>;
3132
};
3233

3334
export function CreateTokenAssetPageUI(props: {

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/create-token-page.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const mockCreateTokenFunctions: CreateTokenFunctions = {
2929
airdropTokens: async () => {
3030
await new Promise((resolve) => setTimeout(resolve, 1000));
3131
},
32+
approveAirdropTokens: async () => {
33+
await new Promise((resolve) => setTimeout(resolve, 1000));
34+
},
3235
deployContract: async () => {
3336
await new Promise((resolve) => setTimeout(resolve, 1000));
3437
return { contractAddress: "0x123" };

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/launch/launch-token.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { TokenDistributionBarChart } from "../distribution/token-distribution";
3939

4040
const stepIds = {
4141
"airdrop-tokens": "airdrop-tokens",
42+
"approve-airdrop-tokens": "approve-airdrop-tokens",
4243
"deploy-contract": "deploy-contract",
4344
"mint-tokens": "mint-tokens",
4445
"set-claim-conditions": "set-claim-conditions",
@@ -97,6 +98,12 @@ export function LaunchTokenStatus(props: {
9798
];
9899

99100
if (formValues.airdropEnabled && formValues.airdropAddresses.length > 0) {
101+
initialSteps.push({
102+
id: stepIds["approve-airdrop-tokens"],
103+
label: "Approve spending tokens for airdrop",
104+
status: { type: "idle" },
105+
});
106+
100107
initialSteps.push({
101108
id: stepIds["airdrop-tokens"],
102109
label: "Airdrop tokens",
@@ -123,6 +130,8 @@ export function LaunchTokenStatus(props: {
123130
setContractAddress(result.contractAddress);
124131
} else if (stepId === "airdrop-tokens") {
125132
await createTokenFunctions.airdropTokens(params);
133+
} else if (stepId === "approve-airdrop-tokens") {
134+
await createTokenFunctions.approveAirdropTokens(params);
126135
}
127136
}
128137

0 commit comments

Comments
 (0)