From 76eb0a994c11ab2509084db9b118308ff546d309 Mon Sep 17 00:00:00 2001 From: adwait Date: Mon, 27 Jan 2025 09:46:40 +0000 Subject: [PATCH] Add check for phantom wallet before throwing error (#1) Part of https://www.notion.so/Debug-and-fix-meme-generator-app-188a6b22d4728043ba2fd706d7c7def7 - During meme generation, only solflare wallet was being checked for. This caused an error if the user was using phantom wallet - Added a check for phantom wallet before throwing error Co-authored-by: Adw8 Reviewed-on: https://git.vdb.to/deep-stack/sol-mem-gen/pulls/1 Co-authored-by: adwait Co-committed-by: adwait --- .env.example | 6 ++++++ .gitignore | 4 ++++ src/app/page.tsx | 19 ++++++++++--------- src/components/AIServiceCard.tsx | 12 ++++++------ src/services/fluxService.ts | 4 ++-- src/services/paymentService.ts | 21 ++++++++++----------- 6 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 .env.example create mode 100644 .gitignore diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..9caa6f0 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +FAL_AI_KEY= + +NEXT_PUBLIC_MTM_TOKEN_MINT=97RggLo3zV5kFGYW4yoQTxr4Xkz4Vg2WPHzNYXXWpump +NEXT_PUBLIC_PAYMENT_RECEIVER_ADDRESS=FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY +NEXT_PUBLIC_SOLANA_RPC_URL=https://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4 +NEXT_PUBLIC_SOLANA_WEBSOCKET_URL=wss://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42fc8c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +.next + +.env diff --git a/src/app/page.tsx b/src/app/page.tsx index 755f1f9..bbcfb5f 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -15,7 +15,7 @@ const Page: React.FC = (): React.ReactElement => { type: null }) - const handleConnect = async (walletType: WalletType): Promise => { + const handleConnect = async (walletType: WalletType): Promise => { try { const newWalletState = await connectWallet(walletType) setWalletState(newWalletState) @@ -29,11 +29,13 @@ const Page: React.FC = (): React.ReactElement => { } } - const handleFluxGeneration = (modelId: string, cost: number) => { return async (prompt: string): Promise => { - if (!walletState.connected || !walletState.publicKey || !window.solflare) { - return { error: 'Wallet not connected' } + const type = walletState.type; + if (!walletState.connected || !walletState.publicKey || + (type === 'phantom' && !window.phantom) || + (type === 'solflare' && !window.solflare)) { + return { error: 'Wallet not connected' } } // Process payment first @@ -63,7 +65,7 @@ const Page: React.FC = (): React.ReactElement => {

Use MTM to generate memes

- + { onGenerate={handleFluxGeneration(model.modelId, model.cost)} /> ))} - + {/* Coming Soon Card */}
@@ -98,12 +100,11 @@ const Page: React.FC = (): React.ReactElement => { TBD
-