Skip to content

Commit

Permalink
feat(BSV): begin adding bsv to swap
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Jan 3, 2019
1 parent 0121487 commit 76d89f4
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/mocks/wallet-options-v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
"exchange": true
}
},
"bsv": {
"availability": {
"send": true,
"request": false,
"lockbox": false,
"exchange": true
}
},
"eth": {
"availability": {
"send": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const CREATE_ACCOUNT_ERROR = 'Not enough funds to create new account'
export const NO_ACCOUNT_ERROR = 'Account does not exist'
export const RESERVE_ERROR = 'Reserve exceeds remaining funds'

const currenciesOrder = ['BTC', 'ETH', 'BCH', 'XLM']
const currenciesOrder = ['BTC', 'ETH', 'BCH', 'XLM', 'BSV']
export const sortByOrder = sortBy(flip(indexOf)(currenciesOrder))

const getPairedCoins = curry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default ({ coreSagas, networks }) => {

const btcOptions = [settings.NETWORK_BTC, PROVISIONAL_BTC_SCRIPT]
const bchOptions = [settings.NETWORK_BCH, PROVISIONAL_BCH_SCRIPT]
const bsvOptions = [settings.NETWORK_BCH, PROVISIONAL_BCH_SCRIPT]
const ethOptions = [settings.NETWORK_ETH, null]
const xlmOptions = [null, null]
const calculateProvisionalPayment = function*(source, amount) {
Expand All @@ -46,6 +47,7 @@ export default ({ coreSagas, networks }) => {
const [network, provisionalScript] = prop(coin, {
BTC: btcOptions,
BCH: bchOptions,
BSV: bsvOptions,
ETH: ethOptions,
XLM: xlmOptions
})
Expand Down Expand Up @@ -99,6 +101,15 @@ export default ({ coreSagas, networks }) => {
.from(addressOrIndex, addressType)
.done()
break
case 'BSV':
payment = yield coreSagas.payment.bsv
.create({ network: settings.NETWORK_BCH })
.chain()
.init()
.fee('priority')
.from(addressOrIndex, addressType)
.done()
break
case 'BTC':
payment = yield coreSagas.payment.btc
.create({ network: networks.btc })
Expand Down Expand Up @@ -156,6 +167,14 @@ export default ({ coreSagas, networks }) => {
.fee('priority')
.amount(parseInt(amount))
break
case 'BSV':
payment = coreSagas.payment.bsv
.create({ network: settings.NETWORK_BCH })
.chain()
.init()
.fee('priority')
.amount(parseInt(amount))
break
case 'BTC':
payment = coreSagas.payment.btc
.create({ network: networks.btc })
Expand Down Expand Up @@ -208,6 +227,11 @@ export default ({ coreSagas, networks }) => {
return head(bchAccounts.getOrFail('Could not get BCH HD accounts.'))
}

const getDefaultBsvAccountValue = function*() {
const bsvAccounts = yield select(S.getActiveBsvAccounts)
return head(bsvAccounts.getOrFail('Could not get BSV HD accounts.'))
}

const getDefaultBtcAccountValue = function*() {
const btcAccounts = yield select(S.getActiveBtcAccounts)
return head(btcAccounts.getOrFail('Could not get BTC HD accounts.'))
Expand All @@ -227,6 +251,8 @@ export default ({ coreSagas, networks }) => {
switch (coin) {
case 'BCH':
return yield call(getDefaultBchAccountValue)
case 'BSV':
return yield call(getDefaultBsvAccountValue)
case 'BTC':
return yield call(getDefaultBtcAccountValue)
case 'ETH':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,35 @@ export const getActiveBchAccounts = createDeepEqualSelector(
}
)

export const getActiveBsvAccounts = createDeepEqualSelector(
[
coreSelectors.wallet.getHDAccounts,
coreSelectors.data.bsv.getAddresses,
coreSelectors.kvStore.bsv.getAccounts
],
(bsvAccounts, bsvDataR, bsvMetadataR) => {
const transform = (bsvData, bsvMetadata) =>
bsvAccounts
.map(acc => {
const index = prop('index', acc)
const xpub = prop('xpub', acc)
const data = prop(xpub, bsvData)
const metadata = bsvMetadata[index]

return {
archived: prop('archived', metadata),
coin: 'BSV',
label: prop('label', metadata) || xpub,
address: index,
balance: prop('final_balance', data),
type: ADDRESS_TYPES.ACCOUNT
}
})
.filter(isActive)
return lift(transform)(bsvDataR, bsvMetadataR)
}
)

export const getActiveBtcAccounts = createDeepEqualSelector(
[
coreSelectors.wallet.getHDAccounts,
Expand Down Expand Up @@ -184,6 +213,7 @@ export const getActiveXlmAccounts = createDeepEqualSelector(
export const getActiveAccounts = state => ({
BTC: getActiveBtcAccounts(state).getOrElse([]),
BCH: getActiveBchAccounts(state).getOrElse([]),
BSV: getActiveBsvAccounts(state).getOrElse([]),
ETH: getActiveEthAccounts(state).getOrElse([]),
XLM: getActiveXlmAccounts(state).getOrElse([])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const convertBaseToStandard = (coin, value) => {
case 'BCH':
return Exchange.convertBchToBch({ value, fromUnit: 'SAT', toUnit: 'BCH' })
.value
case 'BSV':
return Exchange.convertBsvToBsv({ value, fromUnit: 'SAT', toUnit: 'BCH' })
.value
case 'BTC':
return Exchange.convertBitcoinToBitcoin({
value,
Expand Down Expand Up @@ -50,6 +53,9 @@ export const convertStandardToBase = (coin, value) => {
case 'BCH':
return Exchange.convertBchToBch({ value, fromUnit: 'BCH', toUnit: 'SAT' })
.value
case 'BSV':
return Exchange.convertBsvToBsv({ value, fromUnit: 'BCH', toUnit: 'SAT' })
.value
case 'BTC':
return Exchange.convertBitcoinToBitcoin({
value,
Expand Down Expand Up @@ -116,6 +122,8 @@ export const selectFee = (coin, payment) => {
switch (coin) {
case 'BCH':
return path(['selection', 'fee'], payment)
case 'BSV':
return path(['selection', 'fee'], payment)
case 'BTC':
return path(['selection', 'fee'], payment)
case 'ETH':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const { formatPair } = model.rates
const getCoinFullName = flip(prop)({
BTC: 'Bitcoin',
BCH: 'Bitcoin Cash',
BSV: 'Bitcoin SV',
ETH: 'Ether',
XLM: 'Stellar'
})
Expand Down

0 comments on commit 76d89f4

Please sign in to comment.