1- import { Button , showAlert , View } from '@avalabs/k2-alpine'
21import { ScrollScreen } from 'common/components/ScrollScreen'
3- import { useRouter } from 'expo-router'
42import React , { useCallback } from 'react'
5- import { useDispatch , useSelector } from 'react-redux'
6- import { selectActiveAccount , setAccount } from 'store/account'
3+ import { useRouter } from 'expo-router'
74import BiometricsSDK from 'utils/BiometricsSDK'
8- import Logger from 'utils/Logger'
9- import { copyToClipboard } from 'common/utils/clipboard'
105import { PinScreen } from '../common/components/PinScreen'
116
127const LoginWithPinOrBiometry = ( ) : JSX . Element => {
138 const router = useRouter ( )
14- const dispatch = useDispatch ( )
15- const activeAccount = useSelector ( selectActiveAccount )
169
1710 const handleForgotPin = ( ) : void => {
1811 // @ts -ignore TODO: make routes typesafe
@@ -23,141 +16,6 @@ const LoginWithPinOrBiometry = (): JSX.Element => {
2316 return BiometricsSDK . loadEncryptionKeyWithBiometry ( )
2417 } , [ ] )
2518
26- // Debug functions to manipulate account state
27- const setXpAddressesToEmpty = useCallback ( ( ) => {
28- if ( activeAccount ) {
29- dispatch (
30- setAccount ( {
31- ...activeAccount ,
32- xpAddresses : [ ]
33- } )
34- )
35- Logger . info ( '[DEBUG] Set xpAddresses to []' )
36- }
37- } , [ activeAccount , dispatch ] )
38-
39- const setXpAddressDictionaryToEmpty = useCallback ( ( ) => {
40- if ( activeAccount ) {
41- dispatch (
42- setAccount ( {
43- ...activeAccount ,
44- xpAddressDictionary : { }
45- } )
46- )
47- Logger . info ( '[DEBUG] Set xpAddressDictionary to {}' )
48- }
49- } , [ activeAccount , dispatch ] )
50-
51- const toggleHasMigratedXpAddresses = useCallback ( ( ) => {
52- if ( activeAccount ) {
53- dispatch (
54- setAccount ( {
55- ...activeAccount ,
56- hasMigratedXpAddresses : ! activeAccount . hasMigratedXpAddresses
57- } )
58- )
59- Logger . info (
60- '[DEBUG] Toggled hasMigratedXpAddresses to' ,
61- ! activeAccount . hasMigratedXpAddresses
62- )
63- }
64- } , [ activeAccount , dispatch ] )
65-
66- const setAddressPVMToEmpty = useCallback ( ( ) => {
67- if ( activeAccount ) {
68- dispatch (
69- setAccount ( {
70- ...activeAccount ,
71- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72- addressPVM : '' as any
73- } )
74- )
75- Logger . info ( '[DEBUG] Set addressPVM to empty string' )
76- }
77- } , [ activeAccount , dispatch ] )
78-
79- const setAddressAVMToEmpty = useCallback ( ( ) => {
80- if ( activeAccount ) {
81- dispatch (
82- setAccount ( {
83- ...activeAccount ,
84- // eslint-disable-next-line @typescript-eslint/no-explicit-any
85- addressAVM : '' as any
86- } )
87- )
88- Logger . info ( '[DEBUG] Set addressAVM to empty string' )
89- }
90- } , [ activeAccount , dispatch ] )
91-
92- const viewActiveAccount = useCallback ( ( ) => {
93- if ( ! activeAccount ) {
94- return
95- }
96-
97- const xpAddressesList =
98- activeAccount . xpAddresses && activeAccount . xpAddresses . length > 0
99- ? activeAccount . xpAddresses
100- . map (
101- ( addr , idx ) => ` [${ idx } ] ${ addr . address } (index: ${ addr . index } )`
102- )
103- . join ( '\n' )
104- : ' (empty)'
105-
106- const xpDictionaryList =
107- Object . keys ( activeAccount . xpAddressDictionary ) . length > 0
108- ? Object . entries ( activeAccount . xpAddressDictionary )
109- . map (
110- ( [ address , metadata ] ) =>
111- ` ${ address } : space=${ metadata . space } , index=${ metadata . index } , hasActivity=${ metadata . hasActivity } `
112- )
113- . join ( '\n' )
114- : ' (empty)'
115-
116- const accountInfo = `
117- ID: ${ activeAccount . id }
118- Name: ${ activeAccount . name }
119- Index: ${ activeAccount . index }
120- Type: ${ activeAccount . type }
121- Wallet ID: ${ activeAccount . walletId }
122-
123- Addresses:
124- - C-Chain: ${ activeAccount . addressC }
125- - P-Chain: ${ activeAccount . addressPVM || 'N/A' }
126- - X-Chain: ${ activeAccount . addressAVM || 'N/A' }
127- - BTC: ${ activeAccount . addressBTC }
128- - SVM: ${ activeAccount . addressSVM || 'N/A' }
129-
130- XP Addresses (${ activeAccount . xpAddresses ?. length || 0 } ):
131- ${ xpAddressesList }
132-
133- XP Dictionary (${
134- Object . keys ( activeAccount . xpAddressDictionary ) . length
135- } entries):
136- ${ xpDictionaryList }
137-
138- Has Migrated: ${ activeAccount . hasMigratedXpAddresses ? 'Yes' : 'No' }
139- ` . trim ( )
140-
141- showAlert ( {
142- title : 'Active Account Details' ,
143- description : accountInfo ,
144- buttons : [
145- {
146- text : 'Copy to Clipboard' ,
147- onPress : ( ) => {
148- copyToClipboard (
149- accountInfo ,
150- 'Active Account Details copied to clipboard'
151- )
152- }
153- } ,
154- {
155- text : 'Close'
156- }
157- ]
158- } )
159- } , [ activeAccount ] )
160-
16119 return (
16220 < ScrollScreen
16321 shouldAvoidKeyboard
@@ -169,45 +27,6 @@ Has Migrated: ${activeAccount.hasMigratedXpAddresses ? 'Yes' : 'No'}
16927 isInitialLogin = { true }
17028 onBiometricPrompt = { handleBiometricPrompt }
17129 />
172- {
173- < View
174- sx = { {
175- position : 'absolute' ,
176- top : 100 ,
177- left : 16 ,
178- right : 16 ,
179- gap : 8 ,
180- padding : 16 ,
181- backgroundColor : '$surfaceSecondary' ,
182- borderRadius : 12
183- } } >
184- < Button type = "primary" size = "small" onPress = { viewActiveAccount } >
185- View Active Account
186- </ Button >
187- < Button type = "secondary" size = "small" onPress = { setXpAddressesToEmpty } >
188- Set xpAddresses to []
189- </ Button >
190- < Button
191- type = "secondary"
192- size = "small"
193- onPress = { setXpAddressDictionaryToEmpty } >
194- Set xpAddressDictionary to { '{}' }
195- </ Button >
196- < Button
197- type = "secondary"
198- size = "small"
199- onPress = { toggleHasMigratedXpAddresses } >
200- Toggle hasMigratedXpAddresses (currently{ ' ' }
201- { activeAccount ?. hasMigratedXpAddresses ? 'true' : 'false' } )
202- </ Button >
203- < Button type = "secondary" size = "small" onPress = { setAddressPVMToEmpty } >
204- Set addressPVM to empty
205- </ Button >
206- < Button type = "secondary" size = "small" onPress = { setAddressAVMToEmpty } >
207- Set addressAVM to empty
208- </ Button >
209- </ View >
210- }
21130 </ ScrollScreen >
21231 )
21332}
0 commit comments