Skip to content

Commit 1f1a8b1

Browse files
authored
Merge pull request #5984 from EdgeApp/jon/fix/disable-empty-migrate
Disable Migrate Wallets when no assets to migrate
2 parents d0964a2 + 18a3c1b commit 1f1a8b1

10 files changed

Lines changed: 122 additions & 95 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- added: New Banxa payment methods
99
- added: Debug settings scene (Developer Mode only) with nodes/servers inspection, engine `dataDump` viewer, and log viewer
1010
- fixed: Swap quote timeout error interrupting user after cancelling a slow swap search
11+
- fixed: Disable "Migrate Wallets" button when no assets are available to migrate
1112

1213
## 4.45.0 (2025-03-10)
1314

eslint.config.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default [
104104
'src/actions/SoundActions.ts',
105105
'src/actions/TokenTermsActions.tsx',
106106
'src/actions/TransactionExportActions.tsx',
107-
'src/actions/WalletActions.tsx',
107+
108108
'src/actions/WalletListActions.tsx',
109109
'src/actions/WalletListMenuActions.tsx',
110110
'src/app.ts',
@@ -240,7 +240,6 @@ export default [
240240
'src/components/scenes/ConfirmScene.tsx',
241241
'src/components/scenes/CreateWalletAccountSelectScene.tsx',
242242
'src/components/scenes/CreateWalletAccountSetupScene.tsx',
243-
'src/components/scenes/CreateWalletCompletionScene.tsx',
244243

245244
'src/components/scenes/CreateWalletImportOptionsScene.tsx',
246245
'src/components/scenes/CreateWalletImportScene.tsx',
@@ -280,8 +279,6 @@ export default [
280279
'src/components/scenes/Loans/LoanStatusScene.tsx',
281280

282281
'src/components/scenes/ManageTokensScene.tsx',
283-
'src/components/scenes/MigrateWalletCalculateFeeScene.tsx',
284-
'src/components/scenes/MigrateWalletCompletionScene.tsx',
285282

286283
'src/components/scenes/NotificationCenterScene.tsx',
287284
'src/components/scenes/NotificationScene.tsx',

src/__tests__/scenes/__snapshots__/SettingsScene.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,7 +4540,7 @@ exports[`SettingsScene should render SettingsScene 1`] = `
45404540
allowFontScaling={false}
45414541
style={
45424542
{
4543-
"color": "#FFFFFF",
4543+
"color": "#888888",
45444544
"flexGrow": 1,
45454545
"flexShrink": 1,
45464546
"fontFamily": "Quicksand-Regular",
@@ -4644,7 +4644,7 @@ exports[`SettingsScene should render SettingsScene 1`] = `
46444644
"fontSize": 22,
46454645
},
46464646
{
4647-
"color": "#00f1a2",
4647+
"color": "rgba(255, 255, 255, .75)",
46484648
"fontSize": 22,
46494649
"marginHorizontal": 11,
46504650
},

src/actions/WalletActions.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type { NavigationBase } from '../types/routerTypes'
3838
import type { MapObject } from '../types/types'
3939
import { getCurrencyCode, isKeysOnlyPlugin } from '../util/CurrencyInfoHelpers'
4040
import { getWalletName } from '../util/CurrencyWalletHelpers'
41+
import { getMigrateWalletItemList } from '../util/getMigrateWalletItemList'
4142
import { fetchInfo } from '../util/network'
4243

4344
export interface SelectWalletTokenParams {
@@ -68,7 +69,7 @@ export function selectWalletToken({
6869
// Manually un-pause the wallet, if necessary:
6970
const wallet: EdgeCurrencyWallet = currencyWallets[walletId]
7071
if (wallet.paused && !isKeysOnlyPlugin(wallet.currencyInfo.pluginId))
71-
wallet.changePaused(false).catch(error => {
72+
wallet.changePaused(false).catch((error: unknown) => {
7273
showError(error)
7374
})
7475

@@ -93,7 +94,7 @@ export function selectWalletToken({
9394
const { isAccountActivationRequired } = getSpecialCurrencyInfo(
9495
wallet.currencyInfo.pluginId
9596
)
96-
if (isAccountActivationRequired) {
97+
if (isAccountActivationRequired === true) {
9798
// activation-required wallets need different path in case not activated yet
9899
if (alwaysActivate) {
99100
return await dispatch(
@@ -141,7 +142,7 @@ function selectActivationRequiredWallet(
141142
)}
142143
buttons={{ ok: { label: lstrings.string_ok } }}
143144
/>
144-
)).catch(err => {
145+
)).catch((err: unknown) => {
145146
showError(err)
146147
})
147148
return false
@@ -172,7 +173,7 @@ export function updateMostRecentWalletsSelected(
172173
data: { mostRecentWallets: currentMostRecentWallets }
173174
})
174175
})
175-
.catch(error => {
176+
.catch((error: unknown) => {
176177
showError(error)
177178
})
178179
}
@@ -278,7 +279,7 @@ export function activateWalletTokens(
278279
message={sprintf(msg, feeString)}
279280
buttons={{ ok: { label: lstrings.string_ok } }}
280281
/>
281-
)).catch(err => {
282+
)).catch((err: unknown) => {
282283
showError(err)
283284
})
284285
navigation.pop()
@@ -306,7 +307,7 @@ export function activateWalletTokens(
306307
)
307308
navigation.pop()
308309
})
309-
.catch(e => {
310+
.catch((e: unknown) => {
310311
navigation.pop()
311312
showError(e)
312313
})
@@ -413,7 +414,7 @@ export function checkCompromisedKeys(
413414
const keyInfo = exposedKeyInfos.find(
414415
info => info.pubKeyHash === pubkeyHash
415416
)
416-
if (keyInfo?.exposed) {
417+
if (keyInfo?.exposed === true) {
417418
exposedWalletIds.push(walletId)
418419
} else {
419420
securityCheckedWallets[walletId] = {
@@ -450,13 +451,17 @@ export function checkCompromisedKeys(
450451
))
451452
}
452453

453-
// If any walletId come back true show modal to go to migration scene with affected wallets preselected
454-
if (exposedWalletIds.length > 0) {
455-
const walletNames = exposedWalletIds.map(walletId =>
454+
const migratableItems = getMigrateWalletItemList(currencyWallets)
455+
const migratableWalletIds = exposedWalletIds.filter(id =>
456+
migratableItems.some(item => item.createWalletId === id)
457+
)
458+
459+
if (migratableWalletIds.length > 0) {
460+
const walletNames = migratableWalletIds.map(walletId =>
456461
getWalletName(currencyWallets[walletId])
457462
)
458463
const response = await MigrateWalletsModal(walletNames)
459-
exposedWalletIds.forEach(walletId => {
464+
migratableWalletIds.forEach(walletId => {
460465
const { checked, modalShown } = securityCheckedWallets[walletId]
461466
securityCheckedWallets[walletId] = {
462467
checked,
@@ -466,7 +471,7 @@ export function checkCompromisedKeys(
466471

467472
if (response === 'yes') {
468473
navigation.push('migrateWalletSelectCrypto', {
469-
preSelectedWalletIds: exposedWalletIds
474+
preSelectedWalletIds: migratableWalletIds
470475
})
471476
}
472477
}

src/components/scenes/CreateWalletCompletionScene.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface CreateWalletCompletionParams {
3939

4040
interface Props extends EdgeAppSceneProps<'createWalletCompletion'> {}
4141

42-
const CreateWalletCompletionComponent = (props: Props) => {
42+
const CreateWalletCompletionComponent: React.FC<Props> = props => {
4343
const { navigation, route } = props
4444
const {
4545
createWalletList,
@@ -145,7 +145,7 @@ const CreateWalletCompletionComponent = (props: Props) => {
145145
[tokenKey]: 'complete'
146146
}))
147147
},
148-
error => {
148+
(error: unknown) => {
149149
showError(error)
150150
setItemStatus(currentState => ({
151151
...currentState,
@@ -255,15 +255,14 @@ const CreateWalletCompletionComponent = (props: Props) => {
255255
// Transform filtered items into the structure expected by the migration component
256256
const migrateWalletList: MigrateWalletItem[] = newWalletItems.map(
257257
createWallet => {
258-
// Link the createWalletIds with the created wallets
259258
const { key, pluginId } = createWallet
260259
const wallet = wallets.find(
261260
wallet => wallet.currencyInfo.pluginId === pluginId
262261
)
263262

264263
return {
265264
...createWallet,
266-
createWalletIds: wallet == null ? [''] : [wallet.id],
265+
createWalletId: wallet == null ? '' : wallet.id,
267266
displayName: walletNames[key],
268267
key,
269268
type: 'create'

src/components/scenes/MigrateWalletCalculateFeeScene.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Props = EdgeAppSceneProps<'migrateWalletCalculateFee'>
4141

4242
type AssetRowState = string | Error
4343

44-
const MigrateWalletCalculateFeeComponent = (props: Props) => {
44+
const MigrateWalletCalculateFeeComponent: React.FC<Props> = props => {
4545
const { navigation, route } = props
4646
const { migrateWalletList } = route.params
4747

@@ -71,10 +71,14 @@ const MigrateWalletCalculateFeeComponent = (props: Props) => {
7171

7272
const renderCurrencyRow = useHandler(
7373
(data: ListRenderItemInfo<MigrateWalletItem>) => {
74-
const { key, pluginId, tokenId, walletType, createWalletIds } = data.item
74+
const {
75+
key,
76+
pluginId,
77+
tokenId,
78+
walletType,
79+
createWalletId: walletId
80+
} = data.item
7581
if (walletType == null) return null
76-
77-
const walletId = createWalletIds[0]
7882
const wallet = currencyWallets[walletId]
7983
if (wallet == null) return null
8084
const {
@@ -198,12 +202,11 @@ const MigrateWalletCalculateFeeComponent = (props: Props) => {
198202
// This bundles the assets by similar walletId with the main asset (ie. ETH) at the end of each array so its makeSpend is called last
199203
const bundledWalletAssets: MigrateWalletItem[][] =
200204
migrateWalletList.reduce((bundles: MigrateWalletItem[][], asset) => {
201-
const { createWalletIds } = asset
202-
const walletId = createWalletIds[0]
205+
const { createWalletId: walletId } = asset
203206

204207
// Find the bundle with the main currency at the end of it
205208
const index = bundles.findIndex(
206-
bundle => walletId === bundle[0].createWalletIds[0]
209+
bundle => walletId === bundle[0].createWalletId
207210
)
208211
if (index === -1) {
209212
bundles.push([asset]) // create bundle for this walletId
@@ -221,8 +224,7 @@ const MigrateWalletCalculateFeeComponent = (props: Props) => {
221224
let successCount = 0
222225
const walletPromises = []
223226
for (const bundle of bundledWalletAssets) {
224-
const wallet =
225-
currencyWallets[bundle[bundle.length - 1].createWalletIds[0]]
227+
const wallet = currencyWallets[bundle[bundle.length - 1].createWalletId]
226228
const {
227229
currencyInfo: { pluginId }
228230
} = wallet
@@ -322,11 +324,9 @@ const MigrateWalletCalculateFeeComponent = (props: Props) => {
322324

323325
// Wait for wallets to sync
324326
React.useEffect(() => {
325-
const migrateWalletIds = migrateWalletList.map(
326-
item => item.createWalletIds[0]
327-
)
327+
const migrateWalletIds = migrateWalletList.map(item => item.createWalletId)
328328

329-
const updateProgress = () => {
329+
const updateProgress = (): void => {
330330
const syncedWallets = migrateWalletIds.filter(walletId => {
331331
const wallet = currencyWallets[walletId]
332332

src/components/scenes/MigrateWalletCompletionScene.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface MigrateWalletTokenItem extends MigrateWalletItem {
4242
tokenId: string
4343
}
4444

45-
const MigrateWalletCompletionComponent = (props: Props) => {
45+
const MigrateWalletCompletionComponent: React.FC<Props> = props => {
4646
const { navigation, route } = props
4747
const { migrateWalletList } = route.params
4848

@@ -54,12 +54,11 @@ const MigrateWalletCompletionComponent = (props: Props) => {
5454

5555
const sortedMigrateWalletListBundles = React.useMemo(() => {
5656
return migrateWalletList.reduce((bundles: MigrateWalletItem[][], asset) => {
57-
const { createWalletIds } = asset
58-
const walletId = createWalletIds[0]
57+
const { createWalletId: walletId } = asset
5958

6059
// Find the bundle with the main currency at the end of it
6160
const index = bundles.findIndex(
62-
bundle => walletId === bundle[0].createWalletIds[0]
61+
bundle => walletId === bundle[0].createWalletId
6362
)
6463

6564
if (index === -1) {
@@ -98,7 +97,7 @@ const MigrateWalletCompletionComponent = (props: Props) => {
9897
const handleItemStatus = (
9998
item: MigrateWalletItem,
10099
status: 'complete' | 'error'
101-
) => {
100+
): void => {
102101
setItemStatus(currentState => ({ ...currentState, [item.key]: status }))
103102
const index = sortedMigrateWalletList.findIndex(
104103
asset => asset.key === item.key
@@ -119,8 +118,7 @@ const MigrateWalletCompletionComponent = (props: Props) => {
119118
const migrationPromises = []
120119
for (const bundle of sortedMigrateWalletListBundles) {
121120
const mainnetItem = bundle[bundle.length - 1]
122-
const { createWalletIds } = mainnetItem
123-
const oldWalletId = createWalletIds[0]
121+
const { createWalletId: oldWalletId } = mainnetItem
124122

125123
securityCheckedWallets[oldWalletId] ??= {
126124
checked: false,
@@ -135,7 +133,7 @@ const MigrateWalletCompletionComponent = (props: Props) => {
135133
const newWalletName = `${oldWalletName}${lstrings.migrate_wallet_new_fragment}`
136134

137135
// Create new wallet
138-
const createNewWalletPromise = async () => {
136+
const createNewWalletPromise = async (): Promise<void> => {
139137
const previouslyCreatedWalletInfo = account.allKeys.find(
140138
keys =>
141139
keys.migratedFromWalletId === oldWalletId &&
@@ -342,9 +340,7 @@ const MigrateWalletCompletionComponent = (props: Props) => {
342340
const renderRow = useHandler(
343341
(data: ListRenderItemInfo<MigrateWalletItem>) => {
344342
const { item } = data
345-
const { createWalletIds } = item
346-
347-
const walletId = createWalletIds[0]
343+
const { createWalletId: walletId } = item
348344
const wallet = currencyWallets[walletId]
349345
if (wallet == null) return null
350346
return (

0 commit comments

Comments
 (0)