Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions src/components/scenes/CreateWalletCompletionScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,51 @@ const CreateWalletCompletionComponent: React.FC<Props> = props => {
})

const handleMigrate = useHandler(() => {
// Transform filtered items into the structure expected by the migration component
const migrateWalletList: MigrateWalletItem[] = newWalletItems.map(
createWallet => {
const { key, pluginId } = createWallet
const wallet = wallets.find(
wallet => wallet.currencyInfo.pluginId === pluginId
)
const successfulNewWalletItems = newWalletItems.filter(
item => itemStatus[item.key] === 'complete'
)

return {
...createWallet,
createWalletId: wallet == null ? '' : wallet.id,
displayName: walletNames[key],
key,
type: 'create'
}
const migrateWalletList: MigrateWalletItem[] = [
...successfulNewWalletItems,
...newTokenItems
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfiltered token items with failed parents break migration

High Severity

newTokenItems are spread into the migration list without filtering for parent wallet success. When a parent wallet creation fails, tokens with PLACEHOLDER_WALLET_ID won't find a parentWalletItem in successfulNewWalletItems, resulting in wallet being undefined and createWalletId falling back to ''. In MigrateWalletCalculateFeeScene, the useAsyncEffect processes all items and does currencyWallets[createWalletId] followed by an unguarded destructuring of .currencyInfo, which throws a TypeError on undefined — breaking the entire migration flow for all items, not just the failed ones.

Additional Locations (1)
Fix in Cursor Fix in Web

].map(createWallet => {
const createWalletIds = createWallet.createWalletIds ?? []
const parentWalletItem =
createWallet.walletType != null
? createWallet
: createWalletIds[0] === PLACEHOLDER_WALLET_ID
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unchecked array index on createWalletIds[0]

Low Severity

createWalletIds[0] is accessed multiple times without verifying the array has elements. The createWalletIds variable is initialized via createWallet.createWalletIds ?? [], so it can be an empty array, making createWalletIds[0] undefined. While the comparisons happen to degrade gracefully here, this violates the check-array-bounds rule and makes the intent unclear.

Additional Locations (1)
Fix in Cursor Fix in Web

? successfulNewWalletItems.find(
item => item.pluginId === createWallet.pluginId
)
: undefined
const parentWalletIndex =
parentWalletItem == null
? -1
: successfulNewWalletItems.findIndex(
item => item.key === parentWalletItem.key
)

const wallet =
parentWalletIndex >= 0
? wallets[parentWalletIndex]
: createWalletIds[0] == null ||
createWalletIds[0] === PLACEHOLDER_WALLET_ID
? undefined
: account.currencyWallets[createWalletIds[0]]

return {
...createWallet,
createWalletId: wallet?.id ?? '',
walletType:
parentWalletItem?.walletType ?? wallet?.currencyInfo.walletType,
displayName:
parentWalletItem == null
? createWallet.displayName
: walletNames[parentWalletItem.key] ?? parentWalletItem.displayName,
key: createWallet.key,
type: 'create' as const
}
)
})

// Navigate to the migration screen with the prepared list
if (migrateWalletList.length > 0) {
Expand Down
Loading