From d55d5e9c7b417489ae5965a618460e234ea80098 Mon Sep 17 00:00:00 2001 From: Alessandro Rezzi Date: Wed, 17 Apr 2024 10:48:58 +0200 Subject: [PATCH 1/3] remove unused function --- scripts/wallet.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/scripts/wallet.js b/scripts/wallet.js index e2eb61152..f6e7a93bc 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -186,30 +186,6 @@ export class Wallet { return this.#masterKey.isHD; } - async hasWalletUnlocked(fIncludeNetwork = false) { - if (fIncludeNetwork && !getNetwork().enabled) - return createAlert( - 'warning', - ALERTS.WALLET_OFFLINE_AUTOMATIC, - 5500 - ); - if (!this.isLoaded()) { - return createAlert( - 'warning', - tr(ALERTS.WALLET_UNLOCK_IMPORT, [ - { - unlock: (await hasEncryptedWallet()) - ? 'unlock ' - : 'import/create', - }, - ]), - 3500 - ); - } else { - return true; - } - } - /** * 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 From d0decca417a971ef3e833640d73649045493a10c Mon Sep 17 00:00:00 2001 From: Alessandro Rezzi Date: Wed, 17 Apr 2024 12:30:25 +0200 Subject: [PATCH 2/3] hardware wallets are not view only --- scripts/composables/use_wallet.js | 6 +----- scripts/dashboard/Dashboard.vue | 7 ++++--- scripts/index.js | 2 +- scripts/legacy.js | 7 ++----- scripts/promos.js | 2 +- scripts/stake/Stake.vue | 1 - scripts/wallet.js | 10 ++++++++-- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/scripts/composables/use_wallet.js b/scripts/composables/use_wallet.js index d769fe98d..a239be524 100644 --- a/scripts/composables/use_wallet.js +++ b/scripts/composables/use_wallet.js @@ -86,11 +86,7 @@ export const useWallet = defineStore('wallet', () => { ); const createAndSendTransaction = async (network, address, value, opts) => { const tx = wallet.createTransaction(address, value, opts); - if (wallet.isHardwareWallet()) { - await ledgerSignTransaction(wallet, tx); - } else { - await wallet.sign(tx); - } + await wallet.sign(tx); const res = await network.sendTransaction(tx.serialize()); if (res) { await wallet.addTransaction(tx); diff --git a/scripts/dashboard/Dashboard.vue b/scripts/dashboard/Dashboard.vue index 4d51a5635..bae6869bb 100644 --- a/scripts/dashboard/Dashboard.vue +++ b/scripts/dashboard/Dashboard.vue @@ -139,7 +139,6 @@ async function encryptWallet(password, currentPassword = '') { async function restoreWallet(strReason) { if (!wallet.isEncrypted) return false; - if (wallet.isHardwareWallet) return true; showRestoreWallet.value = true; return await new Promise((res) => { watch( @@ -206,7 +205,7 @@ function lockWallet() { */ async function send(address, amount, useShieldInputs) { // Ensure a wallet is unlocked - if (wallet.isViewOnly && !wallet.isHardwareWallet) { + if (wallet.isViewOnly) { if ( !(await restoreWallet( tr(ALERTS.WALLET_UNLOCK_IMPORT, [ @@ -516,7 +515,9 @@ defineExpose({
diff --git a/scripts/index.js b/scripts/index.js index 794f6cb70..366b3551e 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -30,7 +30,7 @@ export { switchSettings, govVote, } from './global.js'; -export { wallet, getNewAddress } from './wallet.js'; +export { wallet } from './wallet.js'; export { logOut, toggleTestnet, diff --git a/scripts/legacy.js b/scripts/legacy.js index 2cb8d4e38..b3f3f1063 100644 --- a/scripts/legacy.js +++ b/scripts/legacy.js @@ -37,10 +37,7 @@ export async function createAndSendTransaction({ changeAddress, returnAddress: delegationOwnerAddress, }); - if (!wallet.isHardwareWallet()) await wallet.sign(tx); - else { - await ledgerSignTransaction(wallet, tx); - } + await wallet.sign(tx); const res = await getNetwork().sendTransaction(tx.serialize()); if (res) { await wallet.addTransaction(tx); @@ -63,7 +60,7 @@ export async function createMasternode() { // Generate the Masternode collateral const [address] = await getNewAddress({ - verify: wallet.isHardwareWallet(), + verify: true, nReceiving: 1, }); const result = await createAndSendTransaction({ diff --git a/scripts/promos.js b/scripts/promos.js index 254a663a6..4cefe56d0 100644 --- a/scripts/promos.js +++ b/scripts/promos.js @@ -469,7 +469,7 @@ export async function updatePromoCreationTick(fRecursive = false) { } // Send the fill transaction if unlocked - if (!wallet.isViewOnly() || wallet.isHardwareWallet()) { + if (!wallet.isViewOnly()) { const res = await createAndSendTransaction({ address: strAddress, amount: Math.round(cThread.amount * COIN + PROMO_FEE), diff --git a/scripts/stake/Stake.vue b/scripts/stake/Stake.vue index 85cc4c72c..3e5f0bc5a 100644 --- a/scripts/stake/Stake.vue +++ b/scripts/stake/Stake.vue @@ -89,7 +89,6 @@ async function unstake(value) { async function restoreWallet(strReason) { if (!wallet.isEncrypted) return false; - if (wallet.isHardwareWallet) return true; showRestoreWallet.value = true; return await new Promise((res) => { watch( diff --git a/scripts/wallet.js b/scripts/wallet.js index f6e7a93bc..7c85cc497 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -16,7 +16,7 @@ import { RECEIVE_TYPES } from './contacts-book.js'; import { Account } from './accounts.js'; import { fAdvancedMode } from './settings.js'; import { bytesToHex, hexToBytes, sleep, startBatch } from './utils.js'; -import { strHardwareName } from './ledger.js'; +import { ledgerSignTransaction, strHardwareName } from './ledger.js'; import { OutpointState, Mempool } from './mempool.js'; import { getEventEmitter } from './event_bus.js'; @@ -178,7 +178,7 @@ export class Wallet { isViewOnly() { if (!this.#masterKey) return false; - return this.#masterKey.isViewOnly; + return this.#masterKey.isViewOnly && !this.isHardwareWallet(); } isHD() { @@ -922,6 +922,9 @@ export class Wallet { if (balance < value) { throw new Error('Not enough balance'); } + if (isDelegation && this.isHardwareWallet()) { + throw new Error('Ledger does not support cold staking yet'); + } if (delegateChange && !changeDelegationAddress) throw new Error( '`delegateChange` was set to true, but no `changeDelegationAddress` was provided.' @@ -1057,6 +1060,9 @@ export class Wallet { if (this.isViewOnly()) { throw new Error('Cannot sign with a view only wallet'); } + if (this.isHardwareWallet()) { + return await ledgerSignTransaction(this, transaction); + } if (!transaction.vin.length || transaction.shieldOutput[0]) { // TODO: separate signing and building process for shield? return await this.#signShield(transaction); From 012d8c72b44cf38b01b51e73cf24624ca69a2056 Mon Sep 17 00:00:00 2001 From: Alessandro Rezzi Date: Wed, 17 Apr 2024 17:04:09 +0200 Subject: [PATCH 3/3] remove unused import --- scripts/legacy.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/legacy.js b/scripts/legacy.js index b3f3f1063..f2f5ed402 100644 --- a/scripts/legacy.js +++ b/scripts/legacy.js @@ -12,7 +12,6 @@ import { } from './misc.js'; import { Database } from './database.js'; import { getNetwork } from './network.js'; -import { ledgerSignTransaction } from './ledger.js'; /** * @deprecated use the new wallet method instead