From 845c885aad324478a1bf3e10eac6f41460ce8b37 Mon Sep 17 00:00:00 2001 From: csrapr <26280794+csrapr@users.noreply.github.com> Date: Thu, 25 Mar 2021 18:47:11 +0000 Subject: [PATCH] Feat: newAddress route --- .../wallet/pazuz-wallet/pazuz-wallet.js | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js b/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js index 28197355..dcc1a4b3 100644 --- a/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js +++ b/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js @@ -21,45 +21,53 @@ function checkCryptoCode (cryptoCode) { } function balance (account, cryptoCode, settings, operatorId) { - return checkCryptoCode(cryptoCode).then(() => { - return axios.post('/balance', { - account, - cryptoCode, - settings, - operatorId - }).then(({ data }) => { + return checkCryptoCode(cryptoCode) + .then(() => { + return axios.post('/balance', { + account, + cryptoCode, + settings, + operatorId + }) + }) + .then(({ data }) => { if (data.error) throw new Error(JSON.stringify({ errorCode: data.error.errorCode, message: data.error.message })) return BN(data.balance) }) - }) } function sendCoins (account, tx, settings, operatorId) { const { cryptoCode } = tx - return checkCryptoCode(cryptoCode).then(() => { - return axios.post('/sendCoins', { - account, - tx, - settings, - operatorId - }).then(({ data }) => { + return checkCryptoCode(cryptoCode) + .then(() => { + return axios.post('/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 })) const fee = BN(data.fee).round() const txid = data.txid return { txid, fee } }) - }) } function newAddress (account, info, tx, settings, operatorId) { - return axios.post('/newAddress', { - account, - info, - tx, - settings, - operatorId - }).catch(console.error) + return checkCryptoCode(info.cryptoCode) + .then(() => axios.post('/newAddress', { + account, + info, + tx, + settings, + operatorId + })) + .then(({ data }) => { + return data.newAddress + }) } function newFunding (account, cryptoCode, settings, operatorId) {