Skip to content

Commit

Permalink
SetupSwapLedger: handle FETCHING_BITCOIN_TX and BITCOIN_TX_MISMATCH s…
Browse files Browse the repository at this point in the history
…tates

These states were introduced in 4193879 but SetupSwapLedger was not adapted accordingly.
  • Loading branch information
danimoh committed Dec 11, 2024
1 parent 21131b8 commit 0c566f9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 40 deletions.
46 changes: 26 additions & 20 deletions src/i18n/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ msgid "Add Vesting Contract"
msgstr ""

#: src/components/CheckoutCard.vue:84
#: src/views/SetupSwapLedger.vue:292
#: src/views/SetupSwapLedger.vue:290
msgid "Address"
msgstr ""

Expand All @@ -99,8 +99,8 @@ msgstr ""
#: src/components/CheckoutCardBitcoin.vue:30
#: src/components/CheckoutCardEthereum.vue:27
#: src/components/CheckoutCardNimiqExternal.vue:32
#: src/views/SetupSwapLedger.vue:285
#: src/views/SetupSwapLedger.vue:294
#: src/views/SetupSwapLedger.vue:283
#: src/views/SetupSwapLedger.vue:292
msgid "Amount"
msgstr ""

Expand Down Expand Up @@ -198,8 +198,9 @@ msgstr ""
msgid "Bitcoin activated"
msgstr ""

#: src/views/SetupSwapSuccess.vue:662
msgid "Bitcoin HTLC invalid: {error}"
#: src/views/SetupSwapLedger.vue:858
#: src/views/SetupSwapSuccess.vue:640
msgid "Bitcoin HTLC invalid"
msgstr ""

#: src/lib/LabelingMachine.ts:31
Expand Down Expand Up @@ -340,7 +341,7 @@ msgstr ""
msgid "Collecting payment details"
msgstr ""

#: src/views/SetupSwapLedger.vue:991
#: src/views/SetupSwapLedger.vue:999
msgid "Confirm {outgoingOrIncoming} transaction on Ledger"
msgstr ""

Expand Down Expand Up @@ -534,8 +535,8 @@ msgstr ""
#: src/components/CheckoutCardBitcoin.vue:47
#: src/components/CheckoutCardNimiqExternal.vue:47
#: src/components/CurrencyInfo.vue:15
#: src/views/SetupSwapLedger.vue:287
#: src/views/SetupSwapLedger.vue:303
#: src/views/SetupSwapLedger.vue:285
#: src/views/SetupSwapLedger.vue:301
msgid "Fee"
msgstr ""

Expand All @@ -544,19 +545,20 @@ msgstr ""
msgid "Fetching Addresses Failed"
msgstr ""

#: src/views/SetupSwapSuccess.vue:651
#: src/views/SetupSwapLedger.vue:870
#: src/views/SetupSwapSuccess.vue:653
msgid "Fetching Bitcoin HTLC..."
msgstr ""

#: src/views/AddVestingContract.vue:16
msgid "Fetching contract information..."
msgstr ""

#: src/views/SetupSwapSuccess.vue:659
#: src/views/SetupSwapSuccess.vue:662
msgid "Fetching swap data failed: {error}"
msgstr ""

#: src/views/SetupSwapSuccess.vue:647
#: src/views/SetupSwapSuccess.vue:649
msgid "Fetching swap data..."
msgstr ""

Expand Down Expand Up @@ -630,7 +632,7 @@ msgstr ""
msgid "Imported {count} address so far... | Imported {count} addresses so far..."
msgstr ""

#: src/views/SetupSwapLedger.vue:994
#: src/views/SetupSwapLedger.vue:1002
msgid "incoming"
msgstr ""

Expand Down Expand Up @@ -794,7 +796,7 @@ msgstr ""
msgid "Other wallets"
msgstr ""

#: src/views/SetupSwapLedger.vue:993
#: src/views/SetupSwapLedger.vue:1001
msgid "outgoing"
msgstr ""

Expand Down Expand Up @@ -854,7 +856,7 @@ msgstr ""
msgid "Prepare for update"
msgstr ""

#: src/views/SetupSwapSuccess.vue:640
#: src/views/SetupSwapSuccess.vue:642
msgid "Preparing Swap"
msgstr ""

Expand Down Expand Up @@ -922,7 +924,7 @@ msgstr ""
#: src/views/ActivatePolygonSuccess.vue:139
#: src/views/BitcoinSyncBaseView.vue:72
#: src/views/LoginSuccess.vue:134
#: src/views/SetupSwapSuccess.vue:669
#: src/views/SetupSwapSuccess.vue:672
#: src/views/SignupLedger.vue:145
msgid "Retry"
msgstr ""
Expand Down Expand Up @@ -961,7 +963,7 @@ msgstr ""
msgid "Sign Message"
msgstr ""

#: src/views/SetupSwapSuccess.vue:649
#: src/views/SetupSwapSuccess.vue:651
msgid "Signing transactions..."
msgstr ""

Expand Down Expand Up @@ -1003,15 +1005,15 @@ msgstr ""
msgid "Storing your new accounts..."
msgstr ""

#: src/views/SetupSwapLedger.vue:258
#: src/views/SetupSwapLedger.vue:256
msgid "Swap authorized"
msgstr ""

#: src/views/SetupSwapLedger.vue:73
msgid "Swap fee"
msgstr ""

#: src/views/SetupSwapLedger.vue:855
#: src/views/SetupSwapLedger.vue:854
#: src/views/SetupSwapSuccess.vue:636
msgid "Swap Setup Failed"
msgstr ""
Expand All @@ -1029,7 +1031,7 @@ msgstr ""

#: src/views/ActivatePolygonSuccess.vue:113
#: src/views/BitcoinSyncBaseView.vue:50
#: src/views/SetupSwapLedger.vue:857
#: src/views/SetupSwapLedger.vue:856
#: src/views/SetupSwapSuccess.vue:638
#: src/views/SignBtcTransactionLedger.vue:118
msgid "Syncing Failed"
Expand All @@ -1052,7 +1054,7 @@ msgid "Syncing with Bitcoin network failed: {error}"
msgstr ""

#: src/views/BitcoinSyncBaseView.vue:58
#: src/views/SetupSwapLedger.vue:867
#: src/views/SetupSwapLedger.vue:868
msgid "Syncing with Bitcoin network..."
msgstr ""

Expand Down Expand Up @@ -1165,6 +1167,10 @@ msgstr ""
msgid "Try again"
msgstr ""

#: src/views/SetupSwapLedger.vue:860
msgid "Unexpected error"
msgstr ""

#: src/components/NotEnoughCookieSpace.vue:7
msgid "Unfortunately, due to restrictions of Safari you cannot add more accounts and/or addresses. Please log out of unused accounts to free up space."
msgstr ""
Expand Down
36 changes: 22 additions & 14 deletions src/views/SetupSwapLedger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,12 @@
</div>
</PageBody>

<div class="bottom-container" :class="{
'full-height': state === State.SYNCING_FAILED || state === State.FETCHING_SWAP_DATA_FAILED,
}">
<div class="bottom-container" :class="{ 'full-height': statusScreenState === StatusScreenState.ERROR }">
<!-- Do not display the LedgerUi until hiding the swap authorization, to not start the connect animation
while the LedgerUi would be hidden behind the swap authorization. Do not do the same for Bitcoin address
SYNCING state because SYNCING can also occur again throughout the process (to fetch the BTC transaction
that funds the HTLC) in which case we do not want to hide the LedgerUi in the background while the
SYNCING StatusScreen is still fading in. -->
SYNCING and FETCHING_BITCOIN_TX states because those can also occur again throughout the process (to
fetch the BTC transaction that funds the HTLC) in which case we do not want to hide the LedgerUi in the
background while the SYNCING StatusScreen is still fading in. -->
<LedgerUi small
v-if="!swapAuthorizationShown"
@information-shown="ledgerInstructionsShown = true"
Expand Down Expand Up @@ -311,15 +309,14 @@
/>
</div>
</div>
<StatusScreen v-else-if="state === State.SYNCING_FAILED || state === State.FETCHING_SWAP_DATA_FAILED
|| !ledgerInstructionsShown"
<StatusScreen v-else-if="statusScreenState === StatusScreenState.ERROR || !ledgerInstructionsShown"
:state="statusScreenState"
:title="statusScreenTitle"
:status="statusScreenStatus"
:message="statusScreenMessage"
:mainAction="statusScreenAction"
@main-action="_statusScreenActionHandler"
:small="state !== State.SYNCING_FAILED && state !== State.FETCHING_SWAP_DATA_FAILED"
:small="statusScreenState !== StatusScreenState.ERROR"
/>
</transition>
</div>
Expand Down Expand Up @@ -435,6 +432,7 @@ export default class SetupSwapLedger extends Mixins(SetupSwap, SetupSwapSuccess)
protected _account!: WalletInfo;
private readonly SwapAsset = SwapAsset;
private readonly LedgerApiStateType = LedgerApiStateType;
private readonly StatusScreenState = StatusScreen.State;
private _setupSwapPromise!: Promise<SwapSetupInfo>;
private nimiqLedgerAddressInfo?: { address: Nimiq.Address, label: string, balance: number, signerPath: string };
private _nimiqSwapProxyPromise?: Promise<LedgerSwapProxy>;
Expand Down Expand Up @@ -850,21 +848,31 @@ export default class SetupSwapLedger extends Mixins(SetupSwap, SetupSwapSuccess)
// Getters for displaying information
protected get statusScreenTitle() {
if (this.statusScreenState !== StatusScreen.State.ERROR) return ''; // don't display a title in small ui state
switch (this.state) {
case this.State.FETCHING_SWAP_DATA_FAILED:
return this.$t('Swap Setup Failed') as string;
case this.State.SYNCING_FAILED:
return this.$t('Syncing Failed') as string;
case this.State.BITCOIN_TX_MISMATCH:
return this.$t('Bitcoin HTLC invalid') as string;
default:
return ''; // don't display a title in small ui state
return this.$t('Unexpected error') as string;
}
}
protected get statusScreenStatus() {
// Other than SetupSwapSuccess do no show a status for FETCHING_SWAP_DATA and SIGNING_TRANSACTIONS as during
// these states typically the LedgerUi is / was just active and the StatusScreen will fade.
if (this.state !== this.State.SYNCING) return '';
return this.$t('Syncing with Bitcoin network...') as string;
if (this.statusScreenState !== StatusScreen.State.LOADING) return ''; // the status is only relevant for LOADING
switch (this.state) {
case this.State.SYNCING:
return this.$t('Syncing with Bitcoin network...') as string;
case this.State.FETCHING_BITCOIN_TX:
return this.$t('Fetching Bitcoin HTLC...') as string;
default:
// Different to SetupSwapSuccess do not show a status for FETCHING_SWAP_DATA and SIGNING_TRANSACTIONS as
// during these states typically the LedgerUi is / was just active and the StatusScreen will fade.
return '';
}
}
private get _fundingAmountInfo(): SwapAmountInfo {
Expand Down
15 changes: 9 additions & 6 deletions src/views/SetupSwapSuccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
return this.$t('Swap Setup Failed') as string;
case this.State.SYNCING_FAILED:
return this.$t('Syncing Failed') as string;
case this.State.BITCOIN_TX_MISMATCH:
return this.$t('Bitcoin HTLC invalid') as string;
default:
return this.$t('Preparing Swap') as string;
}
Expand All @@ -655,13 +657,14 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
}
protected get statusScreenMessage() {
if (this.state === this.State.FETCHING_SWAP_DATA_FAILED) {
return this.$t('Fetching swap data failed: {error}', { error: this.error }) as string;
}
if (this.state === this.State.BITCOIN_TX_MISMATCH) {
return this.$t('Bitcoin HTLC invalid: {error}', { error: this.btcMismatchError }) as string;
switch (this.state) {
case this.State.FETCHING_SWAP_DATA_FAILED:
return this.$t('Fetching swap data failed: {error}', { error: this.error }) as string;
case this.State.BITCOIN_TX_MISMATCH:
return this.btcMismatchError;
default:
return super.statusScreenMessage;
}
return super.statusScreenMessage;
}
protected get statusScreenAction() {
Expand Down

0 comments on commit 0c566f9

Please sign in to comment.