-
Notifications
You must be signed in to change notification settings - Fork 13
fix: render token details for peanut wallet #653
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,40 @@ | ||
| 'use client' | ||
|
|
||
| import { ARBITRUM_ICON } from '@/assets' | ||
| import { Button } from '@/components/0_Bruddle' | ||
| import DirectionalActionButtons from '@/components/Global/DirectionalActionButtons' | ||
| import NoDataEmptyState from '@/components/Global/EmptyStates/NoDataEmptyState' | ||
| import Icon from '@/components/Global/Icon' | ||
| import { ListItemView } from '@/components/Global/ListItemView' | ||
| import NavHeader from '@/components/Global/NavHeader' | ||
| import { WalletCard } from '@/components/Home/WalletCard' | ||
| import { PEANUT_WALLET_CHAIN, PEANUT_WALLET_TOKEN_DECIMALS, PEANUT_WALLET_TOKEN_NAME } from '@/constants' | ||
| import { useAuth } from '@/context/authContext' | ||
| import { useWallet } from '@/hooks/wallet/useWallet' | ||
| import { IUserBalance } from '@/interfaces' | ||
| import { useWalletConnection } from '@/hooks/wallet/useWalletConnection' | ||
| import { IWallet, WalletProviderType } from '@/interfaces' | ||
| import { useWalletStore } from '@/redux/hooks' | ||
| import { formatAmount, getChainName, getHeaderTitle, getUserPreferences, updateUserPreferences } from '@/utils' | ||
| import { useAppKit, useDisconnect } from '@reown/appkit/react' | ||
| import { useDisconnect } from '@reown/appkit/react' | ||
| import { usePathname } from 'next/navigation' | ||
| import { useMemo, useState } from 'react' | ||
| import { twMerge } from 'tailwind-merge' | ||
| import { useState } from 'react' | ||
| import { formatUnits } from 'viem' | ||
|
|
||
| const WalletDetailsPage = () => { | ||
| const pathname = usePathname() | ||
| const { open } = useAppKit() | ||
| const { disconnect } = useDisconnect() | ||
| const { focusedWallet, wallets } = useWalletStore() | ||
| const { isConnected, address } = useWallet() | ||
| const { focusedWallet } = useWalletStore() | ||
| const { connectWallet } = useWalletConnection() | ||
| const { isWalletConnected, wallets } = useWallet() | ||
| const { username } = useAuth() | ||
| const [isBalanceHidden, setIsBalanceHidden] = useState(() => { | ||
| const prefs = getUserPreferences() | ||
| return prefs?.balanceHidden ?? false | ||
| }) | ||
|
|
||
| const walletDetails = useMemo( | ||
| () => wallets.find((wallet) => wallet.address === focusedWallet), | ||
| [focusedWallet, wallets] | ||
| ) | ||
| const walletDetails = wallets.find((wallet) => wallet.address === focusedWallet) | ||
| const isPeanutWallet = walletDetails?.walletProviderType === WalletProviderType.PEANUT | ||
| const isConnected = isWalletConnected(walletDetails as IWallet) | ||
|
|
||
| const handleToggleBalanceVisibility = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
| e.stopPropagation() | ||
|
|
@@ -43,6 +45,62 @@ const WalletDetailsPage = () => { | |
| }) | ||
| } | ||
|
|
||
| const renderTokenDetails = () => { | ||
| if (!walletDetails) return null | ||
| if (isPeanutWallet) { | ||
| return walletDetails.balance && Number(walletDetails.balance) > 0 ? ( | ||
kushagrasarathe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div className="space-y-3"> | ||
| <div className="text-base font-semibold">Balance</div> | ||
| <div className="border border-b-black"> | ||
| <ListItemView | ||
| key={`peanut-${walletDetails.address}`} | ||
| id={`${PEANUT_WALLET_CHAIN.id}-${PEANUT_WALLET_CHAIN.name}`} | ||
| variant="balance" | ||
| primaryInfo={{ title: PEANUT_WALLET_TOKEN_NAME }} | ||
| secondaryInfo={{ | ||
| mainText: `$ ${formatAmount(formatUnits(walletDetails.balance, PEANUT_WALLET_TOKEN_DECIMALS))}`, | ||
| subText: PEANUT_WALLET_CHAIN.name, | ||
| }} | ||
| metadata={{ | ||
| tokenLogo: ARBITRUM_ICON, | ||
| subText: `${formatAmount(formatUnits(walletDetails.balance, PEANUT_WALLET_TOKEN_DECIMALS))} USDC`, | ||
|
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. I still hate formatAmount(formatUnits)
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. formatformatformat
Contributor
Author
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. ouch, this one can be fixed, my baddd, mee dummbbb |
||
| }} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ) : ( | ||
| <NoDataEmptyState message="You don't have funds in your Peanut wallet" /> | ||
kushagrasarathe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| } else { | ||
| return walletDetails.balances?.length ? ( | ||
| <div className="space-y-3 border-b border-b-black"> | ||
| <div className="text-base font-semibold">Balance</div> | ||
| <div> | ||
| {walletDetails.balances.map((balance) => ( | ||
| <ListItemView | ||
| key={`${balance.chainId}-${balance.symbol}`} | ||
| id={`${balance.chainId}-${balance.symbol}`} | ||
| variant="balance" | ||
| primaryInfo={{ title: balance.symbol }} | ||
| secondaryInfo={{ | ||
| mainText: `$ ${Number(balance.value).toFixed(2)}`, | ||
| subText: getChainName(balance.chainId), | ||
| }} | ||
| metadata={{ | ||
| tokenLogo: balance.logoURI, | ||
| subText: `${formatAmount(balance.amount)} ${balance.symbol}`, | ||
| }} | ||
| details={balance} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ) : ( | ||
| <NoDataEmptyState message="No tokens found" /> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div className="mx-auto flex w-full flex-col gap-6 md:max-w-2xl"> | ||
| <div className="md:hidden"> | ||
|
|
@@ -59,80 +117,30 @@ const WalletDetailsPage = () => { | |
| selected | ||
| onClick={() => {}} | ||
| index={0} | ||
| isFocused | ||
| isBalanceHidden={isBalanceHidden} | ||
| onToggleBalanceVisibility={handleToggleBalanceVisibility} | ||
| /> | ||
| )} | ||
| </div> | ||
|
|
||
| <DirectionalActionButtons | ||
| leftButton={{ | ||
| title: 'Top up', | ||
| href: '/topup', | ||
| disabled: true, | ||
| }} | ||
| rightButton={{ | ||
| title: 'Cash out', | ||
| href: '/cashout', | ||
| }} | ||
| leftButton={{ title: 'Top up', href: '/topup', disabled: true }} | ||
| rightButton={{ title: 'Cashout', href: '/cashout' }} | ||
| /> | ||
|
|
||
| <div | ||
| className={twMerge( | ||
| walletDetails?.balances && !!walletDetails?.balances?.length ? 'border-b border-b-n-1' : '' | ||
| )} | ||
| > | ||
| {!!walletDetails?.balances?.length ? ( | ||
| <div className="space-y-3"> | ||
| <div className="text-base font-semibold">Balance</div> | ||
| <div> | ||
| {walletDetails.balances.map((balance: IUserBalance) => ( | ||
| <ListItemView | ||
| key={`${balance.chainId}-${balance.symbol}`} | ||
| id={`${balance.chainId}-${balance.symbol}`} | ||
| variant="balance" | ||
| primaryInfo={{ | ||
| title: balance.symbol, | ||
| }} | ||
| secondaryInfo={{ | ||
| mainText: `$${Number(balance.value).toFixed(2)}`, | ||
| subText: getChainName(balance.chainId), | ||
| }} | ||
| metadata={{ | ||
| tokenLogo: balance.logoURI, | ||
| subText: `${formatAmount(balance.amount)} ${balance.symbol}`, | ||
| }} | ||
| details={balance} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ) : ( | ||
| <NoDataEmptyState message="No tokens found" /> | ||
| )} | ||
| </div> | ||
| <div> | ||
| {renderTokenDetails()} | ||
|
|
||
| {!isPeanutWallet && ( | ||
| <Button | ||
| onClick={() => { | ||
| if (isConnected && walletDetails?.address === address) { | ||
| disconnect() | ||
| } else { | ||
| open() | ||
| } | ||
| }} | ||
| onClick={() => (isConnected ? disconnect() : connectWallet())} | ||
| variant="transparent-light" | ||
| className="flex w-full items-center justify-center gap-2 border border-black bg-purple-5 hover:bg-purple-5" | ||
| > | ||
| <Icon | ||
| name={isConnected && walletDetails?.address === address ? 'minus-circle' : 'plus-circle'} | ||
| fill="black" | ||
| className="size-4" | ||
| /> | ||
| <div className="text-black"> | ||
| {isConnected && walletDetails?.address === address ? 'Disconnect' : 'Connect'} | ||
| </div> | ||
| <Icon name={isConnected ? 'minus-circle' : 'plus-circle'} fill="black" className="size-4" /> | ||
| <div className="text-black">{isConnected ? 'Disconnect Wallet' : 'Connect Wallet'}</div> | ||
| </Button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
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: why wallet.address is the id in this case? accountId from BE would be better imo. Then again we also have accountIdentifier in Backend, so address works kinda too. But the var names should be renamed if we add banking accounts to selectable accounts