Skip to content

Commit aa71047

Browse files
brancodercpl121
andauthored
Fix: Ledger device minimum migratable amount (#71)
* fix: refactor software profile submiting offledger request for single and multiple bundles * fix: add submitting multiple bundles for ledger devices * fix: update submitting multiple modules for ledger devices * fix: error "tx not added to the mempool" * fix: add migration log for multiple bundles * fix: remove extra routing after migration * fix: test hardcoding amount for ledger devices * fix: address indexes in bundles * fix: address indexes in bundles * fix: remove log file * fix: add warning messages to popup for ledger transfers less than 1 IOTA * fix: update warning messages for ledger migrations --------- Co-authored-by: cpl121 <[email protected]>
1 parent 72ec9f8 commit aa71047

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

packages/shared/components/popups/LedgerLegacyTransaction.svelte

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="typescript" xmlns="http://www.w3.org/1999/html">
22
import { Animation, Text } from 'shared/components'
33
import { formatAddressForLedger } from 'shared/lib/ledger'
4-
import { asyncGetAddressChecksum } from 'shared/lib/migration'
4+
import { MINIMUM_MIGRATABLE_AMOUNT, asyncGetAddressChecksum } from 'shared/lib/migration'
55
import { Input, Transfer } from 'shared/lib/typings/migration'
66
import { formatUnitBestMatch } from 'shared/lib/units'
77
import { Locale } from '@core/i18n'
@@ -11,6 +11,11 @@
1111
export let transfer: Transfer
1212
export let inputs: Input[]
1313
14+
const outputAmount: number = inputs.reduce(
15+
(acc, input) => acc + (input.balance < MINIMUM_MIGRATABLE_AMOUNT ? MINIMUM_MIGRATABLE_AMOUNT : input.balance),
16+
0
17+
)
18+
1419
// Hardcoded strings because Ledger does not translate them
1520
const checksumString = (checksum): string => `Chk: ${checksum}`
1621
const inputString = (index): string => `Input [${index}]`
@@ -19,6 +24,9 @@
1924

2025
<Text type="h4" classes="mb-6">{locale('popups.ledgerTransaction.transaction.title')}</Text>
2126
<Text type="p" classes="mb-6" secondary>{locale('popups.ledgerTransaction.transaction.info')}</Text>
27+
{#if outputAmount !== transfer.value}
28+
<Text type="p" error classes="mb-6" secondary>{locale('popups.ledgerTransaction.transaction.warning')}</Text>
29+
{/if}
2230

2331
<div class="relative w-full h-1/2 bg-white dark:bg-gray-900 flex justify-center content-center">
2432
<Animation
@@ -32,7 +40,14 @@
3240
<div class="transaction flex flex-col space-y-4 scrollable-y">
3341
<div class="rounded-lg bg-gray-50 dark:bg-gray-800 p-5 text-center">
3442
<Text type="h5" highlighted classes="mb-2">{outputString}</Text>
35-
<Text type="pre">{formatUnitBestMatch(transfer.value)}</Text>
43+
<Text type="pre">{formatUnitBestMatch(outputAmount)}</Text>
44+
{#if outputAmount !== transfer.value}
45+
<Text error type="pre">
46+
{locale('popups.ledgerTransaction.transaction.inputAmount', {
47+
values: { amount: formatUnitBestMatch(transfer.value) },
48+
})}
49+
</Text>
50+
{/if}
3651
<Text type="pre">{formatAddressForLedger(transfer.address, true)}</Text>
3752
<Text type="pre">
3853
{#await asyncGetAddressChecksum(transfer.address)}...{:then checksum}{checksumString(checksum)}{/await}
@@ -41,7 +56,16 @@
4156
{#each inputs as { address, balance, index }}
4257
<div class="rounded-lg bg-gray-50 dark:bg-gray-800 p-5 text-center">
4358
<Text type="h5" highlighted classes="mb-2">{inputString(index)}</Text>
44-
<Text type="pre">{formatUnitBestMatch(balance)}</Text>
59+
<Text type="pre"
60+
>{formatUnitBestMatch(balance < MINIMUM_MIGRATABLE_AMOUNT ? MINIMUM_MIGRATABLE_AMOUNT : balance)}</Text
61+
>
62+
{#if balance < MINIMUM_MIGRATABLE_AMOUNT}
63+
<Text error type="pre"
64+
>{locale('popups.ledgerTransaction.transaction.inputAmount', {
65+
values: { amount: formatUnitBestMatch(balance) },
66+
})}
67+
</Text>
68+
{/if}
4569
<Text type="pre">{formatAddressForLedger(address)}</Text>
4670
<Text type="pre">
4771
{#await asyncGetAddressChecksum(address, true)}...{:then checksum}{checksumString(checksum)}{/await}

packages/shared/lib/migration.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,18 +695,39 @@ export const createLedgerMigrationBundle = (
695695
): Promise<MigrationBundle> => {
696696
const bundle = findMigrationBundle(bundleIndex)
697697

698-
const transfer = {
698+
const transferForConfirmation = {
699699
address: migrationAddress.trytes,
700700
value: bundle.inputs.reduce((acc, input) => acc + input.balance, 0),
701701
tag: 'U'.repeat(27),
702702
}
703703

704-
openLedgerLegacyTransactionPopup(transfer, bundle.inputs)
704+
openLedgerLegacyTransactionPopup(transferForConfirmation, bundle.inputs)
705705

706-
return prepareTransfersFn(
707-
[transfer],
708-
bundle.inputs.map((input) => Object.assign({}, input, { keyIndex: input.index }))
709-
).then((trytes) => {
706+
const transfers = [
707+
{
708+
address: migrationAddress.trytes,
709+
value: bundle.inputs.reduce(
710+
(acc, input) =>
711+
acc + (input.balance < MINIMUM_MIGRATABLE_AMOUNT ? MINIMUM_MIGRATABLE_AMOUNT : input.balance),
712+
0
713+
),
714+
tag: 'U'.repeat(27),
715+
},
716+
]
717+
718+
// The correct amount for migration is tracked in totalBalance and is diplayed to the user.
719+
// If the totalBalance is less than the Min required storage deposit on stardust the receipt will contain the error messgage
720+
// ex. "not enough base tokens for storage deposit: available 211188 < required 239500 base tokens"
721+
// Hardcode MINIMUM_MIGRATABLE_AMOUNT for every input so we bypass legacy validation tool in contract which doesnt allow migrating less than MINIMUM_MIGRATABLE_AMOUNT.
722+
// The ISC only cares about the addresses in the bundle, it internaly resolves the balances and does NOT depend on the amounts hardcoded here.
723+
const inputsForTransfer: any[] = bundle.inputs.map((input) => ({
724+
address: input.address,
725+
keyIndex: input.index,
726+
security: input.securityLevel,
727+
balance: input.balance < MINIMUM_MIGRATABLE_AMOUNT ? MINIMUM_MIGRATABLE_AMOUNT : input.balance, // hardcoded amount
728+
}))
729+
730+
return prepareTransfersFn(transfers, inputsForTransfer).then((trytes) => {
710731
updateLedgerBundleState(bundleIndex, trytes, false)
711732
callback()
712733
return { trytes, bundleHash: asTransactionObject(trytes[0]).bundle }

packages/shared/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,9 @@
845845
},
846846
"transaction": {
847847
"title": "Confirm transaction",
848-
"info": "Confirm that the transaction information displayed on your Ledger device matches the information displayed below. If they match, press both buttons on your Ledger as prompted."
848+
"info": "Confirm that the transaction information displayed on your Ledger device matches the information displayed below. If they match, press both buttons on your Ledger as prompted.",
849+
"warning": "Due to constraints in the legacy network, addresses with amounts below the minimum migratable threshold will show 1 IOTA as the input amount.",
850+
"inputAmount": "Amount that will be migrated: {amount}"
849851
}
850852
},
851853
"ledgerAddress": {

0 commit comments

Comments
 (0)