Skip to content

Commit

Permalink
Ledger queue (#527)
Browse files Browse the repository at this point in the history
* Ledger refactor

* Remove unused params

* Add queue
  • Loading branch information
Duddino authored Feb 20, 2025
1 parent 77ed216 commit ec6fdbd
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 229 deletions.
24 changes: 20 additions & 4 deletions scripts/composables/use_wallet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { getEventEmitter } from '../event_bus.js';
import { hasEncryptedWallet, wallet } from '../wallet.js';
import {
hasEncryptedWallet,
wallet,
getNewAddress as guiGetNewAddress,
} from '../wallet.js';
import { ref, computed } from 'vue';
import { fPublicMode, strCurrency, togglePublicMode } from '../settings.js';
import { cOracle } from '../prices.js';
import { ledgerSignTransaction } from '../ledger.js';
import { LedgerController } from '../ledger.js';
import { defineStore } from 'pinia';
import { lockableFunction } from '../lock.js';
import { blockCount as rawBlockCount } from '../global.js';
Expand Down Expand Up @@ -85,10 +89,22 @@ export const useWallet = defineStore('wallet', () => {
});
const createAndSendTransaction = lockableFunction(
async (network, address, value, opts) => {
const tx = wallet.createTransaction(address, value, opts);
let tx;
if (wallet.isHardwareWallet()) {
await ledgerSignTransaction(wallet, tx);
const [changeAddress] = await guiGetNewAddress({
verify: true,
nReceiving: 0,
});
tx = wallet.createTransaction(address, value, {
...opts,
changeAddress,
});
await LedgerController.getInstance().signTransaction(
wallet,
tx
);
} else {
tx = wallet.createTransaction(address, value, opts);
await wallet.sign(tx);
}
const res = await network.sendTransaction(tx.serialize());
Expand Down
7 changes: 5 additions & 2 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
isStandardAddress,
} from '../misc.js';
import { getNetwork } from '../network/network_manager.js';
import { strHardwareName } from '../ledger';
import { LedgerController } from '../ledger';
import { guiAddContactPrompt } from '../contacts-book';
import { scanQRCode } from '../scanner';
import { useWallet } from '../composables/use_wallet.js';
Expand Down Expand Up @@ -116,7 +116,10 @@ async function importWallet({
createAlert(
'info',
tr(ALERTS.WALLET_HARDWARE_WALLET, [
{ hardwareWallet: strHardwareName },
{
hardwareWallet:
LedgerController.getInstance().getHardwareName(),
},
]),
12500
);
Expand Down
Loading

0 comments on commit ec6fdbd

Please sign in to comment.