From 4748e49ff843fc9a68627f620cec3075d236d208 Mon Sep 17 00:00:00 2001 From: kushagrasarathe <76868364+kushagrasarathe@users.noreply.github.com> Date: Wed, 15 Jan 2025 22:57:09 +0530 Subject: [PATCH] fix: claim for guests + recipient address update in input --- src/components/Claim/Link/Initial.view.tsx | 43 +++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/components/Claim/Link/Initial.view.tsx b/src/components/Claim/Link/Initial.view.tsx index 24450fef..7ceaad72 100644 --- a/src/components/Claim/Link/Initial.view.tsx +++ b/src/components/Claim/Link/Initial.view.tsx @@ -32,7 +32,6 @@ import { } from '@/utils' import { getSquidTokenAddress, SQUID_ETH_ADDRESS } from '@/utils/token.utils' import { Popover } from '@headlessui/react' -import { useAppKit } from '@reown/appkit/react' import { getSquidRouteRaw } from '@squirrel-labs/peanut-sdk' import { useCallback, useContext, useEffect, useState } from 'react' import * as _consts from '../Claim.consts' @@ -83,8 +82,7 @@ export const InitialClaimLinkView = ({ supportedSquidChainsAndTokens, } = useContext(context.tokenSelectorContext) const { claimLink } = useClaimLink() - const { open } = useAppKit() - const { isConnected, address, signInModal, isExternalWallet, isPeanutWallet } = useWallet() + const { isConnected, address, signInModal, isExternalWallet, isPeanutWallet, selectedWallet } = useWallet() const { user } = useAuth() const resetSelectedToken = useCallback(() => { @@ -401,11 +399,38 @@ export const InitialClaimLinkView = ({ }, [recipientType]) useEffect(() => { - if (isPeanutWallet && address) { - setRecipient({ name: undefined, address: address }) - setIsValidRecipient(true) + if (!isConnected) { + setRecipient({ name: undefined, address: '' }) + setIsValidRecipient(false) + return + } + + // reset recipient when wallet type changes or when selected wallet changes + if (selectedWallet) { + // reset recipient + setRecipient({ name: undefined, address: '' }) + setIsValidRecipient(false) + + // set it to the current address after a short delay + // to ensure the ui updates properly + setTimeout(() => { + if (address) { + setRecipient({ name: undefined, address: address }) + setIsValidRecipient(true) + } + }, 100) } - }, [isPeanutWallet, address]) + }, [selectedWallet, isConnected, address]) + + useEffect(() => { + if (recipient.address) return + if (isConnected && address) { + setRecipient({ name: undefined, address }) + } else { + setRecipient({ name: undefined, address: '' }) + setIsValidRecipient(false) + } + }, [address]) return (
@@ -455,7 +480,7 @@ export const InitialClaimLinkView = ({ - {isExternalWallet && recipientType !== 'iban' && recipientType !== 'us' && ( + {(!isConnected || isExternalWallet) && recipientType !== 'iban' && recipientType !== 'us' && ( )} - {isExternalWallet && ( + {(!isConnected || isExternalWallet) && (