-
Notifications
You must be signed in to change notification settings - Fork 1
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
implement offramp summary popup #394
base: polygon-prototype-staging
Are you sure you want to change the base?
Changes from 2 commits
ad255d9
5336a7e
3cc0458
09cfa1f
652c3bc
4020b0b
090c6f4
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,140 @@ | ||||||
import { ArrowDownIcon } from '@heroicons/react/20/solid'; | ||||||
import { FC } from 'preact/compat'; | ||||||
import Big from 'big.js'; | ||||||
|
||||||
import { InputTokenDetails, OutputTokenDetails } from '../../constants/tokenConfig'; | ||||||
import { UseTokenOutAmountResult } from '../../hooks/nabla/useTokenAmountOut'; | ||||||
import { useGetAssetIcon } from '../../hooks/useGetAssetIcon'; | ||||||
import { useOfframpFees } from '../../hooks/useOfframpFees'; | ||||||
import { useNetwork } from '../../contexts/network'; | ||||||
import { Networks } from '../../helpers/networks'; | ||||||
|
||||||
import { ExchangeRate } from '../ExchangeRate'; | ||||||
import { NetworkIcon } from '../NetworkIcon'; | ||||||
import { Dialog } from '../Dialog'; | ||||||
|
||||||
interface AssetDisplayProps { | ||||||
amount: string; | ||||||
symbol: string; | ||||||
iconSrc: string; | ||||||
iconAlt: string; | ||||||
} | ||||||
|
||||||
const AssetDisplay = ({ amount, symbol, iconSrc, iconAlt }: AssetDisplayProps) => ( | ||||||
<div className="flex items-center justify-between w-full"> | ||||||
<span className="text-lg font-bold"> | ||||||
{amount} {symbol} | ||||||
</span> | ||||||
<img src={iconSrc} alt={iconAlt} className="w-8 h-8" /> | ||||||
</div> | ||||||
); | ||||||
|
||||||
interface FeeDetailsProps { | ||||||
network: Networks; | ||||||
feesCost: string; | ||||||
fiatSymbol: string; | ||||||
tokenOutAmount: UseTokenOutAmountResult; | ||||||
fromToken: InputTokenDetails; | ||||||
anchorUrl?: string; | ||||||
} | ||||||
|
||||||
const FeeDetails = ({ network, feesCost, fiatSymbol, tokenOutAmount, fromToken, anchorUrl }: FeeDetailsProps) => ( | ||||||
<section className="mt-6"> | ||||||
<div className="flex justify-between mb-2"> | ||||||
<p>Offramp fees</p> | ||||||
<p className="flex items-center gap-2"> | ||||||
<NetworkIcon network={network} className="w-4 h-4" /> | ||||||
<strong> | ||||||
{feesCost} {fiatSymbol} | ||||||
</strong> | ||||||
</p> | ||||||
</div> | ||||||
<div className="flex justify-between mb-2"> | ||||||
<p>Quote</p> | ||||||
<p> | ||||||
<strong> | ||||||
<ExchangeRate tokenOutData={tokenOutAmount} fromToken={fromToken} toTokenSymbol={fiatSymbol} /> | ||||||
($1.00) | ||||||
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. While it's in the reference image, I think we should remove this. As far as I understand, the idea of this '($1.00)' would be to indicate the dollar value of the resulting quote. This means, in order to make this value make sense, we would need to fetch the ARS or EUR to USD exchange rate from somewhere else and compare our output token amount to that. I think this is too complex and we should rather remove it for now. If this becomes a hard requirement later, we can still add it in the future.
Suggested change
|
||||||
</strong> | ||||||
</p> | ||||||
</div> | ||||||
<div className="flex justify-between"> | ||||||
<p>Partner - {anchorUrl ? new URL(anchorUrl).origin : ''}</p> | ||||||
</div> | ||||||
</section> | ||||||
); | ||||||
|
||||||
interface OfframpSummaryDialogProps { | ||||||
fromToken: InputTokenDetails; | ||||||
toToken: OutputTokenDetails; | ||||||
formToAmount: string; | ||||||
fromAmountString: string; | ||||||
visible: boolean; | ||||||
tokenOutAmount: UseTokenOutAmountResult; | ||||||
anchorUrl?: string; | ||||||
onSubmit: () => void; | ||||||
onClose: () => void; | ||||||
} | ||||||
|
||||||
export const OfframpSummaryDialog: FC<OfframpSummaryDialogProps> = ({ | ||||||
fromToken, | ||||||
toToken, | ||||||
visible, | ||||||
formToAmount, | ||||||
fromAmountString, | ||||||
tokenOutAmount, | ||||||
anchorUrl, | ||||||
onClose, | ||||||
onSubmit, | ||||||
}) => { | ||||||
const { selectedNetwork } = useNetwork(); | ||||||
const fromIcon = useGetAssetIcon(fromToken.networkAssetIcon); | ||||||
const toIcon = useGetAssetIcon(toToken.fiat.assetIcon); | ||||||
|
||||||
const { feesCost } = useOfframpFees(tokenOutAmount.data?.roundedDownQuotedAmountOut || Big(0), toToken); | ||||||
|
||||||
if (!visible) return null; | ||||||
if (!anchorUrl) return null; | ||||||
|
||||||
const content = ( | ||||||
<div className="flex flex-col justify-center"> | ||||||
<AssetDisplay | ||||||
iconAlt={fromToken.networkAssetIcon} | ||||||
symbol={fromToken.assetSymbol} | ||||||
amount={fromAmountString} | ||||||
iconSrc={fromIcon} | ||||||
/> | ||||||
<ArrowDownIcon className="w-4 h-4 my-2" /> | ||||||
<AssetDisplay amount={formToAmount} symbol={toToken.fiat.symbol} iconSrc={toIcon} iconAlt={toToken.fiat.symbol} /> | ||||||
<FeeDetails | ||||||
fiatSymbol={toToken.fiat.symbol} | ||||||
fromToken={fromToken} | ||||||
tokenOutAmount={tokenOutAmount} | ||||||
network={selectedNetwork} | ||||||
feesCost={feesCost} | ||||||
anchorUrl={anchorUrl} | ||||||
/> | ||||||
</div> | ||||||
); | ||||||
const actions = ( | ||||||
// eslint-disable-next-line react/jsx-no-target-blank | ||||||
<a | ||||||
href={anchorUrl} | ||||||
target="_blank" | ||||||
rel="opener" //noopener forbids the use of postMessages. | ||||||
className="btn-vortex-primary btn rounded-xl" | ||||||
style={{ flex: '1 1 calc(50% - 0.75rem/2)' }} | ||||||
onClick={(e) => { | ||||||
e.preventDefault(); | ||||||
onSubmit(); | ||||||
window.open(anchorUrl, '_blank'); | ||||||
}} | ||||||
> | ||||||
Continue with Partner | ||||||
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. We should add the 'external' icon that indicates that clicking this button/link will open a new tab. |
||||||
</a> | ||||||
); | ||||||
|
||||||
return ( | ||||||
<Dialog content={content} visible={visible} actions={actions} headerText="You're offramping" onClose={onClose} /> | ||||||
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 just realized that we should change this title since we don't want to call it 'offramp' but use the term 'sell' everywhere.
Suggested change
|
||||||
); | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Big from 'big.js'; | ||
import { calculateTotalReceive } from '../components/FeeCollapse'; | ||
import { roundDownToTwoDecimals } from '../helpers/parseNumbers'; | ||
import { OutputTokenDetails } from '../constants/tokenConfig'; | ||
|
||
export const useOfframpFees = (toAmount: Big, toToken: OutputTokenDetails) => { | ||
const toAmountFixed = roundDownToTwoDecimals(toAmount); | ||
const totalReceive = calculateTotalReceive(toAmount, toToken); | ||
const totalReceiveFormatted = roundDownToTwoDecimals(Big(totalReceive)); | ||
const feesCost = roundDownToTwoDecimals(Big(toAmountFixed || 0).sub(totalReceive)); | ||
|
||
return { | ||
toAmountFixed, | ||
totalReceive, | ||
totalReceiveFormatted, | ||
feesCost, | ||
}; | ||
}; |
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.
We should add in the brackets how this offramp fee is comprised. (The code I suggested is not enough, we still need to transform the values to something easy to read for the user)