Skip to content

Commit 40b5397

Browse files
cpl121brancoder
andauthored
fix: migration log (#65)
* feat: continue with the flow of migration * feat: add prepareMigrationLog tp send migration request * fix: debris * fix: error creating a second profile * fix: handle error * fix: handle error with software profile --------- Co-authored-by: Branko Bosnic <[email protected]>
1 parent e2341b3 commit 40b5397

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

packages/shared/lib/migration.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export const prepareMigrationLog = (bundleHash: string, trytes: string[], balanc
372372
const { bundles } = get(migration)
373373

374374
const bundle = get(bundles).find((bundle) => bundle.bundleHash === bundleHash)
375-
const spentInputs = bundle.inputs.filter((input) => input.spent === true)
375+
const spentInputs = bundle?.inputs?.filter((input) => input.spent === true) || []
376376

377377
const spentBundleHashes = []
378378

@@ -391,9 +391,9 @@ export const prepareMigrationLog = (bundleHash: string, trytes: string[], balanc
391391
receiveAddressTrytes: transactionObjects.find((tx) => tx.address.startsWith('TRANSFER')).address,
392392
balance,
393393
spentBundleHashes,
394-
spentAddresses: bundle.inputs.filter((input) => input.spent === true).map((input) => input.address),
395-
mine: bundle.miningRuns > 0,
396-
crackability: bundle.crackability,
394+
spentAddresses: bundle?.inputs?.filter((input) => input.spent === true).map((input) => input.address) || [],
395+
mine: bundle?.miningRuns > 0,
396+
crackability: bundle?.crackability || null,
397397
},
398398
])
399399
}
@@ -730,14 +730,10 @@ export const sendLedgerMigrationBundle = (bundleHash: string, trytes: string[]):
730730
* @returns {Promise<Receipt>}
731731
*/
732732
export const sendOffLedgerMigrationRequest = async (trytes: string[]): Promise<any> => {
733-
try {
734-
const offLedgerHexRequest = createOffLedgerRequest(trytes)
735-
await fetchOffLedgerRequest(offLedgerHexRequest.request)
736-
return await fetchReceiptForRequest(offLedgerHexRequest.requestId)
737-
} catch (err) {
738-
showAppNotification({ type: 'error', message: err.message || 'Failed to send migration request' })
739-
return
740-
}
733+
const offLedgerHexRequest = createOffLedgerRequest(trytes)
734+
await fetchOffLedgerRequest(offLedgerHexRequest.request)
735+
const receiptResponse = await fetchReceiptForRequest(offLedgerHexRequest.requestId)
736+
return receiptResponse
741737
}
742738
/**
743739
* Creates migration bundle

packages/shared/routes/setup/Welcome.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { showAppNotification } from 'shared/lib/notifications'
1717
import { Platform } from 'shared/lib/platform'
1818
import { openPopup } from 'shared/lib/popup'
19-
import { newProfile, storeProfile, validateProfileName } from 'shared/lib/profile'
19+
import { newProfile, profiles, storeProfile, validateProfileName } from 'shared/lib/profile'
2020
import { Stage } from 'shared/lib/typings/stage'
2121
import { destroyActor, getProfileDataPath, initialise } from 'shared/lib/wallet'
2222
import { get } from 'svelte/store'
@@ -32,7 +32,9 @@
3232
$: hasDeveloperProfileChanged = $newProfile?.isDeveloperProfile !== isDeveloperProfile
3333
3434
async function handleContinueClick(): Promise<void> {
35-
const trimmedProfileName = TMP_PROFILE_NAME.trim()
35+
const _profiles = get(profiles)
36+
const trimmedProfileName = TMP_PROFILE_NAME.trim() + _profiles.length
37+
3638
try {
3739
validateProfileName(trimmedProfileName)
3840
} catch (err) {

packages/shared/routes/setup/migrate/views/Migrate.svelte

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
hasBundlesWithSpentAddresses,
1313
hasSingleBundle,
1414
migration,
15+
prepareMigrationLog,
1516
removeAddressChecksum,
1617
sendOffLedgerMigrationRequest,
1718
unselectedInputs,
@@ -29,7 +30,6 @@
2930
import { MigrationAddress } from '@lib/typings/migration'
3031
import { createPrepareTransfers } from '@iota/core'
3132
import { appRouter } from '@core/router'
32-
import { convertBech32AddressToEd25519Address } from '@lib/ed25519'
3333
3434
export let locale: Locale
3535
@@ -88,17 +88,13 @@
8888
balance: input.balance,
8989
}))
9090
91-
try {
92-
const bundleTrytes: string[] = await prepareTransfers(get(seed), transfers, {
93-
inputs: inputsForTransfer,
94-
})
91+
const bundleTrytes: string[] = await prepareTransfers(get(seed), transfers, {
92+
inputs: inputsForTransfer,
93+
})
9594
96-
return sendOffLedgerMigrationRequest(bundleTrytes.reverse())
97-
} catch (err) {
98-
showAppNotification({ type: 'error', message: err.message || 'Failed to prepare transfers' })
99-
} finally {
100-
loading = false
101-
}
95+
// TODO: Check the bundlehash with software profiles
96+
prepareMigrationLog('', bundleTrytes.reverse(), migratableBalance)
97+
return sendOffLedgerMigrationRequest(bundleTrytes.reverse())
10298
}
10399
104100
function handleContinueClick() {
@@ -116,6 +112,7 @@
116112
.then(({ trytes, bundleHash }) => {
117113
closePopup(true) // close transaction popup
118114
singleMigrationBundleHash = bundleHash
115+
prepareMigrationLog(bundleHash, trytes.reverse(), migratableBalance)
119116
return sendOffLedgerMigrationRequest(trytes.reverse())
120117
})
121118
.then((receipt) => {

0 commit comments

Comments
 (0)