-
Notifications
You must be signed in to change notification settings - Fork 13
[TASK-6758] Hide token selector on peanut wallet and default token #551
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
3b935bb
7317ecc
67455d9
cac8494
8c264ce
45af86b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,10 @@ import ValidatedInput from '@/components/Global/ValidatedInput' | |
import { useState, useContext, useEffect, useMemo } from 'react' | ||
import * as _consts from '../Cashout.consts' | ||
import * as context from '@/context' | ||
import { useBalance } from '@/hooks/useBalance' | ||
import { useAuth } from '@/context/authContext' | ||
import { useCreateLink } from '@/components/Create/useCreateLink' | ||
import * as assets from '@/assets' | ||
import { formatIban, validateBankAccount, floorFixed } from '@/utils' | ||
import { formatIban, validateBankAccount, floorFixed, balanceByToken } from '@/utils' | ||
import { FAQComponent } from './Faq.comp' | ||
import { RecipientInfoComponent } from './RecipientInfo.comp' | ||
import Icon from '@/components/Global/Icon' | ||
|
@@ -19,6 +18,8 @@ import { MAX_CASHOUT_LIMIT, MIN_CASHOUT_LIMIT } from '@/components/Offramp/Offra | |
import { Button, Card } from '@/components/0_Bruddle' | ||
import { useWallet } from '@/context/walletContext' | ||
import { sanitizeBankAccount } from '@/utils/format.utils' | ||
import { PEANUT_WALLET_CHAIN, PEANUT_WALLET_TOKEN } from '@/constants' | ||
import { useWeb3Modal } from '@web3modal/wagmi/react' | ||
|
||
export const InitialCashoutView = ({ | ||
onNext, | ||
|
@@ -31,11 +32,15 @@ export const InitialCashoutView = ({ | |
setOfframpForm, | ||
crossChainDetails, | ||
}: _consts.ICashoutScreenProps) => { | ||
const { selectedTokenPrice, inputDenomination, selectedChainID, selectedTokenAddress } = useContext( | ||
context.tokenSelectorContext | ||
) | ||
const { | ||
selectedTokenPrice, | ||
inputDenomination, | ||
selectedChainID, | ||
setSelectedChainID, | ||
selectedTokenAddress, | ||
setSelectedTokenAddress, | ||
} = useContext(context.tokenSelectorContext) | ||
|
||
const { balances, hasFetchedBalances, balanceByToken } = useBalance() | ||
const { user, fetchUser, isFetchingUser } = useAuth() | ||
const [, setUserType] = useState<'NEW' | 'EXISTING' | undefined>(undefined) | ||
|
||
|
@@ -68,7 +73,8 @@ export const InitialCashoutView = ({ | |
|
||
const { prepareCreateLinkWrapper } = useCreateLink() | ||
|
||
const { isConnected, signInModal } = useWallet() | ||
const { isConnected, signInModal, selectedWallet, isExternalWallet, isPeanutWallet } = useWallet() | ||
const { open: web3modalOpen } = useWeb3Modal() | ||
|
||
const isBelowMinLimit = useMemo(() => { | ||
if (!usdValue) return false | ||
|
@@ -190,11 +196,14 @@ export const InitialCashoutView = ({ | |
} | ||
|
||
const maxValue = useMemo(() => { | ||
const balance = balanceByToken(selectedChainID, selectedTokenAddress) | ||
if (!selectedWallet?.balances) { | ||
return selectedWallet?.balance.toString() ?? '' | ||
} | ||
const balance = balanceByToken(selectedWallet.balances, selectedChainID, selectedTokenAddress) | ||
if (!balance) return '' | ||
// 6 decimal places, prettier | ||
return floorFixed(balance.amount, 6) | ||
}, [selectedChainID, selectedTokenAddress, balanceByToken]) | ||
}, [selectedChainID, selectedTokenAddress, selectedWallet?.balances, selectedWallet?.balance]) | ||
|
||
useEffect(() => { | ||
if (!_tokenValue) return | ||
|
@@ -211,6 +220,13 @@ export const InitialCashoutView = ({ | |
} | ||
}, [_tokenValue, inputDenomination]) | ||
|
||
useEffect(() => { | ||
if (isPeanutWallet) { | ||
setSelectedChainID(PEANUT_WALLET_CHAIN.id.toString()) | ||
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. nice |
||
setSelectedTokenAddress(PEANUT_WALLET_TOKEN) | ||
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. thought: we miiiiiiiiiiight want to support other tokens in the future. Depends on demand and situation. E.g. maybe we find out ppinta token is great for onboarding and we run a promotion campaign partnering with them. Not sure what the best to do in that case would be here 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 is a great point and we have to think how we handle it. The idea of PW is absolute abstraction, but that comes with reduced functionality, like you mentioned (and PNT or MORFI are great onboarding tools). One inmediate issue I can see is what do we do with claim links that contains tokens not supported for x-chain |
||
} | ||
}, [isPeanutWallet]) | ||
|
||
// Update the bank account selection handler | ||
const handleBankAccountSelect = (accountIdentifier: string) => { | ||
if (!xchainAllowed) return | ||
|
@@ -270,16 +286,20 @@ export const InitialCashoutView = ({ | |
Minimum amount is ${MIN_CASHOUT_LIMIT} | ||
</div> | ||
)} | ||
<TokenSelector classNameButton="max-w-[100%]" /> | ||
{hasFetchedBalances && balances.length === 0 && ( | ||
<div | ||
onClick={() => { | ||
open() | ||
}} | ||
className="cursor-pointer text-h9 underline" | ||
> | ||
( Buy Tokens ) | ||
</div> | ||
{isExternalWallet && ( | ||
<> | ||
<TokenSelector classNameButton="max-w-[100%]" /> | ||
{selectedWallet!.balances!.length === 0 && ( | ||
<div | ||
onClick={() => { | ||
web3modalOpen() | ||
}} | ||
className="cursor-pointer text-h9 underline" | ||
> | ||
( Buy Tokens ) | ||
</div> | ||
)} | ||
</> | ||
)} | ||
<div className="flex w-full flex-col justify-center gap-3"> | ||
<RecipientInfoComponent /> | ||
|
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: balance is bigint. Might be a rlly large number with 21 decimal places (js formates as scientific notation). Not sure toFixed(2) would help here
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.
formatUnit handles part of that, it will return the USD(C) amount. Unless the balance is too big, in that case you are right and we would have problems with scientific notation.
I have this task https://www.notion.so/peanutprotocol/Bug-X-chain-from-amount-formatted-wrongly-to-scientific-notation-141838117579807abd12ee396cbfee97?pvs=4 to deal with that