-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from zallo-labs/Z-307-improved-send-screen
Z 307 improved send screen
- Loading branch information
Showing
40 changed files
with
764 additions
and
296 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { PaneSkeleton } from '#/skeleton/PaneSkeleton'; | ||
import { withSuspense } from '#/skeleton/withSuspense'; | ||
import { zUAddress } from '~/lib/zod'; | ||
import { AccountParams } from '../_layout'; | ||
import { useLocalParams } from '~/hooks/useLocalParams'; | ||
import { graphql } from 'relay-runtime'; | ||
import { useState } from 'react'; | ||
import Decimal from 'decimal.js'; | ||
import { z } from 'zod'; | ||
import { Pane } from '#/layout/Pane'; | ||
import { TokenAmountInput } from '#/token/TokenAmountInput'; | ||
import { useLazyQuery } from '~/api'; | ||
import { send_SendScreen2Query } from '~/api/__generated__/send_SendScreen2Query.graphql'; | ||
import { useSelectedToken } from '~/hooks/useSelectToken'; | ||
import { asChain } from 'lib'; | ||
import { Scrollable } from '#/Scrollable'; | ||
import { Appbar } from '#/Appbar/Appbar'; | ||
import { View } from 'react-native'; | ||
import { createStyles, useStyles } from '@theme/styles'; | ||
import { SendMode, SendModeChips } from '#/send/SendModeChips'; | ||
import { ItemList } from '#/layout/ItemList'; | ||
import { SendAccount } from '#/send/SendAccount'; | ||
import { SendTo } from '#/send/SendTo'; | ||
import { match } from 'ts-pattern'; | ||
import { TransferMode } from '#/send/TransferMode'; | ||
import { TransferFromMode } from '#/send/TransferFromMode'; | ||
import { Text } from 'react-native-paper'; | ||
|
||
const Query = graphql` | ||
query send_SendScreen2Query($account: UAddress!, $token: UAddress!) { | ||
token(address: $token) @required(action: THROW) { | ||
id | ||
address | ||
decimals | ||
balance(input: { account: $account }) | ||
price { | ||
usd | ||
} | ||
...TokenAmountInput_token | ||
...SendAccount_token @arguments(account: $account) | ||
...TransferMode_token | ||
...TransferFromMode_token | ||
} | ||
account(address: $account) @required(action: THROW) { | ||
address | ||
...useProposeTransaction_account | ||
...SendAccount_account | ||
...TransferMode_account | ||
...TransferFromMode_account | ||
} | ||
} | ||
`; | ||
|
||
export const SendScreenParams = AccountParams.extend({ | ||
to: zUAddress().optional(), | ||
}); | ||
export type SendScreenParams = z.infer<typeof SendScreenParams>; | ||
|
||
function SendScreen() { | ||
const params = useLocalParams(SendScreenParams); | ||
const { styles } = useStyles(stylesheet); | ||
const chain = asChain(params.account); | ||
|
||
const { token, account } = useLazyQuery<send_SendScreen2Query>(Query, { | ||
account: params.account, | ||
token: useSelectedToken(chain), | ||
}); | ||
|
||
const [amount, setAmount] = useState<Decimal>(new Decimal(0)); | ||
const [mode, setMode] = useState<SendMode>('transfer'); | ||
const [to, setTo] = useState(params.to); | ||
|
||
const warning = amount.gt(token.balance) && 'Insufficient balance'; | ||
|
||
return ( | ||
<Pane flex padding={false}> | ||
<Scrollable contentContainerStyle={styles.container}> | ||
<Appbar noPadding /> | ||
<View style={styles.inputContainer}> | ||
<TokenAmountInput | ||
account={account.address} | ||
amount={amount} | ||
onChange={setAmount} | ||
token={token} | ||
/> | ||
<Text variant="headlineMedium" style={styles.warning}> | ||
{warning} | ||
</Text> | ||
</View> | ||
|
||
<View style={styles.sendModeChipsContainer}> | ||
<SendModeChips mode={mode} onChange={setMode} /> | ||
</View> | ||
|
||
<ItemList> | ||
<SendAccount account={account} token={token} style={styles.item} /> | ||
<SendTo chain={chain} to={to} onChange={setTo} containerStyle={styles.item} /> | ||
</ItemList> | ||
|
||
{match(mode) | ||
.with('transfer', () => ( | ||
<TransferMode account={account} token={token} to={to} amount={amount} /> | ||
)) | ||
.with('transferFrom', () => ( | ||
<TransferFromMode account={account} token={token} to={to} amount={amount} /> | ||
)) | ||
.exhaustive()} | ||
</Scrollable> | ||
</Pane> | ||
); | ||
} | ||
|
||
const stylesheet = createStyles(({ colors, padding, negativeMargin }) => ({ | ||
container: { | ||
gap: 8, | ||
paddingHorizontal: padding, | ||
}, | ||
inputContainer: { | ||
marginVertical: 16, | ||
}, | ||
sendModeChipsContainer: { | ||
marginHorizontal: negativeMargin, | ||
}, | ||
item: { | ||
backgroundColor: colors.surface, | ||
}, | ||
warning: { | ||
color: colors.warning, | ||
}, | ||
})); | ||
|
||
export default withSuspense(SendScreen, <PaneSkeleton />); | ||
|
||
export { ErrorBoundary } from '#/ErrorBoundary'; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.