|
137 | 137 | function rerunMigration() { |
138 | 138 | const _unmigratedBundles = $unmigratedBundles |
139 | 139 | const unmigratedBundleIndexes = _unmigratedBundles.map((_bundle) => _bundle.index) |
140 | | -
|
141 | 140 | transactions = transactions.map((item) => { |
142 | 141 | if (unmigratedBundleIndexes.includes(item.index)) { |
143 | 142 | return { ...item, status: 0, errorText: null } |
|
188 | 187 | function migrateFunds() { |
189 | 188 | migratingFundsMessage = locale('views.migrate.migrating') |
190 | 189 |
|
191 | | - transactions.forEach((transaction, index) => { |
192 | | - if (legacyLedger) { |
193 | | - Platform.ledger |
194 | | - .selectSeed($hardwareIndexes.accountIndex, $hardwareIndexes.pageIndex, ADDRESS_SECURITY_LEVEL) |
195 | | - .then(({ iota, callback }) => { |
196 | | - closeTransport = callback |
197 | | - return createLedgerMigrationBundle( |
198 | | - transaction.index, |
199 | | - get(migrationAddress), |
200 | | - iota.prepareTransfers, |
201 | | - callback |
202 | | - ) |
203 | | - }) |
204 | | - .then(({ trytes, bundleHash }) => { |
205 | | - closePopup(true) // close transaction popup |
206 | | - setMigratingTransaction(transaction, 1) |
207 | | - transactions = transactions.map((_transaction, i) => { |
208 | | - if (_transaction.index === transaction.index) { |
209 | | - return { ..._transaction, bundleHash } |
210 | | - } |
211 | | - return _transaction |
212 | | - }) |
213 | | - const reverseTrytesLedger = trytes.reverse() |
214 | | - prepareMigrationLog(bundleHash, reverseTrytesLedger, transaction.balance) |
215 | | - return sendOffLedgerMigrationRequest(reverseTrytesLedger, transaction.index) |
216 | | - }) |
217 | | - .then((receipt) => { |
218 | | - // todo: handle receipt |
219 | | - if (!hasBroadcastAnyBundle) { |
220 | | - hasBroadcastAnyBundle = true |
221 | | - persistProfile() |
222 | | - } |
223 | | - }) |
224 | | - .catch((error) => { |
225 | | - console.error(error) |
226 | | -
|
227 | | - if (legacyLedger) { |
228 | | - closePopup(true) // close transaction popup |
229 | | - closeTransport() |
230 | | - displayNotificationForLedgerProfile('error', false, true, false, true, error) |
231 | | - } |
232 | | -
|
233 | | - transactions = transactions.map((_transaction, i) => { |
234 | | - if (_transaction.index === transaction.index) { |
235 | | - return { ..._transaction, status: -1, errorText: 'Migration failed' } |
236 | | - } |
237 | | -
|
238 | | - return _transaction |
239 | | - }) |
240 | | - }) |
241 | | - .finally(() => { |
242 | | - if ( |
243 | | - !transactions.some((tx) => tx.status === 1) && |
244 | | - transactions.every((tx) => tx.status !== 0) |
245 | | - ) { |
246 | | - migrated = true |
247 | | - busy = false |
248 | | - } |
249 | | - }) |
250 | | - } else { |
251 | | - setMigratingTransaction(transaction, 1) |
252 | | -
|
253 | | - createMigrationBundle(transaction as Bundle, get(migrationAddress)) |
254 | | - .then((trytes: string[]) => { |
255 | | - const reverseTrytesSoftware = trytes.reverse() |
256 | | - prepareMigrationLog('', reverseTrytesSoftware, transaction.balance) |
257 | | - sendOffLedgerMigrationRequest(reverseTrytesSoftware, transaction.index) |
258 | | - }) |
259 | | - .then((receipt) => { |
260 | | - // todo: handle receipt data |
261 | | - // is this needed? |
262 | | - if (!hasBroadcastAnyBundle) { |
263 | | - hasBroadcastAnyBundle = true |
264 | | -
|
265 | | - persistProfile() |
266 | | - } |
267 | | - }) |
268 | | - .catch((error) => { |
269 | | - showAppNotification({ type: 'error', message: error.message || 'Failed to prepare transfers' }) |
270 | | - console.error(error) |
271 | | -
|
272 | | - transactions = transactions.map((_transaction, i) => { |
273 | | - if (_transaction.index === transaction.index) { |
274 | | - return { ..._transaction, status: -1, errorText: 'Migration failed' } |
275 | | - } |
276 | | -
|
277 | | - return _transaction |
278 | | - }) |
279 | | - }) |
280 | | - .finally(() => { |
281 | | - if ( |
282 | | - !transactions.some((tx) => tx.status === 1) && |
283 | | - transactions.every((tx) => tx.status !== 0) |
284 | | - ) { |
285 | | - migrated = true |
286 | | - busy = false |
287 | | - } |
288 | | - }) |
289 | | - } |
290 | | - }) |
| 190 | + transactions.reduce( |
| 191 | + (promise, transaction, idx) => |
| 192 | + transaction.status === 0 |
| 193 | + ? // @ts-ignore |
| 194 | + promise |
| 195 | + .then((acc) => { |
| 196 | + if (legacyLedger) { |
| 197 | + return Platform.ledger |
| 198 | + .selectSeed( |
| 199 | + $hardwareIndexes.accountIndex, |
| 200 | + $hardwareIndexes.pageIndex, |
| 201 | + ADDRESS_SECURITY_LEVEL |
| 202 | + ) |
| 203 | + .then(({ iota, callback }) => { |
| 204 | + closeTransport = callback |
| 205 | + return createLedgerMigrationBundle( |
| 206 | + transaction.index, |
| 207 | + get(migrationAddress), |
| 208 | + iota.prepareTransfers, |
| 209 | + callback |
| 210 | + ) |
| 211 | + }) |
| 212 | + .then(({ trytes, bundleHash }) => { |
| 213 | + closePopup(true) // close transaction popup |
| 214 | + setMigratingTransaction(transaction, 1) |
| 215 | + transactions = transactions.map((_transaction, i) => { |
| 216 | + if (_transaction.index === transaction.index) { |
| 217 | + return { ..._transaction, bundleHash } |
| 218 | + } |
| 219 | + return _transaction |
| 220 | + }) |
| 221 | + const reverseTrytesLedger = trytes.reverse() |
| 222 | + prepareMigrationLog(bundleHash, reverseTrytesLedger, transaction.balance) |
| 223 | + return sendOffLedgerMigrationRequest(reverseTrytesLedger, transaction.index) |
| 224 | + }) |
| 225 | + .then((receipt) => { |
| 226 | + // todo: handle receipt |
| 227 | + if (!hasBroadcastAnyBundle) { |
| 228 | + hasBroadcastAnyBundle = true |
| 229 | + persistProfile() |
| 230 | + } |
| 231 | + }) |
| 232 | + } else { |
| 233 | + setMigratingTransaction(transaction, 1) |
| 234 | +
|
| 235 | + return createMigrationBundle(transaction as Bundle, get(migrationAddress)) |
| 236 | + .then((trytes: string[]) => { |
| 237 | + const reverseTrytesSoftware = trytes.reverse() |
| 238 | + prepareMigrationLog('', reverseTrytesSoftware, transaction.balance) |
| 239 | + return sendOffLedgerMigrationRequest(reverseTrytesSoftware, transaction.index) |
| 240 | + }) |
| 241 | + .then((receipt) => { |
| 242 | + // todo: handle receipt data |
| 243 | + // is this needed? |
| 244 | + if (!hasBroadcastAnyBundle) { |
| 245 | + hasBroadcastAnyBundle = true |
| 246 | +
|
| 247 | + persistProfile() |
| 248 | + } |
| 249 | + }) |
| 250 | + } |
| 251 | + }) |
| 252 | + .catch((error) => { |
| 253 | + console.error(error) |
| 254 | +
|
| 255 | + if (legacyLedger) { |
| 256 | + closePopup(true) // close transaction popup |
| 257 | + closeTransport() |
| 258 | + displayNotificationForLedgerProfile('error', false, true, false, true, error) |
| 259 | + } |
| 260 | + showAppNotification({ |
| 261 | + type: 'error', |
| 262 | + message: error.message || 'Failed to prepare transfers', |
| 263 | + }) |
| 264 | +
|
| 265 | + transactions = transactions.map((_transaction, i) => { |
| 266 | + if (_transaction.index === transaction.index) { |
| 267 | + return { ..._transaction, status: -1, errorText: 'Migration failed' } |
| 268 | + } |
| 269 | +
|
| 270 | + return _transaction |
| 271 | + }) |
| 272 | + }) |
| 273 | + .finally(() => { |
| 274 | + if (transactions.every((tx) => tx.status !== 0 && tx.status !== 1)) { |
| 275 | + migrated = true |
| 276 | + busy = false |
| 277 | + } |
| 278 | + }) |
| 279 | + : promise, |
| 280 | + Promise.resolve([]) |
| 281 | + ) |
291 | 282 | } |
292 | 283 | </script> |
293 | 284 |
|
|
0 commit comments