Skip to content

Commit 6521246

Browse files
authored
fix: In checkForUserOnBlockchain, allow same name on blockchain if same address (gnolang#98)
1 parent 24c96e0 commit 6521246

21 files changed

Lines changed: 315 additions & 329 deletions

File tree

mobile/app/+not-found.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.

mobile/app/home/home.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react'
22
import { FlatList, TouchableOpacity } from 'react-native'
33
import { Link, useRouter } from 'expo-router'
44
import { Layout } from '@/components/index'
5-
import { fetchBalances, useAppDispatch, useAppSelector, selectVaultsWithBalances } from '@/redux'
5+
import { fetchBalances, useAppDispatch, useAppSelector, selectVaultsWithBalances, generateNewPhrase } from '@/redux'
66
import { setVaultToEdit, fetchVaults } from '@/redux'
77
import {
88
Button,
@@ -80,6 +80,7 @@ export default function Page() {
8080
}
8181

8282
const navigateToAddKey = () => {
83+
dispatch(generateNewPhrase())
8384
route.push('home/vault/add')
8485
}
8586

mobile/app/home/vault/_layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default function VaultModalLayout() {
4949
...defaultOptions
5050
}}
5151
/>
52+
<Stack.Screen name="add/existing-account" options={{ ...defaultOptions }} />
5253

5354
{/* Import a vault stack */}
5455
<Stack.Screen name="option-phrase/enter-phrase" options={{ ...defaultOptions, title: 'Seed Phrase' }} />
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React from 'react'
2+
import { View } from 'react-native'
3+
import { Button, Text, Spacer, HomeLayout, ScreenHeader } from '@/modules/ui-components'
4+
import { importKey, selectAddVaultExistingName, useAppDispatch, useAppSelector } from '@/redux'
5+
import { useRouter } from 'expo-router'
6+
7+
const Page = () => {
8+
const router = useRouter()
9+
const existingName = useAppSelector(selectAddVaultExistingName)
10+
const dispatch = useAppDispatch()
11+
12+
const onChooseAnother = () => {
13+
router.replace({ pathname: '/home/vault/add' })
14+
}
15+
16+
const onReuse = async () => {
17+
if (!existingName) {
18+
console.error('No existing name found')
19+
return
20+
}
21+
dispatch(importKey({ vaultName: existingName }))
22+
router.replace('/home/vault/add/new-vault-loading')
23+
}
24+
25+
if (!existingName) {
26+
return (
27+
<HomeLayout
28+
header={<ScreenHeader title="Reuse Account Name" />}
29+
footer={
30+
<Button color="primary" onPress={() => onChooseAnother()}>
31+
Go Back
32+
</Button>
33+
}
34+
>
35+
<View>
36+
<Text.Title1>Account Name Not Found</Text.Title1>
37+
<Spacer space={16} />
38+
<Text.Body>We could not find the existing account name. Please go back and try again.</Text.Body>
39+
<Spacer space={32} />
40+
</View>
41+
</HomeLayout>
42+
)
43+
}
44+
45+
return (
46+
<HomeLayout
47+
header={<ScreenHeader title="Reuse Account Name" onBackPress={onChooseAnother} />}
48+
footer={
49+
<>
50+
<Button color="primary" onPress={onReuse}>
51+
{`Continue with ${existingName}`}
52+
</Button>
53+
<Spacer space={16} />
54+
<Button color="secondary" onPress={onChooseAnother}>
55+
Go Back
56+
</Button>
57+
</>
58+
}
59+
>
60+
<View>
61+
<Spacer space={32} />
62+
<Text.Title3>Seed Phrase Already Registered</Text.Title3>
63+
<Spacer space={16} />
64+
<Text.Body>
65+
The name <Text.Body_Bold>{existingName}</Text.Body_Bold> is already registered on-chain for this seed phrase.
66+
</Text.Body>
67+
<Spacer space={16} />
68+
<Text.Body>
69+
You can import this account and use the existing name. The app will not register a new account, but will import your key
70+
and link it to the on-chain account named <Text.Body_Bold>{existingName}</Text.Body_Bold>.
71+
</Text.Body>
72+
<Spacer space={32} />
73+
</View>
74+
</HomeLayout>
75+
)
76+
}
77+
78+
export default Page

mobile/app/home/vault/add/index.tsx

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
11
import { Alert as RNAlert, ScrollView } from 'react-native'
22
import React, { useState } from 'react'
3-
import { router, useFocusEffect, useLocalSearchParams } from 'expo-router'
4-
import {
5-
selectMasterPassword,
6-
useAppDispatch,
7-
useAppSelector,
8-
createKey,
9-
selectPhrase,
10-
generateNewPhrase,
11-
resetAddVaultState,
12-
selectAddVaultName
13-
} from '@/redux'
3+
import { router } from 'expo-router'
4+
import { useAppDispatch, useAppSelector, createKey, selectPhrase, resetAddVaultState, selectAddVaultName } from '@/redux'
145
import { Button, Form, HomeLayout, ScreenHeader, Spacer, NewVaultForm, BetaVersionMiniBanner } from '@/modules/ui-components'
156

167
export default function Page() {
178
const [error, setError] = useState<string | undefined>(undefined)
189
const dispatch = useAppDispatch()
1910

20-
const masterPassword = useAppSelector(selectMasterPassword)
2111
const keyName = useAppSelector(selectAddVaultName)
2212
const phrase = useAppSelector(selectPhrase)
2313

24-
const params = useLocalSearchParams()
25-
const skipNewPhraseGeneration = params.skipNewPhraseGeneration === 'true'
26-
27-
useFocusEffect(
28-
React.useCallback(() => {
29-
if (!skipNewPhraseGeneration) {
30-
dispatch(generateNewPhrase())
31-
}
32-
// eslint-disable-next-line react-hooks/exhaustive-deps
33-
}, [])
34-
)
35-
3614
const onCreate = async () => {
3715
setError(undefined)
3816

@@ -54,14 +32,9 @@ export default function Page() {
5432
return
5533
}
5634

57-
if (!masterPassword) {
58-
setError('Master password not found.')
59-
return
60-
}
61-
6235
try {
63-
dispatch(createKey({ name: keyName, password: masterPassword, phrase }))
64-
router.navigate('/home/vault/add/new-vault-loading')
36+
dispatch(createKey())
37+
router.replace('/home/vault/add/new-vault-loading')
6538
// await dispatch(fetchVaults()).unwrap()
6639
// dispatch(checkForKeyOnChains())
6740
} catch (error: any) {

mobile/app/home/vault/add/new-vault-loading.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HomeLayout, ActivityIndicator } from '@/modules/ui-components'
1+
import { HomeLayout, ActivityIndicator, ButtonBack, HeroBox, ErrorBox } from '@/modules/ui-components'
22
import {
33
registerAccount,
44
selectLastProgress,
@@ -9,14 +9,14 @@ import {
99
VaultCreationState
1010
} from '@/redux'
1111
import { useCallback, useEffect, useState } from 'react'
12-
import { router, useLocalSearchParams } from 'expo-router'
13-
import { ButtonBack, HeroBox, ErrorBox } from '@/modules/ui-components/molecules'
12+
import { useLocalSearchParams, useRouter } from 'expo-router'
1413

1514
const Page = () => {
1615
const signUpState = useAppSelector(signUpStateSelector)
1716
const currentNetwork = useAppSelector(selectSelectedChain)
1817
const dispatch = useAppDispatch()
1918
const progress = useAppSelector(selectLastProgress)
19+
const router = useRouter()
2020

2121
const [error, setError] = useState<string | undefined>(undefined)
2222

@@ -44,9 +44,8 @@ const Page = () => {
4444
return
4545
}
4646
if (signUpState === VaultCreationState.user_already_exists_on_blockchain_under_different_name) {
47-
setError(
48-
'This account is already registered on the blockchain under a different name. Please press Back and sign up again with another Seed Phrase, or for a normal sign in with a different account if available.'
49-
)
47+
// This account is already registered on the blockchain under a different name.
48+
router.replace({ pathname: '/home/vault/add/existing-account', params: { existingName: keyName } })
5049
return
5150
}
5251
if (signUpState === VaultCreationState.user_exists_only_on_local_storage) {
@@ -97,7 +96,10 @@ const Page = () => {
9796
}, [signUpState, dispatch])
9897

9998
return (
100-
<HomeLayout header={null} footer={error ? <ButtonBack /> : null}>
99+
<HomeLayout
100+
header={null}
101+
footer={error ? <ButtonBack onPress={() => router.replace({ pathname: '/home/vault/add' })} /> : null}
102+
>
101103
{error ? (
102104
<ErrorBox title="Error" description={error} errorDetails={progress} />
103105
) : (

mobile/app/home/vault/index.tsx

Lines changed: 0 additions & 45 deletions
This file was deleted.

mobile/app/home/vault/option-phrase/enter-phrase.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button, Spacer, Text, SafeAreaView, HomeLayout, ScreenHeader } from '@/modules/ui-components'
1+
import { Button, Spacer, Text, SafeAreaView, HomeLayout, ScreenHeader, SeedInputs } from '@/modules/ui-components'
22
import { useState, useRef } from 'react'
33
import {
44
Alert,
@@ -11,7 +11,6 @@ import {
1111
StyleSheet
1212
} from 'react-native'
1313
import Clipboard from '@react-native-clipboard/clipboard'
14-
import { SeedInputs } from '@/views'
1514
import { useAppDispatch, setPhrase, resetAddVaultState, checkPhrase } from '@/redux'
1615
import { useRouter, useFocusEffect } from 'expo-router'
1716
import styled from 'styled-components/native'
@@ -46,7 +45,7 @@ export default function Page() {
4645
return
4746
}
4847

49-
route.push({ pathname: '/home/vault/add', params: { skipNewPhraseGeneration: 'true' } })
48+
route.push({ pathname: '/home/vault/add' })
5049
}
5150

5251
return (
@@ -107,7 +106,7 @@ export default function Page() {
107106
}
108107

109108
const SmallButton = styled(Button)`
110-
width: 120px;
109+
width: 105px;
111110
`
112111

113112
const styles = StyleSheet.create({
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useRouter } from 'expo-router'
2+
import { Button } from '../../src'
3+
4+
interface Props {
5+
onPress?: () => void
6+
}
7+
8+
const ButtonBack = ({ onPress }: Props) => {
9+
const router = useRouter()
10+
11+
return (
12+
<Button color="primary" onPress={() => (onPress ? onPress() : router.canGoBack() && router.back())}>
13+
Go Back
14+
</Button>
15+
)
16+
}
17+
18+
export { ButtonBack }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { default as HeaderActionButton } from './HeaderActionButton'
22
export { default as SwipeEditButton } from './SwipeEditButton'
33
export { default as VaultOptionsButton } from './VaultOptionsButton'
4+
export { ButtonBack } from './ButtonBack'

0 commit comments

Comments
 (0)