From ecc0031b828f1887a82f5e33f4afa7d68dd32123 Mon Sep 17 00:00:00 2001 From: joemarct Date: Mon, 26 Aug 2024 00:21:58 +0800 Subject: [PATCH] Fixed sweep failure when wallet is used as fee funder --- package-lock.json | 14 +++++++------- package.json | 2 +- src/pages/apps/sweep.vue | 38 ++++++++++++++++++++------------------ src/wallet/sweep.js | 4 ++-- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 54338b28e..77803e28d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -92,7 +92,7 @@ "vuex": "^4.0.2", "vuex-persist": "^3.1.3", "vuex-persistedstate": "^4.0.0-beta.2", - "watchtower-cash-js": "^0.1.49" + "watchtower-cash-js": "^0.2.1" }, "devDependencies": { "@babel/eslint-parser": "^7.0.0", @@ -24271,9 +24271,9 @@ } }, "node_modules/watchtower-cash-js": { - "version": "0.1.50", - "resolved": "https://registry.npmjs.org/watchtower-cash-js/-/watchtower-cash-js-0.1.50.tgz", - "integrity": "sha512-SmsEDO1pGQFg68EXNY0bg5v3yQplv+gLEjpI0I7YPK40WVgCJZuUa3kKjg+adMiuv95ZXZxi3V1NSk3pQlNjJg==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/watchtower-cash-js/-/watchtower-cash-js-0.2.1.tgz", + "integrity": "sha512-O7Ug3jCzJ77f6EVzwwCNdsM9e1WDUpvA1cRN22EBMNcntjHfsuHnYyd3Jf6tMyVYvNJcSlDcSHIXytSt+4oVaA==", "dependencies": { "@bitauth/libauth": "^2.0.0-alpha.8", "@psf/bch-js": "^6.3.4", @@ -43377,9 +43377,9 @@ } }, "watchtower-cash-js": { - "version": "0.1.50", - "resolved": "https://registry.npmjs.org/watchtower-cash-js/-/watchtower-cash-js-0.1.50.tgz", - "integrity": "sha512-SmsEDO1pGQFg68EXNY0bg5v3yQplv+gLEjpI0I7YPK40WVgCJZuUa3kKjg+adMiuv95ZXZxi3V1NSk3pQlNjJg==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/watchtower-cash-js/-/watchtower-cash-js-0.2.1.tgz", + "integrity": "sha512-O7Ug3jCzJ77f6EVzwwCNdsM9e1WDUpvA1cRN22EBMNcntjHfsuHnYyd3Jf6tMyVYvNJcSlDcSHIXytSt+4oVaA==", "requires": { "@bitauth/libauth": "^2.0.0-alpha.8", "@psf/bch-js": "^6.3.4", diff --git a/package.json b/package.json index cb0ad2c90..d5b12e015 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "vuex": "^4.0.2", "vuex-persist": "^3.1.3", "vuex-persistedstate": "^4.0.0-beta.2", - "watchtower-cash-js": "^0.1.49" + "watchtower-cash-js": "^0.2.1" }, "overrides": { "@generalprotocols/anyhedge-old": { diff --git a/src/pages/apps/sweep.vue b/src/pages/apps/sweep.vue index c1f154de1..5549d751e 100644 --- a/src/pages/apps/sweep.vue +++ b/src/pages/apps/sweep.vue @@ -85,7 +85,7 @@ :class="getDarkModeClass(darkMode)" :disabled="(totalTokensCount - skippedTokens.length) > 0" /> - + {{ $t(isHongKong(currentCountry) ? 'SweepThePointsFirst' : 'SweepTheTokensFirst') }}
@@ -348,22 +348,6 @@ export default { emptyAssets() { const DUST = 546 / 10 ** 8 return this.bchBalance < DUST && this.totalTokensCount == 0 - }, - feeFunder () { - let funder - if (this.payFeeFrom.value === 'address') { - funder = { - address: this.sweeper.bchAddress, - wif: this.wif - } - } else if (this.payFeeFrom.value === 'wallet') { - funder = { - walletHash: this.wallet.BCH.walletHash, - mnemonic: this.wallet.mnemonic, - derivationPath: this.wallet.BCH.derivationPath - } - } - return funder } }, methods: { @@ -397,6 +381,22 @@ export default { validatePrivateKey (value) { return /^[5KL][1-9A-HJ-NP-Za-km-z]{50,51}$/.test(String(value)) }, + getFeeFunder () { + let funder + if (this.payFeeFrom.value === 'address') { + funder = { + address: this.sweeper.bchAddress, + wif: this.wif + } + } else if (this.payFeeFrom.value === 'wallet') { + funder = { + walletHash: this.wallet.BCH.walletHash, + mnemonic: this.wallet.mnemonic, + derivationPath: this.wallet.BCH.derivationPath + } + } + return funder + }, async getTokens (signalFetch) { if (!this.validatePrivateKey(this.wif)) { this.error = this.$t('InvalidPrivateKey') @@ -436,7 +436,7 @@ export default { vm.wif, token.token_id, token.spendable, - vm.feeFunder, + vm.getFeeFunder(), vm.$store.getters['global/getAddress']('slp') ).then(function (result) { if (!result.success) { @@ -462,6 +462,7 @@ export default { tokenId: token?.category, }, tokenAmount: token.balance, + feeFunder: this.getFeeFunder(), recipient: tokenAddress, }).then(result => { if (!result.success) { @@ -494,6 +495,7 @@ export default { txid: token?.currentTxid, vout: token?.currentIndex, }, + feeFunder: this.getFeeFunder(), recipient: tokenAddress, }).then(result => { if (!result.success) { diff --git a/src/wallet/sweep.js b/src/wallet/sweep.js index c4f7a3481..9360a71cd 100644 --- a/src/wallet/sweep.js +++ b/src/wallet/sweep.js @@ -145,7 +145,7 @@ export class SweepPrivateKey { * @param {Number} param0.tokenAmount * @param {String} param0.recipient */ - sweepCashToken({ tokenAddress, bchWif, token, tokenAmount, recipient }) { + sweepCashToken({ tokenAddress, bchWif, token, tokenAmount, feeFunder, recipient }) { const watchtower = new Watchtower() const data = { sender: { address: tokenAddress, wif: bchWif }, @@ -153,9 +153,9 @@ export class SweepPrivateKey { { address: recipient, tokenAmount: tokenAmount }, ], token, + feeFunder: feeFunder, broadcast: true, } - return watchtower.BCH.send(data) }