Skip to content

Commit

Permalink
switch
Browse files Browse the repository at this point in the history
  • Loading branch information
mPaella committed Oct 17, 2024
1 parent 523c43e commit 2d2c65a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
16 changes: 4 additions & 12 deletions apps/payments/nextjs/pages/embedded-checkout/v3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export default function EmbeddedCheckoutV3Page() {
}}
>
<CrossmintProvider
overrideBaseUrl="https://dserver.maxf.io"
overrideBaseUrl="https://wserver.maxf.io"
apiKey="sk_development_5ZUNkuhjP8aYZEgUTDfWToqFpo5zakEqte1db4pHZgPAVKZ9JuSvnKeGiqY654DoBuuZEzYz4Eb8gRV2ePqQ1fxTjEP8tTaUQdzbGfyG9RgyeN5YbqViXinqxk8EayEkAGtvSSgjpjEr6iaBptJtUFwPW59DjQzTQP6P8uZdiajenVg7bARGKjzFyByNuVEoz41DpRB4hDZNFdwCTuf5joFv"
>
<CrossmintEmbeddedCheckout
// recipient={{
// walletAddress: "0x5e575279bf9f4acf0a130c186861454247394c06",
// }}
recipient={{
email: "[email protected]",
}}
lineItems={{
collectionLocator: "crossmint:206b3146-f526-444e-bd9d-0607d581b0e9",
callData: {
Expand All @@ -40,17 +40,9 @@ export default function EmbeddedCheckoutV3Page() {
payment={{
crypto: {
enabled: true,
defaultChain: "ethereum-sepolia",
defaultCurrency: "eth",
},
fiat: {
enabled: true,
allowedMethods: {
card: true,
applePay: true,
googlePay: true,
},
// defaultCurrency: "inr",
},
defaultMethod: "fiat",
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import DynamicContextProviderWrapper from "@/components/dynamic-xyz/DynamicContextProviderWrapper";
import type { EmbeddedCheckoutV3IFrameEmitter } from "@crossmint/client-sdk-base";
import { type BlockchainIncludingTestnet, chainIdToBlockchain } from "@crossmint/common-sdk-base";
import {
type BlockchainIncludingTestnet,
blockchainToChainId,
chainIdToBlockchain,
EVMBlockchainIncludingTestnet,
} from "@crossmint/common-sdk-base";
import { EthereumWalletConnectors, isEthereumWallet } from "@dynamic-labs/ethereum";
import { type HandleConnectedWallet, useDynamicContext } from "@dynamic-labs/sdk-react-core";
import { isSolanaWallet, SolanaWalletConnectors } from "@dynamic-labs/solana";
Expand Down Expand Up @@ -79,7 +84,6 @@ function _CryptoWalletConnectionHandler({ iframeClient }: Parameters<typeof Cryp
return () => {
console.log("[CryptoWalletConnectionHandler] cleaning up listeners");
iframeClient.off(showAuthFlowListener);
// iframeClient.off(signTransactionListener);
};
}, [iframeClient]);

Expand All @@ -100,7 +104,19 @@ function _CryptoWalletConnectionHandler({ iframeClient }: Parameters<typeof Cryp
return;
}

if (isEthereumWallet(primaryWallet)) {
if (isSolanaWallet(primaryWallet)) {
throw new Error("Solana wallets are not supported");
} else if (isEthereumWallet(primaryWallet)) {
try {
await primaryWallet.switchNetwork(blockchainToChainId(chain as EVMBlockchainIncludingTestnet));
} catch (error) {
console.error("[CryptoWalletConnectionHandler] failed to switch network", error);
iframeClient.send("crypto:send-transaction:failed", {
error: (error as Error).message,
});
return;
}

const walletClient = await primaryWallet.getWalletClient();
const parsedTransaction = parseTransaction(serializedTransaction as `0x${string}`);
try {
Expand All @@ -119,8 +135,6 @@ function _CryptoWalletConnectionHandler({ iframeClient }: Parameters<typeof Cryp
});
return;
}
} else if (isSolanaWallet(primaryWallet)) {
console.error("[CryptoWalletConnectionHandler] signTransaction: unsupported wallet");
}
}
);
Expand Down

0 comments on commit 2d2c65a

Please sign in to comment.