diff --git a/locale/cnr/translation.toml b/locale/cnr/translation.toml index 9032b5d82..90d2c3514 100644 --- a/locale/cnr/translation.toml +++ b/locale/cnr/translation.toml @@ -209,7 +209,7 @@ syncStatusStarting = "Vaš novčanik se sinhronizuje!
Moći ćete ga p syncStatusFinished = "Završena sinhronizacija!
Vaš novčanik je spreman za upotrebu!" # Sync Finished!
Your wallet is ready to use! activityReceivedWith = "Primljeno sa {s}" # Received with {s} accountDeleted = "Vaš nalog je uspešno obrisan!" # Your account has been successfully deleted! -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} chartImmatureBalance = "" # Immature balance useShieldInputs = "" # Use shield inputs @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Interna greška, molimo pokušajte ponovo kasnije" # Internal error, please try again later diff --git a/locale/de/translation.toml b/locale/de/translation.toml index 282b84bc0..6c4c87d87 100644 --- a/locale/de/translation.toml +++ b/locale/de/translation.toml @@ -210,7 +210,7 @@ accountDeleted = "Deine Geldbörse wurde erfolgreich gelöscht" # Your account h activitySelf = "Eigenüberweisung" # self activityReceivedWith = "Erhalten über {s}" # Received with {s} chartImmatureBalance = "" # Immature balance -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} useShieldInputs = "" # Use shield inputs newShieldAddress = "" # Get new shield address @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Interner Fehler, bitte versuche es später erneut" # Internal error, please try again later diff --git a/locale/en/translation.toml b/locale/en/translation.toml index 25f5ccc0b..d0956ed49 100644 --- a/locale/en/translation.toml +++ b/locale/en/translation.toml @@ -210,7 +210,7 @@ syncStatusFinished = "Sync Finished!
Your wallet is ready to use!" # < activityReceivedWith = "Received with {s}" # Received with {s} accountDeleted = "Your account has been successfully deleted!" # Your account has been successfully deleted! chartImmatureBalance = "Immature balance" # Immature balance -syncLoadingSaplingProver = "Loading Sapling Prover" # Loading Sapling Prover +syncLoadingSaplingProver = "Loading SHIELD parameters..." # Loading SHIELD parameters... syncShieldProgress = "Loading shielded blocks {current} of {total}" # Loading shielded blocks {current} of {total} useShieldInputs = "Use shield inputs" # Use shield inputs newShieldAddress = "Get new shield address" # Get new shield address @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "Auto Lock the Wallet" # Auto Lock the Wallet saveWalletFile = "Save Wallet File" # Save Wallet File proposalOverBudget = "Over Budget" # Over Budget badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "Creating SHIELD transaction..." # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Internal error, please try again later" # Internal error, please try again later diff --git a/locale/es-mx/translation.toml b/locale/es-mx/translation.toml index 4a422bfaf..8799397c0 100644 --- a/locale/es-mx/translation.toml +++ b/locale/es-mx/translation.toml @@ -210,7 +210,7 @@ contestedProposalsTitle = "" # Contested Proposals accountDeleted = "" # Your account has been successfully deleted! activityReceivedWith = "" # Received with {s} chartImmatureBalance = "" # Immature balance -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} useShieldInputs = "" # Use shield inputs newShieldAddress = "" # Get new shield address @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Error interno, vuelve a intentarlo más tarde" # Internal error, please try again later diff --git a/locale/fr/translation.toml b/locale/fr/translation.toml index 33853af66..3ebe8c866 100644 --- a/locale/fr/translation.toml +++ b/locale/fr/translation.toml @@ -210,7 +210,7 @@ contestedProposalsTitle = "Propositions contestées" # Contested Proposals accountDeleted = "" # Your account has been successfully deleted! activityReceivedWith = "Reçu avec {s}" # Received with {s} chartImmatureBalance = "" # Immature balance -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} useShieldInputs = "" # Use shield inputs newShieldAddress = "" # Get new shield address @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Erreur interne, veuillez réessayer plus tard" # Internal error, please try again later diff --git a/locale/it/translation.toml b/locale/it/translation.toml index ac4d42045..4af5510b4 100644 --- a/locale/it/translation.toml +++ b/locale/it/translation.toml @@ -210,7 +210,7 @@ settingsToggleAdvancedModeSubtext = "Sblocca funzionalità e personalizzazioni p accountDeleted = "Il tuo account è stato eliminato con successo!" # Your account has been successfully deleted! activityReceivedWith = "Ricevuto con {s}" # Received with {s} chartImmatureBalance = "Saldo immaturo" # Immature balance -syncLoadingSaplingProver = "Caricamento del Sapling Prover" # Loading Sapling Prover +syncLoadingSaplingProver = "Caricamento del Sapling Prover" # Loading SHIELD parameters... syncShieldProgress = "Caricamento blocchi shield {current}/{total}" # Loading shielded blocks {current} of {total} useShieldInputs = "Usa input shield" # Use shield inputs newShieldAddress = "Genera un nuovo indirizzo shield" # Get new shield address @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Errore interno, rirova più tardi" # Internal error, please try again later diff --git a/locale/nl/translation.toml b/locale/nl/translation.toml index c833cf311..e70dc7836 100644 --- a/locale/nl/translation.toml +++ b/locale/nl/translation.toml @@ -210,7 +210,7 @@ syncStatusFinished = "" # Sync Finished!
Your wallet is ready to use! accountDeleted = "" # Your account has been successfully deleted! activityReceivedWith = "" # Received with {s} chartImmatureBalance = "" # Immature balance -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} useShieldInputs = "" # Use shield inputs newShieldAddress = "" # Get new shield address @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Interne fout, probeer het later opnieuw" # Internal error, please try again later diff --git a/locale/ph/translation.toml b/locale/ph/translation.toml index c1ae52dae..36d2dba1f 100644 --- a/locale/ph/translation.toml +++ b/locale/ph/translation.toml @@ -210,7 +210,7 @@ accountDeleted = "" # Your account has been successfully deleted! activityReceivedWith = "" # Received with {s} popupProposalName = "" # Proposal Name chartImmatureBalance = "" # Immature balance -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} useShieldInputs = "" # Use shield inputs newShieldAddress = "" # Get new shield address @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Internal error, Pakiusap uliting muli" # Internal error, please try again later diff --git a/locale/pl/translation.toml b/locale/pl/translation.toml index e6efdfe42..82bfc7344 100644 --- a/locale/pl/translation.toml +++ b/locale/pl/translation.toml @@ -209,7 +209,7 @@ syncStatusStarting = "Twój portfel jest w trakcie synchronizacji!
Po syncStatusFinished = "Synchronizacja Zakończona!
Twój portfel jest gotowy do użycia!" # Sync Finished!
Your wallet is ready to use! activityReceivedWith = "Otrzymano z {s}" # Received with {s} accountDeleted = "Twoje konto zostało pomyślnie usunięte!" # Your account has been successfully deleted! -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} chartImmatureBalance = "" # Immature balance useShieldInputs = "" # Use shield inputs @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Błąd wewnętrzny, spróbuj ponownie później" # Internal error, please try again later diff --git a/locale/pt-br/translation.toml b/locale/pt-br/translation.toml index 26121fa21..b1ec19379 100644 --- a/locale/pt-br/translation.toml +++ b/locale/pt-br/translation.toml @@ -77,7 +77,7 @@ syncStatusStarting = "Sua carteira está sincronizando!
Você poderá syncStatusFinished = " Sincronização Terminada!
Sua carteira está pronta para ser utilizada" # Sync Finished!
Your wallet is ready to use! accountDeleted = "Sua conta foi deletada com successo" # Your account has been successfully deleted! chartImmatureBalance = "" # Immature balance -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} useShieldInputs = "" # Use shield inputs newShieldAddress = "" # Get new shield address @@ -87,6 +87,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] STAKE_ADDR_SET = "Endereço de Cold Staking definido!
Ao fazer Stake no futuro este endereço irá ser usado." # Cold Address set!
Future stakes will use this address. diff --git a/locale/pt-pt/translation.toml b/locale/pt-pt/translation.toml index 58f40537a..ea6d00b9a 100644 --- a/locale/pt-pt/translation.toml +++ b/locale/pt-pt/translation.toml @@ -77,7 +77,7 @@ syncStatusStarting = "Sua carteira está sincronizando!
Você poderá syncStatusFinished = "Sincronização concluída!
Sua carteira está pronta para uso!" # Sync Finished!
Your wallet is ready to use! accountDeleted = "Sua conta foi excluída com sucesso!" # Your account has been successfully deleted! chartImmatureBalance = "" # Immature balance -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} useShieldInputs = "" # Use shield inputs newShieldAddress = "" # Get new shield address @@ -87,6 +87,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "" # Save Wallet File proposalOverBudget = "" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] STAKE_ADDR_SET = "Endereço de Cold Staking definido!
Ao fazer Stake no futuro irá ser usado este endereço." # Cold Address set!
Future stakes will use this address. diff --git a/locale/template/translation.toml b/locale/template/translation.toml index 2469fcb76..cd777e5b4 100644 --- a/locale/template/translation.toml +++ b/locale/template/translation.toml @@ -74,7 +74,7 @@ secureYourWallet = "Secure your wallet" unlockWallet = "Unlock wallet" lockWallet = "Lock wallet" syncStatusHistoryProgress = "Syncing History Chunks {current} of {total}" -syncLoadingSaplingProver = "Loading Sapling Prover" +syncLoadingSaplingProver = "Loading SHIELD parameters..." syncShieldProgress = "Loading shielded blocks {current} of {total}" syncStatusStarting = "Your wallet is syncing!
You'll be able to use it fully once this is complete." syncStatusFinished = "Sync Finished!
Your wallet is ready to use!" @@ -244,6 +244,7 @@ newShieldAddress = "Get new shield address" shieldAddress = "Shield address" cantShieldToExc = "This address does not support shield transfers" badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)" +creatingShieldTransaction = "Creating SHIELD transaction..." [ALERTS] INTERNAL_ERROR = "Internal error, please try again later" diff --git a/locale/uwu/translation.toml b/locale/uwu/translation.toml index a86140326..2ec8dde52 100644 --- a/locale/uwu/translation.toml +++ b/locale/uwu/translation.toml @@ -210,7 +210,7 @@ accountDeleted = "" # Your account has been successfully deleted! activityShieldedAddress = "" # Shielded address activityReceivedWith = "" # Received with {s} chartImmatureBalance = "" # Immature balance -syncLoadingSaplingProver = "" # Loading Sapling Prover +syncLoadingSaplingProver = "" # Loading SHIELD parameters... syncShieldProgress = "" # Loading shielded blocks {current} of {total} useShieldInputs = "" # Use shield inputs newShieldAddress = "" # Get new shield address @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet saveWalletFile = "Save Wawwet File" # Save Wallet File proposalOverBudget = "Over Budgey" # Over Budget badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root) +creatingShieldTransaction = "" # Creating SHIELD transaction... [ALERTS] INTERNAL_ERROR = "Internal error, pwease try again later" # Internal error, please try again later diff --git a/scripts/composables/use_wallet.js b/scripts/composables/use_wallet.js index 5e27a585b..bceb179bb 100644 --- a/scripts/composables/use_wallet.js +++ b/scripts/composables/use_wallet.js @@ -25,8 +25,8 @@ export const useWallet = defineStore('wallet', () => { const loadFromDisk = () => wallet.loadFromDisk(); const hasShield = ref(wallet.hasShield()); - const setMasterKey = async (mk) => { - wallet.setMasterKey(mk); + const setMasterKey = async ({ mk, extsk }) => { + wallet.setMasterKey({ mk, extsk }); isImported.value = wallet.isLoaded(); isHardwareWallet.value = wallet.isHardwareWallet(); isHD.value = wallet.isHD(); @@ -90,6 +90,7 @@ export const useWallet = defineStore('wallet', () => { return res; } ); + const isCreatingTransaction = () => createAndSendTransaction.isLocked(); getEventEmitter().on('toggle-network', async () => { isEncrypted.value = await hasEncryptedWallet(); @@ -122,6 +123,7 @@ export const useWallet = defineStore('wallet', () => { wallet.wipePrivateData(); isViewOnly.value = wallet.isViewOnly(); }, + isCreatingTransaction, isHD, balance, hasShield, diff --git a/scripts/dashboard/Dashboard.vue b/scripts/dashboard/Dashboard.vue index a91281121..febf5e063 100644 --- a/scripts/dashboard/Dashboard.vue +++ b/scripts/dashboard/Dashboard.vue @@ -101,7 +101,7 @@ async function importWallet({ type, secret, password = '' }) { ); } if (parsedSecret) { - await wallet.setMasterKey(parsedSecret.masterKey); + await wallet.setMasterKey({ mk: parsedSecret.masterKey }); wallet.setShield(parsedSecret.shield); jdenticonValue.value = wallet.getAddress(); @@ -155,16 +155,13 @@ async function restoreWallet(strReason) { async function importWif(wif, extsk) { const secret = await ParsedSecret.parse(wif); if (secret.masterKey) { - await wallet.setMasterKey(secret.masterKey); + await wallet.setMasterKey({ mk: secret.masterKey, extsk }); if (wallet.hasShield && !extsk) { createAlert( 'warning', 'Could not decrypt sk even if password is correct, please contact a developer' ); } - if (wallet.hasShield) { - await wallet.setExtsk(extsk); - } createAlert('success', ALERTS.WALLET_UNLOCKED, 1500); } } @@ -226,7 +223,7 @@ async function send(address, amount, useShieldInputs) { } // Make sure we are not already creating a (shield) tx - if (wallet.createAndSendTransaction.isLocked()) { + if (wallet.isCreatingTransaction()) { return createAlert( 'warning', 'Already creating a transaction! please wait for it to finish' @@ -357,7 +354,7 @@ function getMaxBalance(useShieldInputs) { getEventEmitter().on('toggle-network', async () => { const database = await Database.getInstance(); const account = await database.getAccount(); - await wallet.setMasterKey(null); + await wallet.setMasterKey({ mk: null }); activity.value?.reset(); if (wallet.isEncrypted) { diff --git a/scripts/dashboard/WalletBalance.vue b/scripts/dashboard/WalletBalance.vue index f6acf6998..3cc063f70 100644 --- a/scripts/dashboard/WalletBalance.vue +++ b/scripts/dashboard/WalletBalance.vue @@ -67,7 +67,7 @@ const syncSStr = ref(''); // Shield transaction creation const isCreatingTx = ref(false); const txPercentageCreation = ref(0.0); -const txCreationStr = 'Creating SHIELD transaction...'; +const txCreationStr = ref('Creating SHIELD transaction...'); const balanceStr = computed(() => { const nCoins = balance.value / COIN; @@ -116,9 +116,15 @@ getEventEmitter().on('shield-sync-status-update', (str, finished) => { getEventEmitter().on( 'shield-transaction-creation-update', async (percentage, finished) => { + if (percentage === 0.0 && !finished) { + txCreationStr.value = translation.syncLoadingSaplingProver; + } else { + txCreationStr.value = translation.creatingShieldTransaction; + } + // If it just finished sleep for 1 second before making everything invisible - txPercentageCreation.value = 100.0; if (finished) { + txPercentageCreation.value = 100.0; await sleep(1000); } isCreatingTx.value = !finished; diff --git a/scripts/global.js b/scripts/global.js index 4209a003c..196d500b2 100644 --- a/scripts/global.js +++ b/scripts/global.js @@ -709,7 +709,7 @@ export async function sweepAddress(arrUTXOs, sweepingMasterKey, nFixedFee) { // Sign using the given Master Key, then broadcast the sweep, returning the TXID (or a failure) const sweepingWallet = new Wallet({ nAccount: 0 }); - sweepingWallet.setMasterKey(sweepingMasterKey); + sweepingWallet.setMasterKey({ mk: sweepingMasterKey }); await sweepingWallet.sign(tx); return await getNetwork().sendTransaction(tx.serialize()); diff --git a/scripts/mempool.js b/scripts/mempool.js index 836960d72..8103759dc 100644 --- a/scripts/mempool.js +++ b/scripts/mempool.js @@ -177,6 +177,7 @@ export class Mempool { * By default it's `OutpointState.SPENT | OutpointState.IMMATURE | OutpointState.LOCKED` * @param {number} [o.requirement] - A requirement to apply to all UTXOs. For example * `OutpointState.P2CS` will only return P2CS transactions. + * @param {number} [o.target] - Number of satoshis needed. The method will return early when the value of the UTXOs has been reached, plus a bit to account for change * By default it's MAX_SAFE_INTEGER * @returns {UTXO[]} a list of unspent transaction outputs */ diff --git a/scripts/stake/Stake.vue b/scripts/stake/Stake.vue index 85cc4c72c..f3349a873 100644 --- a/scripts/stake/Stake.vue +++ b/scripts/stake/Stake.vue @@ -106,16 +106,13 @@ async function restoreWallet(strReason) { async function importWif(wif, extsk) { const secret = await ParsedSecret.parse(wif); if (secret.masterKey) { - await wallet.setMasterKey(secret.masterKey); + await wallet.setMasterKey({ mk: secret.masterKey, extsk }); if (wallet.hasShield && !extsk) { createAlert( 'warning', 'Could not decrypt sk even if password is correct, please contact a developer' ); } - if (wallet.hasShield) { - await wallet.setExtsk(extsk); - } createAlert('success', ALERTS.WALLET_UNLOCKED, 1500); } } diff --git a/scripts/wallet.js b/scripts/wallet.js index 7f30a6d0d..675d8d2b0 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -212,14 +212,18 @@ export class Wallet { /** * Set or replace the active Master Key with a new Master Key - * @param {import('./masterkey.js').MasterKey} mk - The new Master Key to set active + * @param {object} o - Object to be destructured + * @param {import('./masterkey.js').MasterKey} o.mk - The new Master Key + * @param {number} [o.nAccount] - The account number + * @param {string} [o.extsk] - The extended spending key */ - setMasterKey(mk, nAccount = 0) { + async setMasterKey({ mk, nAccount = 0, extsk }) { const isNewAcc = mk?.getKeyToExport(nAccount) !== this.#masterKey?.getKeyToExport(this.#nAccount); this.#masterKey = mk; this.#nAccount = nAccount; + if (extsk) await this.setExtsk(extsk); if (isNewAcc) { this.reset(); for (let i = 0; i < Wallet.chains; i++) this.loadAddresses(i); @@ -721,12 +725,6 @@ export class Wallet { return; } const cNet = getNetwork(); - getEventEmitter().emit( - 'shield-sync-status-update', - translation.syncLoadingSaplingProver, - false - ); - await this.#shield.loadSaplingProver(); try { const blockHeights = (await cNet.getShieldBlockList()).filter( (b) => b > this.#shield.getLastSyncedBlock() @@ -784,13 +782,15 @@ export class Wallet { /** * @todo this needs to take the `vin` as input, * But currently we don't have any way of getting the UTXO - * out of the vin. This will hapèen after the mempool refactor, + * out of the vin. This will happen after the mempool refactor, * But for now we can just recalculate the UTXOs + * @param {number} target - Number of satoshis needed. See Mempool.getUTXOs */ - #getUTXOsForShield() { + #getUTXOsForShield(target = Number.POSITIVE_INFINITY) { return this.#mempool .getUTXOs({ requirement: OutpointState.P2PKH | OutpointState.OURS, + target, }) .map((u) => { return { @@ -1063,7 +1063,7 @@ export class Wallet { } const periodicFunction = setInterval(async () => { - const percentage = 5 + (await this.#shield.getTxStatus()) * 95; + const percentage = (await this.#shield.getTxStatus()) * 100; getEventEmitter().emit( 'shield-transaction-creation-update', percentage, @@ -1082,14 +1082,14 @@ export class Wallet { amount: value, blockHeight: blockCount + 1, useShieldInputs: transaction.vin.length === 0, - utxos: this.#getUTXOsForShield(), + utxos: this.#getUTXOsForShield(value), transparentChangeAddress: this.getNewAddress(1)[0], }); return transaction.fromHex(hex); } catch (e) { // sleep a full period of periodicFunction await sleep(500); - throw new Error(e); + throw e; } finally { clearInterval(periodicFunction); getEventEmitter().emit( diff --git a/tests/unit/test_utils.js b/tests/unit/test_utils.js index c52dad09a..1e43c31da 100644 --- a/tests/unit/test_utils.js +++ b/tests/unit/test_utils.js @@ -30,7 +30,7 @@ PIVXShield.prototype.getBalance = vi.fn(() => 40 * 10 ** 8); export async function setUpMainnetWallet() { const mempool = new Mempool(); const wallet = new Wallet({ nAccount: 0, isMainWallet: false, mempool }); - wallet.setMasterKey(getLegacyMainnet()); + wallet.setMasterKey({ mk: getLegacyMainnet() }); wallet.setShield(new PIVXShield()); // tx_1 provides a spendable balance of 0.1 * 10^8 satoshi diff --git a/tests/unit/use_wallet.spec.js b/tests/unit/use_wallet.spec.js index 3abee801c..3d81fa437 100644 --- a/tests/unit/use_wallet.spec.js +++ b/tests/unit/use_wallet.spec.js @@ -48,15 +48,15 @@ describe('useWallet tests', () => { }); it('is synced after importing key', async () => { - walletComposable.setMasterKey( - new LegacyMasterKey({ + walletComposable.setMasterKey({ + mk: new LegacyMasterKey({ pkBytes: new Uint8Array([ 181, 66, 141, 90, 213, 58, 137, 158, 160, 57, 109, 252, 51, 227, 221, 192, 8, 4, 223, 42, 42, 8, 191, 7, 251, 231, 167, 119, 54, 161, 194, 229, ]), - }) - ); + }), + }); expect(await isSyncedWithWallet()).toBe(true); }); @@ -71,6 +71,16 @@ describe('useWallet tests', () => { }); it('is synced after creating tx', async () => { + await walletComposable.setMasterKey({ + mk: new LegacyMasterKey({ + pkBytes: new Uint8Array([ + 181, 66, 141, 90, 213, 58, 137, 158, 160, 57, 109, 252, 51, + 227, 221, 192, 8, 4, 223, 42, 42, 8, 191, 7, 251, 231, 167, + 119, 54, 161, 194, 229, + ]), + }), + }); + await walletComposable.createAndSendTransaction( getNetwork(), 'DLabsktzGMnsK5K9uRTMCF6NoYNY6ET4Bb', diff --git a/tests/unit/wallet/transactions.spec.js b/tests/unit/wallet/transactions.spec.js index 46f152d51..570274b5a 100644 --- a/tests/unit/wallet/transactions.spec.js +++ b/tests/unit/wallet/transactions.spec.js @@ -38,9 +38,9 @@ async function checkFees(wallet, tx, feesPerBytes) { describe('Wallet transaction tests', () => { let wallet; const MIN_FEE_PER_BYTE = new TransactionBuilder().MIN_FEE_PER_BYTE; + beforeEach(async () => { wallet = await setUpMainnetWallet(); - // Reset indexedDB before each test vi.stubGlobal('indexedDB', new IDBFactory()); return vi.unstubAllGlobals;