Add layer2 address separately

This commit is contained in:
Josh Harvey 2018-06-03 12:34:26 +03:00
parent d9aaf2437f
commit d1712ce1ce
7 changed files with 85 additions and 31 deletions

View file

@ -40,12 +40,6 @@ function fetchWallet (settings, cryptoCode) {
})
}
function isLayer2 (tx) {
return _.isNil(tx.isLightning)
? layer2.isLayer2Address(tx.toAddress)
: tx.isLightning
}
const lastBalance = {}
function _balance (settings, cryptoCode) {
@ -81,10 +75,17 @@ function sendCoins (settings, toAddress, cryptoAtoms, cryptoCode) {
}
function newAddress (settings, info) {
if (isLayer2(info)) return layer2.newAddress(settings, info)
return fetchWallet(settings, info.cryptoCode)
const walletAddressPromise = fetchWallet(settings, info.cryptoCode)
.then(r => r.wallet.newAddress(r.account, info))
return Promise.all([
walletAddressPromise,
layer2.newAddress(settings, info)
])
.then(([toAddress, layer2Address]) => ({
toAddress,
layer2Address
}))
}
function newFunding (settings, cryptoCode, address) {
@ -97,11 +98,38 @@ function newFunding (settings, cryptoCode, address) {
})
}
function getWalletStatus (settings, tx) {
if (isLayer2(tx)) return layer2.getStatus(settings, tx)
function mergeStatus (a, b) {
if (!a) return b
if (!b) return a
return fetchWallet(settings, tx.cryptoCode)
return {status: mergeStatusMode(a.status, b.status)}
}
function mergeStatusMode (a, b) {
const cleared = ['authorized', 'confirmed', 'instant']
if (_.includes(a, cleared)) return a
if (_.includes(b, cleared)) return b
if (a === 'published') return a
if (b === 'published') return b
if (a === 'rejected') return a
if (b === 'rejected') return b
return 'notSeen'
}
function getWalletStatus (settings, tx) {
const walletStatusPromise = fetchWallet(settings, tx.cryptoCode)
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
return Promise.all([
walletStatusPromise,
layer2.getStatus(settings, tx)
])
.then(([walletStatus, layer2Status]) => {
return mergeStatus(walletStatus, layer2Status)
})
}
function authorizeZeroConf (settings, tx, machineId) {