Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.

Commit fef5991

Browse files
authored
Merge pull request #271 from zallo-labs/Z-307-improved-send-screen
Z 307 improved send screen
2 parents 380ef43 + 268a939 commit fef5991

40 files changed

+764
-296
lines changed

app/src/app/(modal)/_layout.tsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import { Slot, Stack } from 'expo-router';
1+
import { Slot } from 'expo-router';
22

33
export default function SheetLayout() {
44
return (
55
<>
6-
<Stack.Screen
7-
options={{
8-
presentation: 'transparentModal',
9-
headerShown: false,
10-
animation: 'fade',
11-
animationDuration: 100,
12-
}}
13-
/>
146
<Slot />
157
</>
168
);

app/src/app/(nav)/[account]/(home)/_layout.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Panes } from '#/layout/Panes';
2-
import { Slot, Stack } from 'expo-router';
2+
import { Slot } from 'expo-router';
33
import { HomePane } from './index';
44

55
export default function HomeLayout() {
66
return (
77
<Panes>
8-
<Stack.Screen options={{ headerShown: false }} />
98
<HomePane />
109
<Slot />
1110
</Panes>

app/src/app/(nav)/[account]/(home)/activity/_layout.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Panes } from '#/layout/Panes';
21
import { Slot } from 'expo-router';
32
import { ActivityPane } from './index';
43

app/src/app/(nav)/[account]/(home)/index.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ function HomePane_() {
6363

6464
return (
6565
<Pane flex padding={false}>
66+
<Appbar
67+
leading="menu"
68+
center
69+
headline={<AccountSelector account={account} />}
70+
style={styles.appbar}
71+
noPadding
72+
/>
6673
<FlatList
6774
contentContainerStyle={styles.container}
6875
ListHeaderComponent={
6976
<>
70-
<Appbar
71-
leading="menu"
72-
center
73-
headline={<AccountSelector account={account} />}
74-
style={styles.appbar}
75-
noPadding
76-
/>
7777
<QuickActions account={address} />
7878
<ActivitySection account={account} user={user} />
7979
<AccountValue tokens={tokens} />
+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { PaneSkeleton } from '#/skeleton/PaneSkeleton';
2+
import { withSuspense } from '#/skeleton/withSuspense';
3+
import { zUAddress } from '~/lib/zod';
4+
import { AccountParams } from '../_layout';
5+
import { useLocalParams } from '~/hooks/useLocalParams';
6+
import { graphql } from 'relay-runtime';
7+
import { useState } from 'react';
8+
import Decimal from 'decimal.js';
9+
import { z } from 'zod';
10+
import { Pane } from '#/layout/Pane';
11+
import { TokenAmountInput } from '#/token/TokenAmountInput';
12+
import { useLazyQuery } from '~/api';
13+
import { send_SendScreen2Query } from '~/api/__generated__/send_SendScreen2Query.graphql';
14+
import { useSelectedToken } from '~/hooks/useSelectToken';
15+
import { asChain } from 'lib';
16+
import { Scrollable } from '#/Scrollable';
17+
import { Appbar } from '#/Appbar/Appbar';
18+
import { View } from 'react-native';
19+
import { createStyles, useStyles } from '@theme/styles';
20+
import { SendMode, SendModeChips } from '#/send/SendModeChips';
21+
import { ItemList } from '#/layout/ItemList';
22+
import { SendAccount } from '#/send/SendAccount';
23+
import { SendTo } from '#/send/SendTo';
24+
import { match } from 'ts-pattern';
25+
import { TransferMode } from '#/send/TransferMode';
26+
import { TransferFromMode } from '#/send/TransferFromMode';
27+
import { Text } from 'react-native-paper';
28+
29+
const Query = graphql`
30+
query send_SendScreen2Query($account: UAddress!, $token: UAddress!) {
31+
token(address: $token) @required(action: THROW) {
32+
id
33+
address
34+
decimals
35+
balance(input: { account: $account })
36+
price {
37+
usd
38+
}
39+
...TokenAmountInput_token
40+
...SendAccount_token @arguments(account: $account)
41+
...TransferMode_token
42+
...TransferFromMode_token
43+
}
44+
45+
account(address: $account) @required(action: THROW) {
46+
address
47+
...useProposeTransaction_account
48+
...SendAccount_account
49+
...TransferMode_account
50+
...TransferFromMode_account
51+
}
52+
}
53+
`;
54+
55+
export const SendScreenParams = AccountParams.extend({
56+
to: zUAddress().optional(),
57+
});
58+
export type SendScreenParams = z.infer<typeof SendScreenParams>;
59+
60+
function SendScreen() {
61+
const params = useLocalParams(SendScreenParams);
62+
const { styles } = useStyles(stylesheet);
63+
const chain = asChain(params.account);
64+
65+
const { token, account } = useLazyQuery<send_SendScreen2Query>(Query, {
66+
account: params.account,
67+
token: useSelectedToken(chain),
68+
});
69+
70+
const [amount, setAmount] = useState<Decimal>(new Decimal(0));
71+
const [mode, setMode] = useState<SendMode>('transfer');
72+
const [to, setTo] = useState(params.to);
73+
74+
const warning = amount.gt(token.balance) && 'Insufficient balance';
75+
76+
return (
77+
<Pane flex padding={false}>
78+
<Scrollable contentContainerStyle={styles.container}>
79+
<Appbar noPadding />
80+
<View style={styles.inputContainer}>
81+
<TokenAmountInput
82+
account={account.address}
83+
amount={amount}
84+
onChange={setAmount}
85+
token={token}
86+
/>
87+
<Text variant="headlineMedium" style={styles.warning}>
88+
{warning}
89+
</Text>
90+
</View>
91+
92+
<View style={styles.sendModeChipsContainer}>
93+
<SendModeChips mode={mode} onChange={setMode} />
94+
</View>
95+
96+
<ItemList>
97+
<SendAccount account={account} token={token} style={styles.item} />
98+
<SendTo chain={chain} to={to} onChange={setTo} containerStyle={styles.item} />
99+
</ItemList>
100+
101+
{match(mode)
102+
.with('transfer', () => (
103+
<TransferMode account={account} token={token} to={to} amount={amount} />
104+
))
105+
.with('transferFrom', () => (
106+
<TransferFromMode account={account} token={token} to={to} amount={amount} />
107+
))
108+
.exhaustive()}
109+
</Scrollable>
110+
</Pane>
111+
);
112+
}
113+
114+
const stylesheet = createStyles(({ colors, padding, negativeMargin }) => ({
115+
container: {
116+
gap: 8,
117+
paddingHorizontal: padding,
118+
},
119+
inputContainer: {
120+
marginVertical: 16,
121+
},
122+
sendModeChipsContainer: {
123+
marginHorizontal: negativeMargin,
124+
},
125+
item: {
126+
backgroundColor: colors.surface,
127+
},
128+
warning: {
129+
color: colors.warning,
130+
},
131+
}));
132+
133+
export default withSuspense(SendScreen, <PaneSkeleton />);
134+
135+
export { ErrorBoundary } from '#/ErrorBoundary';

app/src/app/(nav)/[account]/_layout.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useLayoutEffect } from 'react';
2-
import { Redirect, Stack, useLocalSearchParams, useRouter } from 'expo-router';
2+
import { Redirect, Slot, useLocalSearchParams, useRouter } from 'expo-router';
33
import {
44
ErrorBoundary as BaseErrorBoundary,
55
ErrorBoundaryProps,
@@ -9,7 +9,6 @@ import NotFound from '~/app/+not-found';
99
import { useLocalParams } from '~/hooks/useLocalParams';
1010
import { useSelectedAccount, useSetSelectedAccont } from '~/hooks/useSelectedAccount';
1111
import { zUAddress } from '~/lib/zod';
12-
import { AppbarHeader } from '#/Appbar/AppbarHeader';
1312
import { withSuspense } from '#/skeleton/withSuspense';
1413
import { Splash } from '#/Splash';
1514
import { graphql } from 'relay-runtime';
@@ -52,12 +51,7 @@ export function AccountLayout() {
5251
// Redirect to the home page if account isn't found
5352
if (!found) return <Redirect href="/" />;
5453

55-
return (
56-
<>
57-
<Stack.Screen options={{ headerShown: false }} />
58-
<Stack screenOptions={{ header: (props) => <AppbarHeader {...props} /> }} />
59-
</>
60-
);
54+
return <Slot />;
6155
}
6256

6357
export default withSuspense(AccountLayout, <Splash />);

app/src/app/(nav)/[account]/send.tsx

-152
This file was deleted.

0 commit comments

Comments
 (0)