Skip to content

Commit

Permalink
feat(dynamic erc20): load all erc20 rates on login
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Jul 15, 2021
1 parent ed17312 commit 7077346
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FiatDisplayContainer extends React.PureComponent<Props> {
return
}
if (coinfig.type.erc20Address) {
return this.props.ethActions.fetchErc20Rates(this.props.coin)
return
}
return this.props[`${toLower(coin)}Actions`].fetchRates()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ export const SUPPORTED_COINS: Array<CoinType | string> = [
'BTC',
'ETH',
'BCH',
'AAVE',
'YFI',
'DOT',
'XLM',
'PAX',
'USDT',
'WDGLD',
'ALGO',
'ALGO'
]

// used in the coin/account selector in Swap
export const SWAP_ACCOUNTS_SELECTOR: CoinAccountSelectorType = {
coins: SUPPORTED_COINS,
nonCustodialAccounts: true,
tradingAccounts: true,
tradingAccounts: true
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ export default () => {
yield put(actions.core.data.xlm.fetchRates())
yield put(actions.core.data.dot.fetchRates())
yield put(actions.core.data.algo.fetchRates())
yield put(actions.core.data.eth.fetchErc20Rates('pax'))
yield put(actions.core.data.eth.fetchErc20Rates('usdt'))
yield put(actions.core.data.eth.fetchErc20Rates('wdgld'))
yield put(actions.core.data.eth.fetchErc20Rates('aave'))
yield put(actions.core.data.eth.fetchErc20Rates('yfi'))
yield put(actions.core.data.eth.fetchErc20Rates())
}

const refreshClicked = function* () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const IconBackground = styled.div`
background: white;
`
const StyledIcon = styled(Icon)<{ background: string }>`
background: rgba(${(props) => hexToRgb(props.theme[props.background])}, 0.15);
background: rgba(${(props) => hexToRgb(props.theme[props.background] || '#000000')}, 0.15);
border-radius: 50%;
& :not(::before) {
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-wallet-v4-frontend/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const configuredStore = async function () {
const erc20Res = await fetch(`${options.domains.api}/assets/currencies/erc20`)
const erc20s = await erc20Res.json()
// TODO: erc20 phase 2, remove this whitelist
const coins = ['AAVE', 'PAX', 'USDT', 'WDGLD', 'YFI']
const coins = ['AAVE', 'PAX', 'USDC', 'USDT', 'WDGLD', 'YFI']
const erc20sSupportedBeforeDynamicChange = erc20s.currencies.filter((erc20) =>
coins.includes(erc20.symbol)
)
Expand Down
3 changes: 1 addition & 2 deletions packages/blockchain-wallet-v4/src/redux/data/eth/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ export const fetchErc20DataFailure = (token, error) => ({
})

// RATES
export const fetchErc20Rates = (token) => ({
payload: { token },
export const fetchErc20Rates = () => ({
type: AT.FETCH_ERC20_RATES
})
export const fetchErc20RatesLoading = (token) => ({
Expand Down
24 changes: 14 additions & 10 deletions packages/blockchain-wallet-v4/src/redux/data/eth/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export default ({ api }: { api: APIType }) => {
// TODO: erc20 phase 2, key off hash not symbol
const symbol = toUpper(val.tokenSymbol)
yield put(A.fetchErc20DataLoading(symbol))
yield put(A.fetchErc20Rates(symbol))
const contract = val.tokenHash
const tokenData = data.tokenAccounts.find(
({ tokenHash }) => toLower(tokenHash) === toLower(contract as string)
Expand All @@ -260,15 +259,20 @@ export default ({ api }: { api: APIType }) => {
}
}

const fetchErc20Rates = function* (action) {
const { token } = action.payload
try {
yield put(A.fetchErc20RatesLoading(token))
const data = yield call(api.getErc20Ticker, toUpper(token))
yield put(A.fetchErc20RatesSuccess(token, data))
} catch (e) {
yield put(A.fetchErc20RatesFailure(token, e.message))
}
const fetchErc20Rates = function* () {
const tokens = S.getErc20Coins()

yield all(
tokens.map(function* (token) {
try {
yield put(A.fetchErc20RatesLoading(token))
const data = yield call(api.getErc20Ticker, toUpper(token))
yield put(A.fetchErc20RatesSuccess(token, data))
} catch (e) {
yield put(A.fetchErc20RatesFailure(token, e.message))
}
})
)
}

const watchErc20Transactions = function* () {
Expand Down
3 changes: 3 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/data/eth/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export const getErc20Balance = (state, token) => {
export const getErc20CurrentBalance = (state, token) => {
return path([dataPath, 'eth', 'current_balance', token])(state) || Remote.NotAsked
}
export const getErc20Coins = () => {
return Object.keys(window.coins).filter((coin) => window.coins[coin].coinfig.type.erc20Address)
}
export const getErc20Transactions = (state, token) => {
return path([dataPath, 'eth', 'transactions', token])(state) || Remote.NotAsked
}
Expand Down

0 comments on commit 7077346

Please sign in to comment.