Skip to content

Commit

Permalink
fix: claim for guests + recipient address update in input
Browse files Browse the repository at this point in the history
  • Loading branch information
kushagrasarathe committed Jan 15, 2025
1 parent d6a72c3 commit 4748e49
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions src/components/Claim/Link/Initial.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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 (
<div>
Expand Down Expand Up @@ -455,7 +480,7 @@ export const InitialClaimLinkView = ({
</Card.Description>
</Card.Header>
<Card.Content className="flex flex-col gap-2">
{isExternalWallet && recipientType !== 'iban' && recipientType !== 'us' && (
{(!isConnected || isExternalWallet) && recipientType !== 'iban' && recipientType !== 'us' && (
<TokenSelector
shouldBeConnected={false}
showOnlySquidSupported
Expand All @@ -464,7 +489,7 @@ export const InitialClaimLinkView = ({
}}
/>
)}
{isExternalWallet && (
{(!isConnected || isExternalWallet) && (
<GeneralRecipientInput
className="pl-8"
placeholder="wallet address / ENS / IBAN / US account number"
Expand Down

0 comments on commit 4748e49

Please sign in to comment.