fetch tokens from relay api: fix tests, token model and other minor stuff
This commit is contained in:
parent
d930db5ace
commit
d4c6fda203
|
@ -0,0 +1 @@
|
|||
REACT_APP_RELAY_API_URL=https://safe-relay.dev.gnosisdev.com/api/v1
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,7 @@
|
|||
// @flow
|
||||
/* eslint-disable */
|
||||
import 'babel-polyfill'
|
||||
require('dotenv').config()
|
||||
|
||||
import { MuiThemeProvider } from '@material-ui/core/styles'
|
||||
import React from 'react'
|
||||
|
@ -13,6 +15,7 @@ import AppRoutes from '~/routes'
|
|||
|
||||
import './index.scss'
|
||||
|
||||
|
||||
const Root = () => (
|
||||
<Provider store={store}>
|
||||
<MuiThemeProvider theme={theme}>
|
||||
|
|
|
@ -112,7 +112,7 @@ class Tokens extends React.Component<Props, State> {
|
|||
{filteredTokens.map((token: Token) => (
|
||||
<ListItem key={token.get('address')} className={classes.token}>
|
||||
<ListItemIcon>
|
||||
<Img src={token.get('logoUrl')} height={28} alt={token.get('name')} />
|
||||
<Img src={token.get('logoUri')} height={28} alt={token.get('name')} />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={token.get('symbol')} secondary={token.get('name')} />
|
||||
<ListItemSecondaryAction>
|
||||
|
|
|
@ -72,7 +72,7 @@ const BalanceComponent = openHoc(({
|
|||
return (
|
||||
<ListItem key={symbol} className={classNames(classes.nested, symbol)}>
|
||||
<ListItemIcon>
|
||||
<Img src={token.get('logoUrl')} height={30} alt={name} />
|
||||
<Img src={token.get('logoUri')} height={30} alt={name} />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={name} secondary={`${token.get('funds')} ${symbol}`} />
|
||||
<Button variant="contained" color="primary" onClick={onMoveFundsClick} disabled={disabled}>
|
||||
|
|
|
@ -39,7 +39,7 @@ export const addTokenFnc = async (values: Object, addToken: typeof addTokenActio
|
|||
name,
|
||||
symbol,
|
||||
decimals: Number(decimals),
|
||||
logoUrl: logo,
|
||||
logoUri: logo,
|
||||
status: true,
|
||||
removable: true,
|
||||
})
|
||||
|
|
|
@ -58,6 +58,7 @@ class TokenComponent extends React.PureComponent<Props, State> {
|
|||
|
||||
render() {
|
||||
const { classes, token } = this.props
|
||||
const { checked } = this.state
|
||||
const name = token.get('name')
|
||||
const symbol = token.get('symbol')
|
||||
const disabled = isEther(symbol)
|
||||
|
@ -70,7 +71,7 @@ class TokenComponent extends React.PureComponent<Props, State> {
|
|||
<Typography variant="subheading" color="textSecondary">
|
||||
<Checkbox
|
||||
disabled={disabled}
|
||||
checked={!!this.state.checked}
|
||||
checked={!!checked}
|
||||
onChange={this.handleChange}
|
||||
color="primary"
|
||||
/>
|
||||
|
@ -85,7 +86,7 @@ class TokenComponent extends React.PureComponent<Props, State> {
|
|||
</Block>
|
||||
<CardMedia
|
||||
className={classes.cover}
|
||||
image={token.get('logoUrl')}
|
||||
image={token.get('logoUri')}
|
||||
title={name}
|
||||
/>
|
||||
</Card>
|
||||
|
|
|
@ -42,7 +42,7 @@ export const calculateBalanceOf = async (tokenAddress: string, address: string,
|
|||
}
|
||||
|
||||
export const fetchTokensData = async () => {
|
||||
const url = 'https://gist.githubusercontent.com/rmeissner/98911fcf74b0ea9731e2dae2441c97a4/raw/'
|
||||
const url = `${process.env.REACT_APP_RELAY_API_URL}/tokens`
|
||||
const errMsg = 'Error querying safe balances'
|
||||
return enhancedFetch(url, errMsg)
|
||||
}
|
||||
|
@ -51,11 +51,11 @@ export const fetchTokens = (safeAddress: string) => async (dispatch: ReduxDispat
|
|||
const tokens: List<string> = getActiveTokenAddresses(safeAddress)
|
||||
const ethBalance = await getSafeEthToken(safeAddress)
|
||||
const customTokens = getTokens(safeAddress)
|
||||
const json = await fetchTokensData()
|
||||
const { results } = await fetchTokensData()
|
||||
|
||||
try {
|
||||
const balancesRecords = await Promise.all(
|
||||
json.map(async (item: TokenProps) => {
|
||||
results.map(async (item: TokenProps) => {
|
||||
const status = tokens.includes(item.address)
|
||||
const funds = status ? await calculateBalanceOf(item.address, safeAddress, item.decimals) : '0'
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ export type TokenProps = {
|
|||
name: string,
|
||||
symbol: string,
|
||||
decimals: number,
|
||||
logoUrl: string,
|
||||
logoUri: string,
|
||||
funds: string,
|
||||
status: boolean,
|
||||
removable: boolean,
|
||||
|
@ -18,7 +18,7 @@ export const makeToken: RecordFactory<TokenProps> = Record({
|
|||
name: '',
|
||||
symbol: '',
|
||||
decimals: 0,
|
||||
logoUrl: '',
|
||||
logoUri: '',
|
||||
funds: '0',
|
||||
status: true,
|
||||
removable: false,
|
||||
|
|
|
@ -36,7 +36,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
|
|||
name: 'First Token Example',
|
||||
symbol: 'FTE',
|
||||
decimals: 18,
|
||||
logoUrl: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
},
|
||||
]))
|
||||
})
|
||||
|
|
|
@ -37,14 +37,14 @@ describe('DOM > Feature > Enable and disable default tokens', () => {
|
|||
name: 'First Token Example',
|
||||
symbol: 'FTE',
|
||||
decimals: 18,
|
||||
logoUrl: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
},
|
||||
{
|
||||
address: secondErc20Token.address,
|
||||
name: 'Second Token Example',
|
||||
symbol: 'STE',
|
||||
decimals: 18,
|
||||
logoUrl: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
},
|
||||
]))
|
||||
})
|
||||
|
|
|
@ -36,7 +36,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
|
|||
name: 'First Token Example',
|
||||
symbol: 'FTE',
|
||||
decimals: 18,
|
||||
logoUrl: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
},
|
||||
]))
|
||||
})
|
||||
|
|
|
@ -36,7 +36,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
|
|||
name: 'First Token Example',
|
||||
symbol: 'FTE',
|
||||
decimals: 18,
|
||||
logoUrl: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
},
|
||||
]))
|
||||
})
|
||||
|
|
|
@ -39,7 +39,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
|
|||
name: 'First Token Example',
|
||||
symbol: 'FTE',
|
||||
decimals: 18,
|
||||
logoUrl: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
logoUri: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
},
|
||||
]))
|
||||
})
|
||||
|
@ -78,7 +78,7 @@ describe('DOM > Feature > Add new ERC 20 Tokens', () => {
|
|||
name: 'Custom ERC20 Token',
|
||||
symbol: 'CTS',
|
||||
decimals: 10,
|
||||
logoUrl: 'https://example.com',
|
||||
logoUri: 'https://example.com',
|
||||
status: true,
|
||||
removable: true,
|
||||
})
|
||||
|
|
|
@ -51,7 +51,7 @@ export const dispatchTknBalance = async (store: Store, tokenAddress: string, add
|
|||
name: 'Token',
|
||||
symbol: 'TKN',
|
||||
decimals: 18,
|
||||
logoUrl: 'https://github.com/TrustWallet/tokens/blob/master/images/0x6810e776880c02933d47db1b9fc05908e5386b96.png?raw=true',
|
||||
logoUri: 'https://github.com/TrustWallet/tokens/blob/master/images/0x6810e776880c02933d47db1b9fc05908e5386b96.png?raw=true',
|
||||
funds,
|
||||
}))
|
||||
fetchBalancesMock.mockImplementation(() => store.dispatch(addTokens(address, balances)))
|
||||
|
|
|
@ -15,7 +15,7 @@ export const getSafeEthToken = async (safeAddress: string) => {
|
|||
name: 'Ether',
|
||||
symbol: 'ETH',
|
||||
decimals: 18,
|
||||
logoUrl: logo,
|
||||
logoUri: logo,
|
||||
funds: balance,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue