Skip to content

Commit 4f457e9

Browse files
committed
add POST v1/tokens after coin creation
1 parent 2702e39 commit 4f457e9

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { ThirdwebClient } from "thirdweb";
2+
import { isProd } from "@/constants/env-utils";
3+
4+
export async function createTokenOnUniversalBridge(params: {
5+
chainId: number;
6+
tokenAddress: string;
7+
client: ThirdwebClient;
8+
}) {
9+
const domain = isProd ? "thirdweb.com" : "thirdweb-dev.com";
10+
const res = await fetch(
11+
`https://bridge.${domain}/v1/tokens?chainId=${params.chainId}&tokenAddress=${params.tokenAddress}`,
12+
{
13+
headers: {
14+
"x-client-id": params.client.clientId,
15+
},
16+
method: "POST",
17+
},
18+
);
19+
20+
return res;
21+
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { useAllChainsData } from "@/hooks/chains/allChains";
2424
import { useAddContractToProject } from "@/hooks/project-contracts";
2525
import { defineDashboardChain } from "@/lib/defineDashboardChain";
2626
import { parseError } from "@/utils/errorParser";
27+
import { createTokenOnUniversalBridge } from "../_apis/create-token-on-bridge";
2728
import type { CreateAssetFormValues } from "./_common/form";
2829
import { CreateTokenAssetPageUI } from "./create-token-page.client";
2930

@@ -227,7 +228,12 @@ export function CreateTokenAssetPage(props: {
227228
airdropTokens,
228229
deployContract,
229230
}}
230-
onLaunchSuccess={() => {
231+
onLaunchSuccess={(params) => {
232+
createTokenOnUniversalBridge({
233+
chainId: params.chainId,
234+
client: props.client,
235+
tokenAddress: params.contractAddress,
236+
});
231237
revalidatePathAction(
232238
`/team/${props.teamSlug}/project/${props.projectId}/tokens`,
233239
"page",

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export function CreateTokenAssetPageUI(props: {
3434
accountAddress: string;
3535
client: ThirdwebClient;
3636
createTokenFunctions: CreateTokenFunctions;
37-
onLaunchSuccess: () => void;
37+
onLaunchSuccess: (params: {
38+
chainId: number;
39+
contractAddress: string;
40+
}) => void;
3841
teamSlug: string;
3942
projectSlug: string;
4043
}) {

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ export function LaunchTokenStatus(props: {
4747
values: CreateAssetFormValues;
4848
onPrevious: () => void;
4949
client: ThirdwebClient;
50-
onLaunchSuccess: () => void;
50+
onLaunchSuccess: (params: {
51+
chainId: number;
52+
contractAddress: string;
53+
}) => void;
5154
teamSlug: string;
5255
projectSlug: string;
5356
}) {
5457
const formValues = props.values;
5558
const { createTokenFunctions } = props;
5659
const [steps, setSteps] = useState<MultiStepState<StepId>[]>([]);
5760
const [isModalOpen, setIsModalOpen] = useState(false);
58-
const [contractLink, setContractLink] = useState<string | null>(null);
61+
const [contractAddress, setContractAddress] = useState<string | null>(null);
5962
const activeWallet = useActiveWallet();
6063
const walletRequiresApproval = activeWallet?.id !== "inApp";
6164

@@ -100,9 +103,7 @@ export function LaunchTokenStatus(props: {
100103
async function executeStep(stepId: StepId) {
101104
if (stepId === "deploy-contract") {
102105
const result = await createTokenFunctions.deployContract(formValues);
103-
setContractLink(
104-
`/team/${props.teamSlug}/${props.projectSlug}/contract/${formValues.chain}/${result.contractAddress}`,
105-
);
106+
setContractAddress(result.contractAddress);
106107
} else if (stepId === "airdrop-tokens") {
107108
await createTokenFunctions.airdropTokens(formValues);
108109
}
@@ -152,7 +153,12 @@ export function LaunchTokenStatus(props: {
152153
contractType: "DropERC20",
153154
});
154155

155-
props.onLaunchSuccess();
156+
if (contractAddress) {
157+
props.onLaunchSuccess({
158+
chainId: Number(formValues.chain),
159+
contractAddress,
160+
});
161+
}
156162
}
157163

158164
async function handleRetry(step: MultiStepState<StepId>) {
@@ -164,6 +170,10 @@ export function LaunchTokenStatus(props: {
164170
await executeSteps(steps, startIndex);
165171
}
166172

173+
const contractLink = contractAddress
174+
? `/team/${props.teamSlug}/${props.projectSlug}/contract/${formValues.chain}/${contractAddress}`
175+
: null;
176+
167177
return (
168178
<StepCard
169179
nextButton={{

0 commit comments

Comments
 (0)