Skip to content

Commit

Permalink
Merge pull request #204 from reservoirprotocol/ted/relay-5443-allow-s…
Browse files Browse the repository at this point in the history
…etting-default-from-token-in-chain-widget

Add defaultExternalChainToken to Chain Widget
  • Loading branch information
ted-palmer authored Jul 31, 2024
2 parents 2cc998d + 87239fa commit 17435d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-spies-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-kit-ui': patch
---

Add defaultExternalChainToken to Chain Widget
28 changes: 16 additions & 12 deletions packages/ui/src/components/widgets/ChainWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { PriceImpactTooltip } from '../PriceImpactTooltip.js'
type ChainWidgetProps = {
chainId: number
defaultToken: Token
defaultExternalChainToken?: Token
tokens?: Token[]
defaultToAddress?: Address
defaultAmount?: string
Expand All @@ -44,6 +45,7 @@ const ChainWidget: FC<ChainWidgetProps> = ({
chainId,
tokens,
defaultToken,
defaultExternalChainToken,
defaultToAddress,
defaultAmount,
defaultTradeType,
Expand All @@ -70,25 +72,27 @@ const ChainWidget: FC<ChainWidgetProps> = ({
}
}, [chainId, defaultToken])

const defaultFromToken =
defaultExternalChainToken ??
(chainId !== defaultChainId
? {
chainId: defaultChainId,
address: zeroAddress,
symbol: 'ETH',
name: 'ETH',
decimals: 18,
logoURI: 'https://assets.relay.link/icons/square/1/light.png'
}
: undefined)

return (
<SwapWidgetRenderer
transactionModalOpen={transactionModalOpen}
defaultAmount={defaultAmount}
defaultToAddress={defaultToAddress}
defaultTradeType={defaultTradeType}
defaultToToken={defaultToken}
defaultFromToken={
chainId !== defaultChainId
? {
chainId: defaultChainId,
address: zeroAddress,
symbol: 'ETH',
name: 'ETH',
decimals: 18,
logoURI: 'https://assets.relay.link/icons/square/1/light.png'
}
: undefined
}
defaultFromToken={defaultFromToken}
fetchSolverConfig={true}
onSwapError={onSwapError}
onAnalyticEvent={onAnalyticEvent}
Expand Down

0 comments on commit 17435d6

Please sign in to comment.