Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
[PE-6904] External Wallets section#12972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1a4f225b09e2887ab148ec2c8c3dc9fa5dac54bb23File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,252 @@ | ||
| import { useCallback, useMemo, useState } from 'react' | ||
| import type { ConnectedWallet } from '@audius/common/api' | ||
| import { | ||
| useConnectedWallets, | ||
| useRemoveConnectedWallet | ||
| } from '@audius/common/api' | ||
| import { walletMessages } from '@audius/common/messages' | ||
| import { Chain } from '@audius/common/models' | ||
| import { shortenSPLAddress, WALLET_COUNT_LIMIT } from '@audius/common/utils' | ||
| import Clipboard from '@react-native-clipboard/clipboard' | ||
| import { | ||
| Button, | ||
| Flex, | ||
| IconButton, | ||
| IconKebabHorizontal, | ||
| IconLogoCircleETH, | ||
| IconLogoCircleSOL, | ||
| Paper, | ||
| Text, | ||
| Skeleton, | ||
| Divider, | ||
| useTheme, | ||
| LoadingSpinner | ||
| } from '@audius/harmony-native' | ||
| import ActionDrawer, { | ||
| type ActionDrawerRow | ||
| } from 'app/components/action-drawer/ActionDrawer' | ||
| import { useDrawer } from 'app/hooks/useDrawer' | ||
| import { useNavigation } from 'app/hooks/useNavigation' | ||
| import { useToast } from 'app/hooks/useToast' | ||
| const WALLET_ROW_HEIGHT = 52 | ||
| type WalletRowProps = { | ||
| address: string | ||
| chain: Chain | ||
| index: number | ||
| } | ||
| type WalletRowContentProps = { | ||
| address: string | ||
| chain: Chain | ||
| index: number | ||
| isRemovingWallet: boolean | ||
| onOpenOverflowMenu: () => void | ||
| } | ||
| const WalletRowContent = ({ | ||
| address, | ||
| chain, | ||
| index, | ||
| isRemovingWallet, | ||
| onOpenOverflowMenu | ||
| }: WalletRowContentProps) => { | ||
| return ( | ||
| <Flex | ||
| row | ||
| alignItems='center' | ||
| gap='m' | ||
| w='100%' | ||
| ph='l' | ||
| pv='m' | ||
| h={WALLET_ROW_HEIGHT} | ||
| style={{ opacity: isRemovingWallet ? 0.5 : 1 }} | ||
| > | ||
| <Flex row alignItems='center' gap='s'> | ||
| {chain === Chain.Eth ? <IconLogoCircleETH /> : <IconLogoCircleSOL />} | ||
| <Text variant='body' size='m' strength='strong'> | ||
| {walletMessages.linkedWallets.linkedWallet(index)} | ||
| </Text> | ||
| </Flex> | ||
| <Flex flex={1}> | ||
| <Text variant='body' size='m' strength='strong' color='subdued'> | ||
| {shortenSPLAddress(address)} | ||
| </Text> | ||
| </Flex> | ||
| {isRemovingWallet ? ( | ||
| <LoadingSpinner /> | ||
| ) : ( | ||
| <IconButton | ||
| icon={IconKebabHorizontal} | ||
| onPress={onOpenOverflowMenu} | ||
| ripple | ||
| /> | ||
| )} | ||
| </Flex> | ||
| ) | ||
| } | ||
| const WalletRow = ({ address, chain, index }: WalletRowProps) => { | ||
| const { onOpen } = useDrawer('WalletRowOverflowMenu') | ||
| const [isRemovingWallet, setIsRemovingWallet] = useState(false) | ||
| const handleOpenOverflowMenu = useCallback(() => { | ||
| onOpen({ | ||
| address, | ||
| chain, | ||
| setIsRemovingWallet | ||
| }) | ||
| }, [address, chain, onOpen, setIsRemovingWallet]) | ||
| return ( | ||
| <WalletRowContent | ||
| address={address} | ||
| chain={chain} | ||
| index={index} | ||
| isRemovingWallet={isRemovingWallet} | ||
| onOpenOverflowMenu={handleOpenOverflowMenu} | ||
| /> | ||
| ) | ||
| } | ||
| export const WalletRowOverflowMenu = () => { | ||
| const { data: drawerData } = useDrawer('WalletRowOverflowMenu') | ||
| const { toast } = useToast() | ||
| const { address, chain, setIsRemovingWallet } = drawerData ?? {} | ||
| const { mutateAsync: removeConnectedWalletAsync } = useRemoveConnectedWallet() | ||
| const handleCopy = useCallback(() => { | ||
| if (address) { | ||
| Clipboard.setString(address) | ||
| toast({ content: walletMessages.linkedWallets.copied, type: 'info' }) | ||
| } | ||
| }, [address, toast]) | ||
| const handleRemove = useCallback(async () => { | ||
| if (!address || !chain || !setIsRemovingWallet) return | ||
| setIsRemovingWallet(true) | ||
| await removeConnectedWalletAsync({ | ||
| wallet: { address, chain } | ||
| }) | ||
| setIsRemovingWallet(false) | ||
| }, [address, chain, setIsRemovingWallet, removeConnectedWalletAsync]) | ||
| const rows: ActionDrawerRow[] = useMemo( | ||
| () => [ | ||
| { | ||
| text: walletMessages.linkedWallets.copy, | ||
| callback: handleCopy | ||
| }, | ||
| { | ||
| text: walletMessages.linkedWallets.remove, | ||
| isDestructive: true, | ||
| callback: handleRemove | ||
| } | ||
| ], | ||
| [handleCopy, handleRemove] | ||
| ) | ||
| return <ActionDrawer drawerName='WalletRowOverflowMenu' rows={rows} /> | ||
| } | ||
| const WalletLoadingState = () => { | ||
| const { spacing } = useTheme() | ||
| return ( | ||
| <> | ||
| <Flex mh='l' mt='l' gap='s' h={spacing.unit16}> | ||
| <Skeleton h={spacing.unit12} /> | ||
| </Flex> | ||
| <Flex mh='l' gap='s' h={spacing.unit16}> | ||
| <Skeleton h={spacing.unit12} /> | ||
| </Flex> | ||
| </> | ||
| ) | ||
| } | ||
| const WalletRowsList = ({ | ||
| connectedWallets | ||
| }: { | ||
| connectedWallets?: ConnectedWallet[] | ||
| }) => ( | ||
| <> | ||
| {connectedWallets?.map((wallet, index) => ( | ||
| <WalletRow | ||
| key={wallet.address} | ||
| address={wallet.address} | ||
| chain={wallet.chain} | ||
| index={index} | ||
| /> | ||
| ))} | ||
| </> | ||
| ) | ||
| const WalletEmptyState = () => ( | ||
| <Flex p='l'> | ||
| <Text variant='body' size='m' color='subdued'> | ||
| {walletMessages.linkedWallets.linkWallet} | ||
| </Text> | ||
| </Flex> | ||
| ) | ||
| export const LinkedWallets = () => { | ||
| const navigation = useNavigation() | ||
| const { data: connectedWallets, isLoading } = useConnectedWallets() | ||
dharit-tan marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const hasWallets = !!connectedWallets?.length | ||
| const walletCount = connectedWallets?.length ?? 0 | ||
| const handleAddWallet = useCallback(() => { | ||
| navigation.navigate('ExternalWallets') | ||
| }, [navigation]) | ||
| const isAtOrAboveLimit = walletCount >= WALLET_COUNT_LIMIT | ||
| return ( | ||
| <Paper> | ||
| {/* Header Section */} | ||
| <Flex gap='xl' p='l'> | ||
| <Flex row alignItems='center' gap='s'> | ||
| <Text variant='heading' size='m' color='heading'> | ||
| {hasWallets | ||
| ? walletMessages.linkedWallets.titleHasWallets | ||
| : walletMessages.linkedWallets.titleNoWallets} | ||
| </Text> | ||
| {hasWallets && !isLoading ? ( | ||
| <Text variant='heading' size='m' color='subdued'> | ||
| {walletMessages.linkedWallets.count(walletCount)} | ||
| </Text> | ||
| ) : null} | ||
| </Flex> | ||
| </Flex> | ||
| <Divider /> | ||
| {/* Wallet Stack Section */} | ||
| {isLoading ? ( | ||
| <WalletLoadingState /> | ||
| ) : hasWallets ? ( | ||
| <WalletRowsList connectedWallets={connectedWallets} /> | ||
| ) : ( | ||
| <WalletEmptyState /> | ||
Comment on lines
+229
to
+234
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this reads nicely ❤️ | ||
| )} | ||
| <Divider /> | ||
| {/* Footer Section with Add Button */} | ||
| <Flex p='l'> | ||
| <Button | ||
| variant='secondary' | ||
| size='small' | ||
| onPress={handleAddWallet} | ||
| disabled={isAtOrAboveLimit} | ||
| fullWidth | ||
| > | ||
| {walletMessages.linkedWallets.addWallet} | ||
| </Button> | ||
| </Flex> | ||
| </Paper> | ||
| ) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is there an enum or reference object for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we've done that before but we should lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha good call.. not gonna do that in this PR tho