Feat: newAddress route

This commit is contained in:
csrapr 2021-03-25 18:47:11 +00:00 committed by Josh Harvey
parent df37bcc519
commit 845c885aad

View file

@ -21,45 +21,53 @@ function checkCryptoCode (cryptoCode) {
}
function balance (account, cryptoCode, settings, operatorId) {
return checkCryptoCode(cryptoCode).then(() => {
return checkCryptoCode(cryptoCode)
.then(() => {
return axios.post('/balance', {
account,
cryptoCode,
settings,
operatorId
}).then(({ data }) => {
})
})
.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 checkCryptoCode(cryptoCode)
.then(() => {
return axios.post('/sendCoins', {
account,
tx,
settings,
operatorId
}).then(({ data }) => {
})
})
.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', {
return checkCryptoCode(info.cryptoCode)
.then(() => axios.post('/newAddress', {
account,
info,
tx,
settings,
operatorId
}).catch(console.error)
}))
.then(({ data }) => {
return data.newAddress
})
}
function newFunding (account, cryptoCode, settings, operatorId) {