Skip to content

Commit

Permalink
multiple token support (#40)
Browse files Browse the repository at this point in the history
We decided in a sync that we wanted a switcher that supported multiple tokens.
  • Loading branch information
andy-t-wang authored May 30, 2024
1 parent 726a21a commit b6d4a7a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
66 changes: 35 additions & 31 deletions demo/with-next/components/ClientContent/Pay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,40 @@ export const Pay = () => {
}, []);

const onPayClick = useCallback(
async (token: Tokens, amount: number, address: string) => {
const tokenAmount = tokenToDecimals(amount, token);
async (amount: number, address: string, token?: Tokens) => {
const wldAmount = tokenToDecimals(amount, Tokens.WLD);
const usdcAmount = tokenToDecimals(amount, Tokens.USDCE);

const tokenPayload = [
{
symbol: Tokens.WLD,
token_amount: wldAmount.toString(),
},
{
symbol: Tokens.USDCE,
token_amount: usdcAmount.toString(),
},
];

const payPayload: PayCommandInput = {
to: address,
token_amount: tokenAmount.toString(),
token: token,
tokens: token
? [
{
symbol: token,
token_amount:
token === Tokens.WLD
? wldAmount.toString()
: usdcAmount.toString(),
},
]
: tokenPayload,
description: "Test example payment for minikit",
reference: new Date().toISOString(),
};

const payload = MiniKit.commands.pay(payPayload);

setSentPayPayload({
payload,
});
Expand All @@ -115,56 +137,38 @@ export const Pay = () => {
</pre>
</div>
</div>
<div className="grid grid-cols-2 gap-x-4">
<button
className="bg-black text-white rounded-lg p-4 w-full"
onClick={() =>
onPayClick(
Tokens.USDCE,
0.1,
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
)
}
>
Send pay (USDCE)
</button>
<div className="grid grid-cols-3 gap-x-4">
<button
className="bg-black text-white rounded-lg p-4 w-full"
onClick={() =>
onPayClick(
Tokens.WLD,
0.1,
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
)
onPayClick(0.1, "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")
}
>
Send pay (WLD)
Pay (USDCE + WLD)
</button>
</div>
<div className="grid grid-cols-2 gap-x-4">
<button
className="bg-black text-white rounded-lg p-4 w-full"
onClick={() =>
onPayClick(
Tokens.USDCE,
0.1,
"0xc2eD884aEa29135AcaB517c0967225Bf15DeA6E9"
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
Tokens.WLD
)
}
>
Send pay (USDCE) Addr 2
Pay Single (WLD)
</button>
<button
className="bg-black text-white rounded-lg p-4 w-full"
onClick={() =>
onPayClick(
Tokens.WLD,
0.1,
"0xc2eD884aEa29135AcaB517c0967225Bf15DeA6E9"
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
Tokens.USDCE
)
}
>
Send pay (WLD) Addr 2
Pay Single (USDC)
</button>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions src/types/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ export type VerifyCommandInput = {
verification_level?: VerificationLevel;
};

export type TokensPayload = {
symbol: Tokens;
token_amount: string;
};

export type PayCommandInput = {
reference: string;
to: string;
token_amount: string; // Stringified Decimals
token: Tokens;
tokens: TokensPayload[];
network?: Network; // Optional
description: string;
};
Expand Down

0 comments on commit b6d4a7a

Please sign in to comment.