-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * Check for collection logo image * Make collection detail view image loader match container width * Disable back button in conformation screen * Add missing border radius for collection detail list item * Update fee option hook to allow last registered handler to be triggered * Show txn pending state in confirmation view * Fix zeroAddress and null case for native token fee option * Remove unnecessary id * Remove logs * Update transaction confirmation and fee option UIs
- Loading branch information
1 parent
ac58f51
commit 7fe369c
Showing
15 changed files
with
973 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use client' | ||
|
||
import { FeeOption, Transaction } from '@0xsequence/waas' | ||
import { useConnections } from 'wagmi' | ||
|
||
export function useCheckWaasFeeOptions(): (params: { transactions: Transaction[]; chainId: number }) => Promise<{ | ||
feeQuote: string | undefined | ||
feeOptions: FeeOption[] | undefined | ||
isSponsored: boolean | ||
}> { | ||
const connections = useConnections() | ||
const waasConnector = connections.find(c => c.connector.id.includes('waas'))?.connector | ||
|
||
return async ({ transactions, chainId }) => { | ||
if (!waasConnector) { | ||
throw new Error('WaaS connector not found') | ||
} | ||
|
||
const waasProvider = (waasConnector as any).sequenceWaasProvider | ||
if (!waasProvider) { | ||
throw new Error('WaaS provider not found') | ||
} | ||
|
||
return waasProvider.checkTransactionFeeOptions({ transactions, chainId }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Box, Button, Text } from '@0xsequence/design-system' | ||
import React, { ComponentProps } from 'react' | ||
|
||
export type AlertProps = { | ||
title: string | ||
description: string | ||
secondaryDescription?: string | ||
variant: 'negative' | 'warning' | 'positive' | ||
buttonProps?: ComponentProps<typeof Button> | ||
children?: React.ReactNode | ||
} | ||
|
||
export const Alert = ({ title, description, secondaryDescription, variant, buttonProps, children }: AlertProps) => { | ||
return ( | ||
<Box borderRadius="md" background={variant}> | ||
<Box | ||
background="backgroundOverlay" | ||
borderRadius="md" | ||
paddingX={{ sm: '4', md: '5' }} | ||
paddingY="4" | ||
width="full" | ||
flexDirection="column" | ||
gap="3" | ||
> | ||
<Box width="full" flexDirection={{ sm: 'column', md: 'row' }} gap="2" justifyContent="space-between"> | ||
<Box flexDirection="column" gap="1"> | ||
<Text variant="normal" color="text100" fontWeight="medium"> | ||
{title} | ||
</Text> | ||
|
||
<Text variant="normal" color="text50" fontWeight="medium"> | ||
{description} | ||
</Text> | ||
|
||
{secondaryDescription && ( | ||
<Text variant="normal" color="text80" fontWeight="medium"> | ||
{secondaryDescription} | ||
</Text> | ||
)} | ||
</Box> | ||
|
||
{buttonProps ? ( | ||
<Box background={variant} borderRadius="sm" width={'min'} height={'min'}> | ||
<Button variant="emphasis" shape="square" flexShrink="0" {...buttonProps} /> | ||
</Box> | ||
) : null} | ||
</Box> | ||
|
||
{children} | ||
</Box> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { Box, Text, TokenImage } from '@0xsequence/design-system' | ||
import { ZeroAddress, formatUnits, parseUnits } from 'ethers' | ||
import React from 'react' | ||
|
||
import { Alert, AlertProps } from './Alert' | ||
|
||
export interface FeeOption { | ||
token: FeeToken | ||
to: string | ||
value: string | ||
gasLimit: number | ||
} | ||
export interface FeeToken { | ||
chainId: number | ||
name: string | ||
symbol: string | ||
decimals?: number | ||
logoURL: string | ||
contractAddress?: string | ||
tokenID?: string | ||
} | ||
|
||
export interface FeeOptionBalance { | ||
tokenName: string | ||
decimals: number | ||
balance: string | ||
} | ||
|
||
export interface FeeOptionSelectorProps { | ||
txnFeeOptions: FeeOption[] | ||
feeOptionBalances: FeeOptionBalance[] | ||
selectedFeeOptionAddress: string | undefined | ||
setSelectedFeeOptionAddress: (address: string) => void | ||
} | ||
|
||
const isBalanceSufficient = (balance: string, fee: string, decimals: number) => { | ||
const balanceBN = parseUnits(balance, decimals) | ||
const feeBN = parseUnits(fee, decimals) | ||
return balanceBN >= feeBN | ||
} | ||
|
||
export const FeeOptionSelector: React.FC<FeeOptionSelectorProps> = ({ | ||
txnFeeOptions, | ||
feeOptionBalances, | ||
selectedFeeOptionAddress, | ||
setSelectedFeeOptionAddress | ||
}) => { | ||
const [feeOptionAlert, setFeeOptionAlert] = React.useState<AlertProps | undefined>() | ||
|
||
const sortedOptions = [...txnFeeOptions].sort((a, b) => { | ||
const balanceA = feeOptionBalances.find(balance => balance.tokenName === a.token.name) | ||
const balanceB = feeOptionBalances.find(balance => balance.tokenName === b.token.name) | ||
const isSufficientA = balanceA ? isBalanceSufficient(balanceA.balance, a.value, a.token.decimals || 0) : false | ||
const isSufficientB = balanceB ? isBalanceSufficient(balanceB.balance, b.value, b.token.decimals || 0) : false | ||
return isSufficientA === isSufficientB ? 0 : isSufficientA ? -1 : 1 | ||
}) | ||
|
||
return ( | ||
<Box marginTop="3" width="full"> | ||
<Text variant="normal" color="text100" fontWeight="bold"> | ||
Select a fee option | ||
</Text> | ||
<Box flexDirection="column" marginTop="2" gap="2"> | ||
{sortedOptions.map((option, index) => { | ||
const isSelected = selectedFeeOptionAddress === (option.token.contractAddress ?? ZeroAddress) | ||
const balance = feeOptionBalances.find(b => b.tokenName === option.token.name) | ||
const isSufficient = isBalanceSufficient(balance?.balance || '0', option.value, option.token.decimals || 0) | ||
return ( | ||
<Box | ||
key={index} | ||
paddingX="3" | ||
paddingY="2" | ||
borderRadius="md" | ||
borderColor={isSelected ? 'borderFocus' : 'transparent'} | ||
borderWidth="thick" | ||
borderStyle="solid" | ||
background="backgroundRaised" | ||
onClick={() => { | ||
if (isSufficient) { | ||
setSelectedFeeOptionAddress(option.token.contractAddress ?? ZeroAddress) | ||
setFeeOptionAlert(undefined) | ||
} else { | ||
setFeeOptionAlert({ | ||
title: `Insufficient ${option.token.name} balance`, | ||
description: `Please select another fee option or add funds to your wallet.`, | ||
variant: 'warning' | ||
}) | ||
} | ||
}} | ||
cursor={isSufficient ? 'pointer' : 'default'} | ||
opacity={isSufficient ? '100' : '50'} | ||
> | ||
<Box flexDirection="row" justifyContent="space-between" alignItems="center"> | ||
<Box flexDirection="row" alignItems="center" gap="2"> | ||
<TokenImage src={option.token.logoURL} symbol={option.token.name} /> | ||
<Box flexDirection="column"> | ||
<Text variant="small" color="text100" fontWeight="bold"> | ||
{option.token.name} | ||
</Text> | ||
<Text variant="xsmall" color="text80"> | ||
Fee:{' '} | ||
{parseFloat(formatUnits(BigInt(option.value), option.token.decimals || 0)).toLocaleString(undefined, { | ||
maximumFractionDigits: 6 | ||
})} | ||
</Text> | ||
</Box> | ||
</Box> | ||
<Box flexDirection="column" alignItems="flex-end"> | ||
<Text variant="xsmall" color="text80"> | ||
Balance: | ||
</Text> | ||
<Text variant="xsmall" color="text100"> | ||
{parseFloat(formatUnits(BigInt(balance?.balance || '0'), option.token.decimals || 0)).toLocaleString( | ||
undefined, | ||
{ maximumFractionDigits: 6 } | ||
)} | ||
</Text> | ||
</Box> | ||
</Box> | ||
</Box> | ||
) | ||
})} | ||
</Box> | ||
<Box marginTop="3" alignItems="flex-end" justifyContent="center" flexDirection="column"> | ||
{feeOptionAlert && ( | ||
<Box marginTop="3"> | ||
<Alert | ||
title={feeOptionAlert.title} | ||
description={feeOptionAlert.description} | ||
secondaryDescription={feeOptionAlert.secondaryDescription} | ||
variant={feeOptionAlert.variant} | ||
/> | ||
</Box> | ||
)} | ||
</Box> | ||
</Box> | ||
) | ||
} |
Oops, something went wrong.