-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(withdraw-dialog): withdraw dialog rewrite 1/n (#1413)
- Loading branch information
Showing
15 changed files
with
423 additions
and
10 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
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
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,67 @@ | ||
import { EventHandler } from 'react'; | ||
|
||
import { SyntheticInputEvent } from 'react-number-format/types/types'; | ||
import styled from 'styled-components'; | ||
|
||
import { STRING_KEYS } from '@/constants/localization'; | ||
import { WalletNetworkType } from '@/constants/wallets'; | ||
|
||
import { useAccounts } from '@/hooks/useAccounts'; | ||
import { useStringGetter } from '@/hooks/useStringGetter'; | ||
|
||
import { AssetIcon } from '@/components/AssetIcon'; | ||
import { Icon, IconName } from '@/components/Icon'; | ||
|
||
type AddressInputProps = { | ||
value: string; | ||
onChange: (newValue: string) => void; | ||
_destinationChain: string; | ||
onDestinationClicked: () => void; | ||
}; | ||
|
||
export const AddressInput = ({ | ||
value, | ||
onChange, | ||
_destinationChain, | ||
onDestinationClicked, | ||
}: AddressInputProps) => { | ||
const stringGetter = useStringGetter(); | ||
const { sourceAccount } = useAccounts(); | ||
|
||
const onValueChange: EventHandler<SyntheticInputEvent> = (e) => { | ||
onChange(e.target.value); | ||
}; | ||
|
||
return ( | ||
<div tw="flex items-center justify-between gap-0.5 rounded-0.75 border border-solid border-color-border bg-color-layer-4 px-1.25 py-0.75"> | ||
<div tw="flex flex-1 flex-col gap-0.5 text-small"> | ||
<div>{stringGetter({ key: STRING_KEYS.ADDRESS })}</div> | ||
<input | ||
placeholder={sourceAccount.address} | ||
tw="flex-1 bg-color-layer-4 text-large font-medium outline-none" | ||
value={value} | ||
onChange={onValueChange} | ||
/> | ||
</div> | ||
<button | ||
tw="flex items-center gap-0.75 rounded-0.75 border border-solid border-color-layer-6 bg-color-layer-5 px-0.5 py-0.375" | ||
type="button" | ||
disabled={sourceAccount.chain === WalletNetworkType.Solana} | ||
onClick={onDestinationClicked} | ||
> | ||
<div tw="flex items-center gap-0.5"> | ||
<AssetIcon tw="h-[2rem] w-[2rem]" symbol="ETH" /> | ||
<div>Ethereum</div> | ||
</div> | ||
{sourceAccount.chain !== WalletNetworkType.Solana && ( | ||
<$CaretIcon size="10px" iconName={IconName.Caret} /> | ||
)} | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
const $CaretIcon = styled(Icon)` | ||
transform: rotate(-90deg); | ||
color: var(--color-text-0); | ||
`; |
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,87 @@ | ||
import { EventHandler } from 'react'; | ||
|
||
import { BonsaiCore } from '@/abacus-ts/ontology'; | ||
import { SyntheticInputEvent } from 'react-number-format/types/types'; | ||
|
||
import { STRING_KEYS } from '@/constants/localization'; | ||
import { USDC_DECIMALS } from '@/constants/tokens'; | ||
|
||
import { useStringGetter } from '@/hooks/useStringGetter'; | ||
|
||
import { Output, OutputType } from '@/components/Output'; | ||
|
||
import { useAppSelector } from '@/state/appTypes'; | ||
|
||
import { orEmptyObj } from '@/lib/typeUtils'; | ||
|
||
type AmountInputProps = { | ||
value: string; | ||
onChange: (newValue: string) => void; | ||
}; | ||
|
||
export const AmountInput = ({ value, onChange }: AmountInputProps) => { | ||
const stringGetter = useStringGetter(); | ||
|
||
const onValueChange: EventHandler<SyntheticInputEvent> = (e) => { | ||
onChange(e.target.value); | ||
}; | ||
|
||
const isLoading = | ||
useAppSelector(BonsaiCore.account.parentSubaccountSummary.loading) === 'pending'; | ||
|
||
const { freeCollateral } = orEmptyObj( | ||
useAppSelector(BonsaiCore.account.parentSubaccountSummary.data) | ||
); | ||
|
||
const onClickMax = () => { | ||
if (!freeCollateral) return; | ||
onChange(freeCollateral.toString()); | ||
}; | ||
|
||
const onMaxDisabled = !freeCollateral || isLoading; | ||
|
||
return ( | ||
<div tw="flex items-center justify-between gap-0.5 rounded-0.75 border border-solid border-color-border bg-color-layer-4 px-1.25 py-0.75"> | ||
<div tw="flex flex-1 flex-col gap-0.5 text-small"> | ||
<div> | ||
{stringGetter({ key: STRING_KEYS.AMOUNT })} | ||
|
||
{freeCollateral && ( | ||
<> | ||
<span> • </span> | ||
<Output | ||
tw="inline font-medium text-color-text-0" | ||
fractionDigits={USDC_DECIMALS} | ||
slotRight={` ${stringGetter({ key: STRING_KEYS.AVAILABLE })}`} | ||
value={freeCollateral} | ||
type={OutputType.Fiat} | ||
/> | ||
</> | ||
)} | ||
|
||
{freeCollateral && ( | ||
<> | ||
<span> • </span> | ||
<button | ||
disabled={onMaxDisabled} | ||
onClick={onClickMax} | ||
type="button" | ||
tw="font-medium" | ||
style={{ color: onMaxDisabled ? 'var(--color-text-0)' : 'var(--color-accent)' }} | ||
> | ||
{stringGetter({ key: STRING_KEYS.MAX })} | ||
</button> | ||
</> | ||
)} | ||
</div> | ||
<input | ||
type="number" | ||
placeholder="0.00" | ||
tw="flex-1 bg-color-layer-4 text-large font-medium outline-none" | ||
value={value} | ||
onChange={onValueChange} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; |
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 { Dispatch, Fragment, SetStateAction } from 'react'; | ||
|
||
import { mainnet } from 'viem/chains'; | ||
|
||
import { CHAIN_INFO } from '@/constants/chains'; | ||
|
||
import { AssetIcon } from '@/components/AssetIcon'; | ||
|
||
export const ChainSelect = ({ | ||
onBack, | ||
selectedChain, | ||
setSelectedChain, | ||
}: { | ||
onBack: () => void; | ||
selectedChain: string; | ||
setSelectedChain: Dispatch<SetStateAction<string>>; | ||
}) => { | ||
const onChainClick = (newChainId: string) => () => { | ||
setSelectedChain(newChainId); | ||
onBack(); | ||
}; | ||
|
||
return ( | ||
<div tw="flex flex-col gap-0.5 py-1"> | ||
<div tw="flex flex-col"> | ||
{[mainnet.id].map((chain) => { | ||
const chainId = chain.toString(); | ||
|
||
return ( | ||
<Fragment key={chainId}> | ||
<button | ||
onClick={onChainClick(chainId)} | ||
type="button" | ||
style={{ | ||
backgroundColor: chainId === selectedChain ? 'var(--color-layer-4)' : undefined, | ||
}} | ||
tw="flex w-full justify-between px-1.25 py-1 hover:bg-color-layer-4" | ||
key={chainId} | ||
> | ||
<div tw="flex items-center gap-0.75"> | ||
<AssetIcon tw="h-[2rem] w-[2rem]" symbol="ETH" /> | ||
<div tw="flex flex-col items-start gap-0.125"> | ||
<div tw="text-medium font-medium">{CHAIN_INFO[chainId]?.name}</div> | ||
</div> | ||
</div> | ||
</button> | ||
</Fragment> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.