From da7cfd02b0789117e2d7e9225e8224ff55787f90 Mon Sep 17 00:00:00 2001 From: csrapr <26280794+csrapr@users.noreply.github.com> Date: Thu, 25 Mar 2021 21:48:52 +0000 Subject: [PATCH] Feat: getStatus pazuz wallet --- .../wallet/pazuz-wallet/pazuz-wallet.js | 68 ++++++------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js b/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js index dcc1a4b3..bc694ce3 100644 --- a/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js +++ b/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js @@ -31,7 +31,7 @@ function balance (account, cryptoCode, settings, operatorId) { }) }) .then(({ data }) => { - if (data.error) throw new Error(JSON.stringify({ errorCode: data.error.errorCode, message: data.error.message })) + if (data.error) throw new Error(JSON.stringify(data.error)) return BN(data.balance) }) } @@ -49,7 +49,7 @@ function sendCoins (account, tx, settings, operatorId) { }) .then(({ data }) => { if (data.error && data.error.errorCode === 'sc-001') throw new E.InsufficientFundsError() - else if (data.error) throw new Error(JSON.stringify({ errorCode: data.error.errorCode, message: data.error.message })) + else if (data.error) throw new Error(JSON.stringify(data.error)) const fee = BN(data.fee).round() const txid = data.txid return { txid, fee } @@ -70,57 +70,30 @@ function newAddress (account, info, tx, settings, operatorId) { }) } -function newFunding (account, cryptoCode, settings, operatorId) { - return axios.post('/newFunding', { - account, - cryptoCode, - settings, - operatorId - }).catch(console.error) -} - function getStatus (account, tx, requested, settings, operatorId) { - return axios.post('/getStatus', { - account, - tx, - requested, - settings, - operatorId - }).catch(console.error) -} - -function sweep (account, cryptoCode, hdIndex, settings, operatorId) { - return axios.post('/sweep', { - account, - cryptoCode, - hdIndex, - settings, - operatorId - }).catch(console.error) -} - -function cryptoNetwork (account, cryptoCode, settings, operatorId) { - return checkCryptoCode(cryptoCode) - .then(() => axios.post('/cryptoNetwork', { - account, - cryptoCode, - settings, - operatorId - })) + return checkCryptoCode(tx.cryptoCode) + .then(() => axios.get(`/balance/${tx.toAddress}?cryptoCode=${tx.cryptoCode}`)) .then(({ data }) => { - if (data.error && data.error.errorCode === 'cn-001') return false - else if (data.error) throw new Error(JSON.stringify({ error: data.error, message: data.error.message })) - return data.cryptoNetwork + if (data.error) throw new Error(JSON.stringify(data.error)) + const confirmed = BN(data.confirmedBalance) + const pending = BN(data.pendingBalance) + if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' } + if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' } + if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' } + return { receivedCryptoAtoms: pending, status: 'notSeen' } }) } +function newFunding (account, cryptoCode, settings, operatorId) { + throw new E.NotImplementedError() +} + +function sweep (account, cryptoCode, hdIndex, settings, operatorId) { + throw new E.NotImplementedError() +} + function isStrictAddress (cryptoCode, toAddress, settings, operatorId) { - return axios.post('/isStrictAddress', { - cryptoCode, - toAddress, - settings, - operatorId - }).catch(console.error) + throw new E.NotImplementedError() } module.exports = { @@ -131,6 +104,5 @@ module.exports = { getStatus, sweep, supportsHd: true, - cryptoNetwork, isStrictAddress }