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

Commit 293b843

Browse files
committed
feat(app): improved add token screen
1 parent a6d2de5 commit 293b843

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

app/src/app/(nav)/[account]/tokens/[address].tsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ function TokenScreen_() {
8787
priceId: t?.pythUsdPriceId ?? undefined,
8888
},
8989
});
90-
const [icon, priceId] = watch(['name', 'symbol', 'icon', 'priceId']);
91-
const iconValid = !!tryOrIgnore(() => icon && new URL(icon));
90+
const priceId = watch('priceId');
9291

9392
return (
9493
<Pane flex>
@@ -136,14 +135,6 @@ function TokenScreen_() {
136135
placeholder="0x..."
137136
control={control}
138137
/>
139-
140-
{!priceId && (
141-
<Link asChild href={PYTH_PRICE_FEEDS_URL}>
142-
<Button mode="outlined" icon={ExternalLinkIcon}>
143-
Pyth price feeds
144-
</Button>
145-
</Link>
146-
)}
147138
</View>
148139

149140
<Actions horizontal style={styles.actions}>
@@ -165,6 +156,14 @@ function TokenScreen_() {
165156
>
166157
{query.token ? 'Update' : 'Add'}
167158
</FormSubmitButton>
159+
160+
{!priceId && (
161+
<Link asChild href={PYTH_PRICE_FEEDS_URL}>
162+
<Button mode="outlined" icon={ExternalLinkIcon}>
163+
Pyth price feeds
164+
</Button>
165+
</Link>
166+
)}
168167
</Actions>
169168
</Scrollable>
170169
</Pane>

app/src/app/(nav)/token/add.tsx app/src/app/(nav)/[account]/tokens/add.tsx

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
import { Appbar } from '#/Appbar/Appbar';
2-
import { FormSelectChip } from '#/fields/FormSelectChip';
32
import { FormSubmitButton } from '#/fields/FormSubmitButton';
43
import { FormTextField } from '#/fields/FormTextField';
54
import { Actions } from '#/layout/Actions';
6-
import { ScrollableScreenSurface } from '#/layout/ScrollableScreenSurface';
75
import { zodResolver } from '@hookform/resolvers/zod';
8-
import { CHAIN_ENTRIES } from '@network/chains';
96
import { createStyles } from '@theme/styles';
107
import { useRouter } from 'expo-router';
11-
import { asUAddress } from 'lib';
8+
import { asChain, asUAddress } from 'lib';
129
import { useForm } from 'react-hook-form';
1310
import { View } from 'react-native';
1411
import { z } from 'zod';
15-
import { useSelectedChain } from '~/hooks/useSelectedAccount';
1612
import { zAddress, zChain } from '~/lib/zod';
1713
import { ADDRESS_FIELD_RULES } from '~/util/form.rules';
14+
import { AccountParams } from '../_layout';
15+
import { useLocalParams } from '~/hooks/useLocalParams';
16+
import { Pane } from '#/layout/Pane';
17+
import { Scrollable } from '#/Scrollable';
18+
import { FormChainSelector } from '#/fields/FormChainSelector';
1819

1920
const scheme = z.object({
2021
address: zAddress(),
2122
chain: zChain(),
2223
});
2324

25+
const Params = AccountParams;
26+
2427
export default function AddTokenScreen() {
28+
const { account } = useLocalParams(Params);
2529
const router = useRouter();
2630

2731
const { control, handleSubmit } = useForm<z.infer<typeof scheme>>({
2832
resolver: zodResolver(scheme),
29-
defaultValues: { chain: useSelectedChain() },
33+
defaultValues: { chain: asChain(account) },
3034
});
3135

3236
return (
33-
<>
34-
<Appbar headline="Add token" />
37+
<Pane flex>
38+
<Appbar mode="large" headline="Add token" />
3539

36-
<ScrollableScreenSurface>
40+
<Scrollable>
3741
<View style={styles.container}>
3842
<FormTextField
3943
label="Address"
@@ -47,36 +51,30 @@ export default function AddTokenScreen() {
4751
}}
4852
/>
4953

50-
<FormSelectChip
51-
name="chain"
52-
control={control}
53-
entries={CHAIN_ENTRIES}
54-
chipProps={{ style: styles.chain }}
55-
/>
54+
<FormChainSelector name="chain" control={control} />
5655
</View>
5756

58-
<Actions>
57+
<Actions horizontal>
5958
<FormSubmitButton
6059
mode="contained"
6160
control={control}
6261
onPress={handleSubmit(({ address, chain }) =>
6362
router.replace({
64-
pathname: '/(nav)/token/[address]',
65-
params: { address: asUAddress(address, chain) },
63+
pathname: '/(nav)/[account]/tokens/[address]',
64+
params: { account, address: asUAddress(address, chain) },
6665
}),
6766
)}
6867
>
6968
Continue
7069
</FormSubmitButton>
7170
</Actions>
72-
</ScrollableScreenSurface>
73-
</>
71+
</Scrollable>
72+
</Pane>
7473
);
7574
}
7675

7776
const styles = createStyles({
7877
container: {
79-
marginVertical: 16,
8078
marginHorizontal: 16,
8179
gap: 16,
8280
},

0 commit comments

Comments
 (0)