|
1 | | -import type { EdgeCreateCurrencyWallet, EdgeCurrencyWallet } from 'edge-core-js' |
| 1 | +import type { EdgeCreateCurrencyWallet } from 'edge-core-js' |
2 | 2 | import * as React from 'react' |
3 | 3 | import { ActivityIndicator, View } from 'react-native' |
4 | 4 | import { FlatList } from 'react-native-gesture-handler' |
@@ -56,7 +56,8 @@ const CreateWalletCompletionComponent: React.FC<Props> = props => { |
56 | 56 | const defaultIsoFiat = useSelector(state => state.ui.settings.defaultIsoFiat) |
57 | 57 |
|
58 | 58 | const [done, setDone] = React.useState(false) |
59 | | - const [wallets, setWallets] = React.useState<EdgeCurrencyWallet[]>([]) |
| 59 | + const [createdWalletIdsByPluginId, setCreatedWalletIdsByPluginId] = |
| 60 | + React.useState<Record<string, string>>({}) |
60 | 61 |
|
61 | 62 | const { newWalletItems, newTokenItems } = React.useMemo( |
62 | 63 | () => splitCreateWalletItems(createWalletList), |
@@ -156,14 +157,13 @@ const CreateWalletCompletionComponent: React.FC<Props> = props => { |
156 | 157 | } |
157 | 158 |
|
158 | 159 | // 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) |
167 | 167 |
|
168 | 168 | setDone(true) |
169 | 169 | return () => {} |
@@ -252,23 +252,28 @@ const CreateWalletCompletionComponent: React.FC<Props> = props => { |
252 | 252 | }) |
253 | 253 |
|
254 | 254 | 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 |
262 | 264 |
|
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 |
270 | 275 | } |
271 | | - ) |
| 276 | + }) |
272 | 277 |
|
273 | 278 | // Navigate to the migration screen with the prepared list |
274 | 279 | if (migrateWalletList.length > 0) { |
|
0 commit comments