Skip to content

Commit

Permalink
Fixed sweep failure when wallet is used as fee funder
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarct committed Aug 25, 2024
1 parent 2ac490a commit ecc0031
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
38 changes: 20 additions & 18 deletions src/pages/apps/sweep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
:class="getDarkModeClass(darkMode)"
:disabled="(totalTokensCount - skippedTokens.length) > 0"
/>
<span v-if="(totalTokensCount - skippedTokens.length) > 0" class="text-red">
<span v-if="(totalTokensCount - skippedTokens.length) > 0" class="text-red" style="margin-left: 10px;">
<i>{{ $t(isHongKong(currentCountry) ? 'SweepThePointsFirst' : 'SweepTheTokensFirst') }}</i>
</span>
<div v-if="sweeping && selectedToken === 'bch'">
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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) {
Expand All @@ -462,6 +462,7 @@ export default {
tokenId: token?.category,
},
tokenAmount: token.balance,
feeFunder: this.getFeeFunder(),
recipient: tokenAddress,
}).then(result => {
if (!result.success) {
Expand Down Expand Up @@ -494,6 +495,7 @@ export default {
txid: token?.currentTxid,
vout: token?.currentIndex,
},
feeFunder: this.getFeeFunder(),
recipient: tokenAddress,
}).then(result => {
if (!result.success) {
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/sweep.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,17 @@ 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 },
recipients: [
{ address: recipient, tokenAmount: tokenAmount },
],
token,
feeFunder: feeFunder,
broadcast: true,
}

return watchtower.BCH.send(data)
}

Expand Down

0 comments on commit ecc0031

Please sign in to comment.