Skip to content

Commit 8c17b1e

Browse files
committed
more component cleanup and ui polish
1 parent 3f17c92 commit 8c17b1e

File tree

6 files changed

+99
-208
lines changed

6 files changed

+99
-208
lines changed

packages/core-mobile/app/new/common/components/ProgressDots.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { View, Platform } from 'react-native'
2+
import { View } from 'react-native'
33
import { useTheme } from '@avalabs/k2-alpine'
44
import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'
55

@@ -12,6 +12,8 @@ interface ProgressDotsProps {
1212
dotSize?: number
1313
/** Gap between dots */
1414
gap?: number
15+
/** Custom height for the container */
16+
height?: number
1517
/** Test ID for testing */
1618
testID?: string
1719
}
@@ -55,6 +57,7 @@ export const ProgressDots: React.FC<ProgressDotsProps> = ({
5557
currentStep,
5658
dotSize = 6,
5759
gap = 6,
60+
height,
5861
testID
5962
}) => {
6063
const {
@@ -68,7 +71,7 @@ export const ProgressDots: React.FC<ProgressDotsProps> = ({
6871
flexDirection: 'row',
6972
alignItems: 'center',
7073
gap,
71-
height: 56,
74+
...(height && { height }),
7275
justifyContent: 'center'
7376
}}>
7477
{Array.from({ length: totalSteps }).map((_, index) => (

packages/core-mobile/app/new/features/ledger/components/LedgerAppConnection.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ export const LedgerAppConnection: React.FC<LedgerAppConnectionProps> = ({
112112
const handleConnectAvalanche = useCallback(async () => {
113113
try {
114114
setCurrentStep(AppConnectionStep.AVALANCHE_LOADING)
115-
115+
116116
// Get keys from service
117117
const avalancheKeys = await LedgerService.getAvalancheKeys()
118-
const { bitcoinAddress, xpAddress } = await LedgerService.getBitcoinAndXPAddresses()
119-
118+
const { bitcoinAddress, xpAddress } =
119+
await LedgerService.getBitcoinAndXPAddresses()
120+
120121
// Update local state
121122
setKeys(prev => ({
122123
...prev,
@@ -146,7 +147,7 @@ export const LedgerAppConnection: React.FC<LedgerAppConnectionProps> = ({
146147

147148
// Get keys from service
148149
const solanaKeys = await LedgerService.getSolanaKeys()
149-
150+
150151
// Update local state
151152
setKeys(prev => ({
152153
...prev,
@@ -212,7 +213,10 @@ export const LedgerAppConnection: React.FC<LedgerAppConnectionProps> = ({
212213
}
213214
addresses.push({
214215
title: xpNetwork.chainName,
215-
subtitle: truncateAddress(keys.xpAddress, TRUNCATE_ADDRESS_LENGTH),
216+
subtitle: truncateAddress(
217+
keys.xpAddress.replace(/^[XP]-/, ''),
218+
TRUNCATE_ADDRESS_LENGTH
219+
),
216220
value: (
217221
<Icons.Navigation.Check
218222
color={colors.$textSuccess}
@@ -289,7 +293,7 @@ export const LedgerAppConnection: React.FC<LedgerAppConnectionProps> = ({
289293
// Always add the "Storing wallet data" row at the end
290294
addresses.push({
291295
title: 'Storing wallet data',
292-
value: <LoadingState />
296+
value: <LoadingState sx={{ width: 16, height: 16 }} />
293297
})
294298

295299
return addresses
@@ -313,10 +317,6 @@ export const LedgerAppConnection: React.FC<LedgerAppConnectionProps> = ({
313317
text: 'Continue',
314318
onPress: handleConnectAvalanche
315319
},
316-
secondaryButton: {
317-
text: 'Cancel Setup',
318-
onPress: onCancel
319-
},
320320
showAnimation: false
321321
}
322322

@@ -331,10 +331,6 @@ export const LedgerAppConnection: React.FC<LedgerAppConnectionProps> = ({
331331
),
332332
title: 'Connecting to Avalanche app',
333333
subtitle: `Please keep your Avalanche app open on your ${deviceName}, We're retrieving your Avalanche addresses...`,
334-
secondaryButton: {
335-
text: 'Cancel Setup',
336-
onPress: onCancel
337-
},
338334
showAnimation: true,
339335
isLoading: true
340336
}
@@ -372,10 +368,6 @@ export const LedgerAppConnection: React.FC<LedgerAppConnectionProps> = ({
372368
),
373369
title: 'Connecting to Solana',
374370
subtitle: `Please keep your Solana app open on your ${deviceName}, We're retrieving your Solana address...`,
375-
secondaryButton: {
376-
text: 'Cancel Setup',
377-
onPress: onCancel
378-
},
379371
showAnimation: true,
380372
isLoading: true
381373
}
@@ -419,7 +411,7 @@ export const LedgerAppConnection: React.FC<LedgerAppConnectionProps> = ({
419411
</View>
420412

421413
<View style={{ flex: 1 }}>
422-
<GroupList data={addressListData} itemHeight={56} />
414+
<GroupList data={addressListData} itemHeight={48} />
423415
</View>
424416

425417
<View style={{ paddingBottom: 16, paddingTop: 16 }}>

packages/core-mobile/app/new/features/ledger/consts.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ export const DERIVATION_PATHS = {
2525
}
2626
} as const
2727

28-
// Raw derivation paths for Solana (without m/ prefix)
29-
export const SOLANA_DERIVATION_PATH = "44'/501'/0'/0/0"
30-
3128
// Solana derivation path prefix for generating indexed paths
3229
export const SOLANA_DERIVATION_PATH_PREFIX = "44'/501'/0'/0"
3330

packages/core-mobile/app/new/features/ledger/contexts/LedgerSetupContext.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import {
1111
WalletCreationOptions,
1212
LedgerTransportState
1313
} from 'services/ledger/types'
14-
import {
15-
useLedgerWallet,
16-
UseLedgerWalletReturn
17-
} from '../hooks/useLedgerWallet'
14+
import { useLedgerWallet } from '../hooks/useLedgerWallet'
1815

1916
interface LedgerSetupContextValue {
2017
// State values
@@ -35,7 +32,12 @@ interface LedgerSetupContextValue {
3532
transportState: LedgerTransportState
3633
connectToDevice: (deviceId: string) => Promise<void>
3734
disconnectDevice: () => Promise<void>
38-
createLedgerWallet: (options: WalletCreationOptions) => Promise<string>
35+
createLedgerWallet: (
36+
options: WalletCreationOptions & {
37+
avalancheKeys?: { evm: string; avalanche: string; pvm: string }
38+
solanaKeys?: Array<{ key: string; derivationPath: string; curve: string }>
39+
}
40+
) => Promise<string>
3941

4042
// Helper methods
4143
resetSetup: () => void

packages/core-mobile/app/new/features/ledger/screens/AppConnectionScreen.tsx

Lines changed: 51 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,10 @@
1-
import React, { useCallback, useEffect, useState } from 'react'
1+
import React, { useCallback, useState } from 'react'
22
import { useRouter } from 'expo-router'
33
import { Alert } from 'react-native'
4-
import { useTheme, View } from '@avalabs/k2-alpine'
5-
import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'
64
import { ScrollScreen } from 'common/components/ScrollScreen'
5+
import { ProgressDots } from 'common/components/ProgressDots'
76
import { LedgerAppConnection } from 'new/features/ledger/components/LedgerAppConnection'
87
import { useLedgerSetupContext } from 'new/features/ledger/contexts/LedgerSetupContext'
9-
import { LedgerDerivationPathType } from 'services/ledger/types'
10-
11-
// Animated dot component - moved outside to prevent recreation on every render
12-
const AnimatedDot = ({
13-
isActive,
14-
dotSize,
15-
colors
16-
}: {
17-
isActive: boolean
18-
dotSize: number
19-
colors: Record<string, string>
20-
}): JSX.Element => {
21-
const animatedStyle = useAnimatedStyle(() => {
22-
return {
23-
width: withTiming(isActive ? dotSize * 2 : dotSize, { duration: 200 }),
24-
opacity: withTiming(isActive ? 1 : 0.4, { duration: 200 })
25-
}
26-
})
27-
28-
return (
29-
<Animated.View
30-
style={[
31-
{
32-
height: dotSize,
33-
borderRadius: dotSize / 2,
34-
backgroundColor: colors.$textPrimary
35-
},
36-
animatedStyle
37-
]}
38-
/>
39-
)
40-
}
41-
42-
// Header-compatible progress dots using k2-alpine components
43-
const HeaderProgressDots = ({
44-
totalSteps,
45-
currentStep
46-
}: {
47-
totalSteps: number
48-
currentStep: number
49-
}): JSX.Element => {
50-
const {
51-
theme: { colors }
52-
} = useTheme()
53-
const dotSize = 6
54-
const gap = 6
55-
56-
return (
57-
<View
58-
style={{
59-
flexDirection: 'row',
60-
alignItems: 'center',
61-
gap,
62-
justifyContent: 'center'
63-
}}>
64-
{Array.from({ length: totalSteps }).map((_, index) => (
65-
<AnimatedDot
66-
key={index}
67-
isActive={index === currentStep}
68-
dotSize={dotSize}
69-
colors={colors}
70-
/>
71-
))}
72-
</View>
73-
)
74-
}
758

769
export default function AppConnectionScreen(): JSX.Element {
7710
const { push, back } = useRouter()
@@ -82,69 +15,62 @@ export default function AppConnectionScreen(): JSX.Element {
8215
connectedDeviceId,
8316
connectedDeviceName,
8417
selectedDerivationPath,
85-
setSelectedDerivationPath,
8618
resetSetup,
8719
disconnectDevice,
8820
createLedgerWallet
8921
} = useLedgerSetupContext()
9022

91-
// Set up default values for the Ledger setup
92-
useEffect(() => {
93-
// Set default derivation path if not set
94-
if (!selectedDerivationPath) {
95-
setSelectedDerivationPath(LedgerDerivationPathType.BIP44)
96-
}
97-
}, [selectedDerivationPath, setSelectedDerivationPath])
98-
99-
const handleComplete = useCallback(async (keys: {
100-
solanaKeys: Array<{ key: string; derivationPath: string; curve: string }>
101-
avalancheKeys: { evm: string; avalanche: string; pvm: string } | null
102-
bitcoinAddress: string
103-
xpAddress: string
104-
}) => {
105-
// If wallet hasn't been created yet, create it now
106-
if (
107-
keys.avalancheKeys &&
108-
connectedDeviceId &&
109-
selectedDerivationPath &&
110-
!isCreatingWallet
111-
) {
112-
setIsCreatingWallet(true)
23+
const handleComplete = useCallback(
24+
async (keys: {
25+
solanaKeys: Array<{ key: string; derivationPath: string; curve: string }>
26+
avalancheKeys: { evm: string; avalanche: string; pvm: string } | null
27+
bitcoinAddress: string
28+
xpAddress: string
29+
}) => {
30+
// If wallet hasn't been created yet, create it now
31+
if (
32+
keys.avalancheKeys &&
33+
connectedDeviceId &&
34+
selectedDerivationPath &&
35+
!isCreatingWallet
36+
) {
37+
setIsCreatingWallet(true)
11338

114-
try {
115-
await createLedgerWallet({
116-
deviceId: connectedDeviceId,
117-
deviceName: connectedDeviceName,
118-
derivationPathType: selectedDerivationPath,
119-
// Pass the keys directly to the wallet creation
120-
avalancheKeys: keys.avalancheKeys,
121-
solanaKeys: keys.solanaKeys
122-
})
39+
try {
40+
await createLedgerWallet({
41+
deviceId: connectedDeviceId,
42+
deviceName: connectedDeviceName,
43+
derivationPathType: selectedDerivationPath,
44+
avalancheKeys: keys.avalancheKeys,
45+
solanaKeys: keys.solanaKeys
46+
})
12347

48+
// @ts-ignore TODO: make routes typesafe
49+
push('/accountSettings/ledger/complete')
50+
} catch (error) {
51+
Alert.alert(
52+
'Wallet Creation Failed',
53+
error instanceof Error
54+
? error.message
55+
: 'Failed to create Ledger wallet. Please try again.',
56+
[{ text: 'OK' }]
57+
)
58+
setIsCreatingWallet(false)
59+
}
60+
} else {
12461
// @ts-ignore TODO: make routes typesafe
12562
push('/accountSettings/ledger/complete')
126-
} catch (error) {
127-
Alert.alert(
128-
'Wallet Creation Failed',
129-
error instanceof Error
130-
? error.message
131-
: 'Failed to create Ledger wallet. Please try again.',
132-
[{ text: 'OK' }]
133-
)
134-
setIsCreatingWallet(false)
13563
}
136-
} else {
137-
// @ts-ignore TODO: make routes typesafe
138-
push('/accountSettings/ledger/complete')
139-
}
140-
}, [
141-
connectedDeviceId,
142-
connectedDeviceName,
143-
selectedDerivationPath,
144-
createLedgerWallet,
145-
push,
146-
isCreatingWallet
147-
])
64+
},
65+
[
66+
connectedDeviceId,
67+
connectedDeviceName,
68+
selectedDerivationPath,
69+
createLedgerWallet,
70+
push,
71+
isCreatingWallet
72+
]
73+
)
14874

14975
const handleCancel = useCallback(async () => {
15076
await disconnectDevice()
@@ -153,14 +79,14 @@ export default function AppConnectionScreen(): JSX.Element {
15379
}, [disconnectDevice, resetSetup, back])
15480

15581
const renderHeaderCenterComponent = useCallback(() => {
156-
return <HeaderProgressDots totalSteps={3} currentStep={currentStep} />
82+
return <ProgressDots totalSteps={3} currentStep={currentStep} />
15783
}, [currentStep])
15884

15985
return (
16086
<ScrollScreen
16187
renderHeaderCenterComponent={renderHeaderCenterComponent}
162-
showNavigationHeaderTitle={false} // Hide navigation title since we have progress dots
163-
hasParent={true} // Modal screens need hasParent={true}
88+
showNavigationHeaderTitle={false}
89+
hasParent={true}
16490
isModal={true}
16591
scrollEnabled={false}
16692
contentContainerStyle={{ flex: 1 }}>

0 commit comments

Comments
 (0)