-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Layout): select drop down balances
- Loading branch information
Philip London
committed
Feb 4, 2020
1 parent
85623d8
commit e55990a
Showing
3 changed files
with
84 additions
and
61 deletions.
There are no files selected for viewing
90 changes: 40 additions & 50 deletions
90
...ages/blockchain-wallet-v4-frontend/src/components/Form/SelectBoxXlmAddresses/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,47 @@ | ||
import { concat, curry, filter, has, map, reduce, sequence } from 'ramda' | ||
import { createDeepEqualSelector } from 'services/ReselectHelper' | ||
import { Exchange, Remote } from 'blockchain-wallet-v4/src' | ||
import { selectors } from 'data' | ||
|
||
export const getData = createDeepEqualSelector( | ||
[ | ||
selectors.core.common.xlm.getAccountBalances, | ||
selectors.core.common.xlm.getLockboxXlmBalances, | ||
selectors.components.send.getPaymentsAccountExchange('XLM'), | ||
(state, { includeExchangeAddress }) => includeExchangeAddress, | ||
(state, { exclude }) => exclude, | ||
(state, { excludeLockbox }) => excludeLockbox | ||
], | ||
( | ||
walletBalances, | ||
lockboxBalances, | ||
exchangeAddress, | ||
includeExchangeAddress, | ||
exclude = [], | ||
excludeLockbox | ||
) => { | ||
const buildDisplay = wallet => { | ||
if (has('balance', wallet)) { | ||
let xlmDisplay = Exchange.displayXlmToXlm({ | ||
value: wallet.balance, | ||
fromUnit: 'STROOP', | ||
toUnit: 'XLM' | ||
}) | ||
return wallet.label + ` (${xlmDisplay})` | ||
} | ||
return wallet.label | ||
export const getData = (state, ownProps) => { | ||
const { exclude = [], excludeLockbox, includeExchangeAddress } = ownProps | ||
|
||
const buildDisplay = wallet => { | ||
if (has('balance', wallet)) { | ||
let xlmDisplay = Exchange.displayXlmToXlm({ | ||
value: wallet.balance, | ||
fromUnit: 'STROOP', | ||
toUnit: 'XLM' | ||
}) | ||
return wallet.label + ` (${xlmDisplay})` | ||
} | ||
const excluded = filter(x => !exclude.includes(x.label)) | ||
const toDropdown = map(x => ({ label: buildDisplay(x), value: x })) | ||
const toGroup = curry((label, options) => [{ label, options }]) | ||
const toExchange = x => [{ label: `Exchange XLM Address`, value: x }] | ||
return wallet.label | ||
} | ||
const excluded = filter(x => !exclude.includes(x.label)) | ||
const toDropdown = map(x => ({ label: buildDisplay(x), value: x })) | ||
const toGroup = curry((label, options) => [{ label, options }]) | ||
const toExchange = x => [{ label: `Exchange XLM Address`, value: x }] | ||
|
||
const hasExchangeAddress = Remote.Success.is(exchangeAddress) | ||
const exchangeAddress = selectors.components.send.getPaymentsAccountExchange( | ||
'XLM', | ||
state | ||
) | ||
const hasExchangeAddress = Remote.Success.is(exchangeAddress) | ||
|
||
return sequence(Remote.of, [ | ||
walletBalances | ||
.map(excluded) | ||
.map(toDropdown) | ||
.map(toGroup('Wallet')), | ||
excludeLockbox | ||
? Remote.of([]) | ||
: lockboxBalances | ||
.map(excluded) | ||
.map(toDropdown) | ||
.map(toGroup('Lockbox')), | ||
includeExchangeAddress && hasExchangeAddress | ||
? exchangeAddress.map(toExchange).map(toGroup('Exchange')) | ||
: Remote.of([]) | ||
]).map(([b1, b2, b3]) => ({ data: reduce(concat, [], [b1, b2, b3]) })) | ||
} | ||
) | ||
return sequence(Remote.of, [ | ||
selectors.core.common.xlm | ||
.getAccountBalances(state) | ||
.map(excluded) | ||
.map(toDropdown) | ||
.map(toGroup('Wallet')), | ||
excludeLockbox | ||
? Remote.of([]) | ||
: selectors.core.common.xlm | ||
.getLockboxXlmBalances(state) | ||
.map(excluded) | ||
.map(toDropdown) | ||
.map(toGroup('Lockbox')), | ||
includeExchangeAddress && hasExchangeAddress | ||
? exchangeAddress.map(toExchange).map(toGroup('Exchange')) | ||
: Remote.of([]) | ||
]).map(([b1, b2, b3]) => ({ data: reduce(concat, [], [b1, b2, b3]) })) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 26 additions & 5 deletions
31
.../blockchain-wallet-v4-frontend/src/scenes/Transactions/WalletBalanceDropdown/selectors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters