Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/every-clubs-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@relayprotocol/relay-kit-ui': patch
---

Fix explicit deposit for zero native balance wallets
21 changes: 18 additions & 3 deletions packages/ui/src/components/widgets/SwapWidgetRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,29 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
const loadingProtocolVersion =
fromChain?.id && originChainSupportsProtocolv2 && isLoadingFromTokenPrice

const explicitDeposit = useEOADetection(
// Get native balance only when not swapping from native token
const isFromNative = fromToken?.address === fromChain?.currency?.address
const { value: nativeBalance } = useCurrencyBalance({
chain: fromChain,
address: address,
currency: fromChain?.currency?.address
? (fromChain.currency.address as string)
: undefined,
enabled: fromToken !== undefined && !isFromNative,
wallet
})

const effectiveNativeBalance = isFromNative ? fromBalance : nativeBalance
const hasZeroNativeBalance = effectiveNativeBalance === 0n

const eoaExplicitDeposit = useEOADetection(
wallet,
quoteProtocol,
fromToken?.chainId,
fromChain?.vmType
)

const explicitDeposit = hasZeroNativeBalance ? true : eoaExplicitDeposit
const normalizedSponsoredTokens = useMemo(() => {
const chainVms = relayClient?.chains.reduce(
(chains, chain) => {
Expand Down Expand Up @@ -860,8 +877,6 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
onAnalyticEvent
)

const isFromNative = fromToken?.address === fromChain?.currency?.address

const isSameCurrencySameRecipientSwap =
fromToken?.address === toToken?.address &&
fromToken?.chainId === toToken?.chainId &&
Expand Down