Skip to content

Commit

Permalink
feat: wallet settings screens
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian committed Aug 28, 2024
1 parent 8dfe301 commit c10b0e5
Show file tree
Hide file tree
Showing 87 changed files with 2,133 additions and 851 deletions.
4 changes: 2 additions & 2 deletions .ls-lint.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ls:
.ts: regex:[a-z0-9\-\._]+
.tsx: regex:[a-z0-9\-\._]+
.tsx: regex:[a-z0-9\-\[\]\._]+
.js: regex:[a-z0-9\-\._]+
.dir: regex:[a-z0-9\(\)\-\._]+
.dir: regex:[a-z0-9\(\)\[\]\-\._]+

ignore:
- .git
Expand Down
7 changes: 6 additions & 1 deletion apps/mobile/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ yarn-error.*
*.tsbuildinfo

# Detox artifacts
artifacts/
artifacts/
# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
13 changes: 10 additions & 3 deletions apps/mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": false
},
Expand Down Expand Up @@ -45,7 +47,9 @@
[
"expo-asset",
{
"assets": ["src/assets/scripts/injected-provider.js"]
"assets": [
"src/assets/scripts/injected-provider.js"
]
}
],
[
Expand All @@ -63,6 +67,9 @@
"projectId": "c03c1f22-be7b-4b76-aa1b-3ebf716bd2cc"
}
},
"owner": "leather-wallet"
"owner": "leather-wallet",
"experiments": {
"typedRoutes": true
}
}
}
1 change: 1 addition & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"metro-cache": "0.80.5",
"metro-config": "0.80.5",
"metro-resolver": "0.80.5",
"moment": "2.30.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.74.1",
Expand Down
54 changes: 54 additions & 0 deletions apps/mobile/src/app/wallet/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { t } from '@lingui/macro';
import { useLingui } from '@lingui/react';
import { Stack, useRouter } from 'expo-router';

import { Box, Text, TouchableOpacity } from '@leather.io/ui/native';

export const ActionBarContext = createContext<{ ref: RefObject<ActionBarMethods> | null }>({
ref: null,
});
Expand Down Expand Up @@ -49,6 +51,36 @@ export default function StackLayout() {
/>
);

function NavigationWalletSettings(title: string = t`Settings`) {
return (
<SimpleHeader
insets={insets}
left={<BackButtonHeader onPress={() => router.back()} />}
center={<TitleHeader title={title} />}
right={
<TouchableOpacity
px="3"
onPress={() => {
// TODO: open network settings
// either modal or screen
}}
>
<Box
p="1"
bg="ink.background-secondary"
borderWidth={1}
borderColor="ink.border-transparent"
borderRadius="xs"
>
<Text variant="label03" color="ink.text-subdued">
{t`Testnet`}
</Text>
</Box>
</TouchableOpacity>
}
/>
);
}
const NavigationDeveloperConsole = (
<SimpleHeader
insets={insets}
Expand All @@ -69,6 +101,28 @@ export default function StackLayout() {
<Stack.Screen name="recover-wallet" options={{ header: () => NavigationBackSimple }} />
<Stack.Screen name="secure-your-wallet" options={{ header: () => NavigationBackSimple }} />
<Stack.Screen name="settings/index" options={{ header: () => NavigationSettings }} />
<Stack.Screen
name="wallet-settings/index"
options={{ header: () => NavigationWalletSettings() }}
/>
<Stack.Screen
name="wallet-settings/hidden-accounts"
options={{ header: () => NavigationWalletSettings() }}
/>
<Stack.Screen
name="wallet-settings/configure/[wallet]/[account]"
options={{ header: props => NavigationWalletSettings(props.options.title) }}
/>
<Stack.Screen
name="wallet-settings/configure/[wallet]/index"
options={{
header: props => NavigationWalletSettings(props.options.title),
}}
/>
<Stack.Screen
name="wallet-settings/configure/[wallet]/view-secret-key"
options={{ header: () => NavigationBackSimple }}
/>
<Stack.Screen
name="developer-console/index"
options={{ header: () => NavigationDeveloperConsole }}
Expand Down
16 changes: 1 addition & 15 deletions apps/mobile/src/app/wallet/create-new-wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';

import { ThemedBlurView } from '@/components/blur-view';
import { Button } from '@/components/button';
import { MnemonicWordBox } from '@/components/create-new-wallet/mnemonic-word-box';
import { MnemonicDisplay } from '@/components/create-new-wallet/mnemonic-display';
import { useToastContext } from '@/components/toast/toast-context';
import { useCreateWallet } from '@/hooks/create-wallet';
import { tempMnemonicStore } from '@/state/storage-persistors';
Expand All @@ -24,20 +24,6 @@ import {
TouchableOpacity,
} from '@leather.io/ui/native';

function MnemonicDisplay({ mnemonic }: { mnemonic: string | null }) {
if (!mnemonic) return null;

const mnemonicWords = mnemonic.split(' ');

return (
<Box justifyContent="center" flexDirection="row" flexWrap="wrap" gap="2">
{mnemonicWords.map((word, idx) => (
<MnemonicWordBox key={word + idx} wordIdx={idx + 1} word={word} />
))}
</Box>
);
}

export default function CreateNewWallet() {
const { bottom } = useSafeAreaInsets();
const theme = useTheme<Theme>();
Expand Down
11 changes: 11 additions & 0 deletions apps/mobile/src/app/wallet/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { ScrollView } from 'react-native-gesture-handler';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import { Button } from '@/components/button';
import { APP_ROUTES } from '@/constants';
import { t } from '@lingui/macro';
import { useTheme } from '@shopify/restyle';
import { useRouter } from 'expo-router';

import { Box, Text, Theme } from '@leather.io/ui/native';

export default function SettingsScreen() {
const { bottom } = useSafeAreaInsets();
const theme = useTheme<Theme>();
const router = useRouter();

return (
<Box flex={1} backgroundColor="ink.background-primary">
Expand All @@ -21,6 +25,13 @@ export default function SettingsScreen() {
}}
>
<Text>{t`Hello`}</Text>
<Button
onPress={() => {
router.navigate(APP_ROUTES.WalletWalletsSettings);
}}
buttonState="default"
title={t`Wallets (temp button)`}
/>
</ScrollView>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { useEffect, useRef } from 'react';
import { ScrollView } from 'react-native-gesture-handler';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import { getAvatarIcon } from '@/components/avatar-icon';
import { Cell } from '@/components/cell';
import { AccountCard } from '@/components/wallet-settings/account-card';
import { AccountNameModal } from '@/components/wallet-settings/account-name-modal';
import { Account } from '@/state/accounts/accounts';
import {
useAccountByIdx,
userRenamesAccount,
userTogglesHideAccount,
} from '@/state/accounts/accounts.slice';
import { makeAccountIdentifer, useAppDispatch } from '@/state/utils';
import { BottomSheetModal } from '@gorhom/bottom-sheet';
import { t } from '@lingui/macro';
import { useTheme } from '@shopify/restyle';
import { useLocalSearchParams, useNavigation } from 'expo-router';

import { Box, Eye1ClosedIcon, HeadIcon, PassportIcon, Theme } from '@leather.io/ui/native';

function ConfigureAccount({
fingerprint,
accountIndex,
account,
}: {
fingerprint: string;
accountIndex: number;
account: Account;
}) {
const { bottom } = useSafeAreaInsets();
const theme = useTheme<Theme>();
const accountNameModalRef = useRef<BottomSheetModal>(null);
const dispatch = useAppDispatch();
const navigation = useNavigation();
useEffect(() => {
navigation.setOptions({ title: account.name });
}, []);

function setName(name: string) {
dispatch(
userRenamesAccount({
accountId: makeAccountIdentifer(fingerprint, accountIndex),
name,
})
);
navigation.setOptions({ title: name });
}

function toggleHideAccount() {
dispatch(userTogglesHideAccount({ accountId: account.id }));
}

return (
<>
<Box flex={1} backgroundColor="ink.background-primary">
<ScrollView
contentContainerStyle={{
paddingTop: theme.spacing['5'],
paddingBottom: theme.spacing['5'] + bottom,
gap: theme.spacing[5],
}}
>
<Box px="5" gap="6">
<AccountCard Icon={getAvatarIcon(account.icon)} name={account.name} key={account.id} />
<Cell
title={t`Name`}
subtitle={account.name}
Icon={PassportIcon}
onPress={() => {
accountNameModalRef.current?.present();
}}
/>
<Cell title={t`Avatar`} Icon={HeadIcon} onPress={() => {}} />
<Cell title={t`Hide account`} Icon={Eye1ClosedIcon} onPress={toggleHideAccount} />
</Box>
</ScrollView>
</Box>
<AccountNameModal name={account.name} setName={setName} modalRef={accountNameModalRef} />
</>
);
}

export default function ConfigureAccountScreen() {
const params = useLocalSearchParams();
if (!params.wallet || typeof params.wallet !== 'string') {
throw new Error('No wallet fingerprint is passed in parameters');
}
if (!params.account || typeof params.account !== 'string' || Number.isNaN(+params.account)) {
throw new Error('No account is passed in parameters');
}
const fingerprint = params.wallet;
const accountIndex = +params.account;
const account = useAccountByIdx(fingerprint, accountIndex);
if (!account) {
throw new Error('No account is found');
}
return (
<ConfigureAccount fingerprint={fingerprint} accountIndex={accountIndex} account={account} />
);
}
Loading

0 comments on commit c10b0e5

Please sign in to comment.