Skip to content

Commit e9c9336

Browse files
committed
fix: preserve imported token migrations
Imported token migrations were losing their parent wallet context between wallet creation and the migration flow, which made token migrations disappear or crash before users could review them. Track the created wallet ids during import completion and carry the parent wallet metadata into the migration payload so imported tokens reach the migration scenes as first-class assets.
1 parent 8b1a7ec commit e9c9336

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

src/components/scenes/CreateWalletCompletionScene.tsx

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EdgeCreateCurrencyWallet, EdgeCurrencyWallet } from 'edge-core-js'
1+
import type { EdgeCreateCurrencyWallet } from 'edge-core-js'
22
import * as React from 'react'
33
import { ActivityIndicator, View } from 'react-native'
44
import { FlatList } from 'react-native-gesture-handler'
@@ -56,7 +56,8 @@ const CreateWalletCompletionComponent: React.FC<Props> = props => {
5656
const defaultIsoFiat = useSelector(state => state.ui.settings.defaultIsoFiat)
5757

5858
const [done, setDone] = React.useState(false)
59-
const [wallets, setWallets] = React.useState<EdgeCurrencyWallet[]>([])
59+
const [createdWalletIdsByPluginId, setCreatedWalletIdsByPluginId] =
60+
React.useState<Record<string, string>>({})
6061

6162
const { newWalletItems, newTokenItems } = React.useMemo(
6263
() => splitCreateWalletItems(createWalletList),
@@ -156,14 +157,13 @@ const CreateWalletCompletionComponent: React.FC<Props> = props => {
156157
}
157158

158159
// Save the created wallets
159-
setWallets(
160-
walletResults
161-
.filter(
162-
(result): result is { ok: true; result: EdgeCurrencyWallet } =>
163-
result.ok
164-
)
165-
.map(result => result.result)
166-
)
160+
const newCreatedWalletIdsByPluginId: Record<string, string> = {}
161+
walletResults.forEach((result, index) => {
162+
if (!result.ok) return
163+
newCreatedWalletIdsByPluginId[newWalletItems[index].pluginId] =
164+
result.result.id
165+
})
166+
setCreatedWalletIdsByPluginId(newCreatedWalletIdsByPluginId)
167167

168168
setDone(true)
169169
return () => {}
@@ -252,23 +252,28 @@ const CreateWalletCompletionComponent: React.FC<Props> = props => {
252252
})
253253

254254
const handleMigrate = useHandler(() => {
255-
// Transform filtered items into the structure expected by the migration component
256-
const migrateWalletList: MigrateWalletItem[] = newWalletItems.map(
257-
createWallet => {
258-
const { key, pluginId } = createWallet
259-
const wallet = wallets.find(
260-
wallet => wallet.currencyInfo.pluginId === pluginId
261-
)
255+
const migrateWalletList: MigrateWalletItem[] = [
256+
...newWalletItems,
257+
...newTokenItems
258+
].map(createWallet => {
259+
const { key, pluginId } = createWallet
260+
const parentWalletItem =
261+
createWallet.walletType == null
262+
? newWalletItems.find(item => item.pluginId === pluginId)
263+
: createWallet
262264

263-
return {
264-
...createWallet,
265-
createWalletId: wallet == null ? '' : wallet.id,
266-
displayName: walletNames[key],
267-
key,
268-
type: 'create'
269-
}
265+
return {
266+
...createWallet,
267+
createWalletId: createdWalletIdsByPluginId[pluginId] ?? '',
268+
walletType: parentWalletItem?.walletType ?? createWallet.walletType,
269+
displayName:
270+
parentWalletItem == null
271+
? createWallet.displayName
272+
: walletNames[parentWalletItem.key] ?? parentWalletItem.displayName,
273+
key,
274+
type: 'create' as const
270275
}
271-
)
276+
})
272277

273278
// Navigate to the migration screen with the prepared list
274279
if (migrateWalletList.length > 0) {

0 commit comments

Comments
 (0)