From 5f47c285dcef77042361cdecd90294cd3aafb340 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Thu, 29 Mar 2018 11:35:27 +0200 Subject: [PATCH] unique tokens definitions for different networks --- src/data/{ethERC20.json => ERC20Abi.json} | 0 src/data/appConfig.json | 64 +++++++++++++------ src/data/ethereumClassicTokens.json | 14 ++++ .../{ethTokens.json => ethereumTokens.json} | 0 src/data/rinkebyTokens.json | 20 ++++++ src/data/ropstenTokens.json | 8 +++ src/js/actions/LocalStorageActions.js | 28 +++++--- src/js/actions/SummaryActions.js | 7 +- src/js/actions/Web3Actions.js | 8 +-- src/js/reducers/AccountsReducer.js | 8 +-- src/js/reducers/LocalStorageReducer.js | 14 ++-- 11 files changed, 122 insertions(+), 49 deletions(-) rename src/data/{ethERC20.json => ERC20Abi.json} (100%) create mode 100644 src/data/ethereumClassicTokens.json rename src/data/{ethTokens.json => ethereumTokens.json} (100%) create mode 100644 src/data/rinkebyTokens.json create mode 100644 src/data/ropstenTokens.json diff --git a/src/data/ethERC20.json b/src/data/ERC20Abi.json similarity index 100% rename from src/data/ethERC20.json rename to src/data/ERC20Abi.json diff --git a/src/data/appConfig.json b/src/data/appConfig.json index fafbb619..9f51e822 100644 --- a/src/data/appConfig.json +++ b/src/data/appConfig.json @@ -22,27 +22,49 @@ } ], - "eth": { - "name": "Ethereum", - "symbol": "ETH", - "network": "ethereum", - "bip44": "m/44'/60'/0'/0", - "defaultGasPrice": 64, - "defaultGasLimit": 21000, - "defaultGasLimitTokens": 200000, - "backends": [ - { - "name": "TREZOR Wallet - Ethereum", - "urls": [ - "http://88.208.115.69" - ] - } - ], - "explorer": "https://etherscan.io" - }, - "coins": [ - + { + "name": "Ethereum", + "symbol": "ETH", + "network": "ethereum", + "bip44": "m/44'/60'/0'/0", + "defaultGasPrice": 64, + "defaultGasLimit": 21000, + "defaultGasLimitTokens": 200000, + "tokens": "./data/ethereumTokens.json", + "backends": [ + { + "name": "TREZOR Wallet - Ethereum", + "urls": [ + "https://mainnet.infura.io/QGyVKozSUEh2YhL4s2G4", + "http://88.208.115.69" + ] + } + ], + "explorer": "https://etherscan.io" + }, + { + "name": "Ethereum Classic", + "symbol": "ETC", + "network": "ethereumclassic", + "bip44": "m/44'/61'/0'/0", + "defaultGasPrice": 64, + "defaultGasLimit": 21000, + "defaultGasLimitTokens": 200000, + "tokens": "./data/ethereumClassicTokens.json", + "backends": [ + { + "name": "TREZOR Wallet - Ethereum", + "urls": [ + "https://kovan.infura.io/QGyVKozSUEh2YhL4s2G4", + "http://88.208.115.69", + "https://etc-geth.0xinfra.com/", + "https://mew.epool.io/" + ] + } + ], + "explorer": "https://etherscan.io" + }, { "name": "Ethereum Ropsten", "symbol": "tETH", @@ -51,6 +73,7 @@ "defaultGasPrice": 64, "defaultGasLimit": 21000, "defaultGasLimitTokens": 200000, + "tokens": "./data/ropstenTokens.json", "backends": [ { "name": "TREZOR Wallet - Ethereum", @@ -70,6 +93,7 @@ "defaultGasPrice": 64, "defaultGasLimit": 21000, "defaultGasLimitTokens": 200000, + "tokens": "./data/rinkebyTokens.json", "backends": [ { "name": "TREZOR Wallet - Ethereum", diff --git a/src/data/ethereumClassicTokens.json b/src/data/ethereumClassicTokens.json new file mode 100644 index 00000000..1469addb --- /dev/null +++ b/src/data/ethereumClassicTokens.json @@ -0,0 +1,14 @@ +[ + { + "address": "0x6F6DEb5db0C4994A8283A01D6CFeEB27Fc3bBe9C", + "name": "SmartBillions", + "symbol": "Smart", + "decimals": 0 + }, + { + "address": "0x5ace17f87c7391e5792a7683069a8025b83bbd85", + "name": "SmartBillions Token", + "symbol": "PLAY", + "decimals": 0 + } +] \ No newline at end of file diff --git a/src/data/ethTokens.json b/src/data/ethereumTokens.json similarity index 100% rename from src/data/ethTokens.json rename to src/data/ethereumTokens.json diff --git a/src/data/rinkebyTokens.json b/src/data/rinkebyTokens.json new file mode 100644 index 00000000..6ff856ce --- /dev/null +++ b/src/data/rinkebyTokens.json @@ -0,0 +1,20 @@ +[ + { + "address": "0xA52832A0B3EBfAeF629B1a44A922F46c90445108", + "name": "PLASMA", + "symbol": "PLASMA", + "decimals": 6 + }, + { + "address": "0xe27826eE778B6F78a49a686dA7D64f6E7b084a4f", + "name": "BHNToken", + "symbol": "BHNT", + "decimals": 0 + }, + { + "address": "0x0A057a87CE9C56D7e336B417c79cf30E8d27860B", + "name": "WALLETH", + "symbol": "WALL", + "decimals": 15 + } +] \ No newline at end of file diff --git a/src/data/ropstenTokens.json b/src/data/ropstenTokens.json new file mode 100644 index 00000000..082693ce --- /dev/null +++ b/src/data/ropstenTokens.json @@ -0,0 +1,8 @@ +[ + { + "address":"0x95D7321EdCe519419ba1DbC60A89bAfbF55EAC0D", + "name": "PLASMA", + "symbol" :"PLASMA", + "decimals": 6 + } +] \ No newline at end of file diff --git a/src/js/actions/LocalStorageActions.js b/src/js/actions/LocalStorageActions.js index bfe8a594..9f2061c9 100644 --- a/src/js/actions/LocalStorageActions.js +++ b/src/js/actions/LocalStorageActions.js @@ -30,9 +30,19 @@ export function loadData(): any { export function loadTokensFromJSON(): any { return async (dispatch, getState) => { try { - const appConfig = await httpRequest('data/appConfig.json', 'json'); - const ethTokens = await httpRequest('data/ethTokens.json', 'json'); - const ethERC20 = await httpRequest('data/ethERC20.json', 'json'); + const config = await httpRequest('data/appConfig.json', 'json'); + const ERC20Abi = await httpRequest('data/ERC20Abi.json', 'json'); + + // load tokens + const tokens = await config.coins.reduce(async (previousPromise: Promise, coin: any): Promise => { + const collection = await previousPromise; + const json: JSON = await httpRequest(coin.tokens, 'json'); + collection[ coin.network ] = json; + return collection; + }, Promise.resolve({})); + + console.log("JADE DAL") + const devices: ?string = get('devices'); if (devices) { @@ -50,11 +60,11 @@ export function loadTokensFromJSON(): any { }) } - const tokens: ?string = get('tokens'); - if (tokens) { + const userTokens: ?string = get('tokens'); + if (userTokens) { dispatch({ type: TOKEN.FROM_STORAGE, - payload: JSON.parse(tokens) + payload: JSON.parse(userTokens) }) } @@ -77,9 +87,9 @@ export function loadTokensFromJSON(): any { dispatch({ type: STORAGE.READY, - appConfig, - ethTokens, - ethERC20 + config, + tokens, + ERC20Abi }) } catch(error) { diff --git a/src/js/actions/SummaryActions.js b/src/js/actions/SummaryActions.js index b9c0f492..ee48610a 100644 --- a/src/js/actions/SummaryActions.js +++ b/src/js/actions/SummaryActions.js @@ -111,16 +111,13 @@ export const loadTokens = (input: string, account: any): any => { if (input.length < 1) return null; - // TODO (eth tokens, etc tokens, ropsten tokens ...) - const { ethTokens } = getState().localStorage; - + const tokens = getState().localStorage.tokens[ account.coin ]; const value = input.toLowerCase(); - const result = ethTokens.filter(t => + const result = tokens.filter(t => t.symbol.toLowerCase().indexOf(value) >= 0 || t.address.toLowerCase().indexOf(value) >= 0 || t.name.toLowerCase().indexOf(value) >= 0 ); - //const result = ethTokens.filter(t => t.symbol.toLowerCase().indexOf(lower) >= 0); if (result.length > 0) { return { options: result }; diff --git a/src/js/actions/Web3Actions.js b/src/js/actions/Web3Actions.js index 3efb1833..c54d5de9 100644 --- a/src/js/actions/Web3Actions.js +++ b/src/js/actions/Web3Actions.js @@ -54,7 +54,7 @@ type Web3Action = { export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod { return async (dispatch, getState) => { - const { config, ethERC20 } = getState().localStorage; + const { config, ERC20Abi } = getState().localStorage; const coin = config.coins[ coinIndex ]; if (!coin) { @@ -107,7 +107,7 @@ export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod { dispatch( init(instance, coinIndex) ); } else { - const erc20 = instance.eth.contract(ethERC20); + const erc20 = instance.eth.contract(ERC20Abi); dispatch({ type: WEB3.CREATE, @@ -269,6 +269,7 @@ export function getBalance(addr: Address): ActionMethod { dispatch({ type: ADDRESS.SET_BALANCE, address: addr.address, + coin: addr.coin, balance: newBalance }); @@ -292,11 +293,10 @@ export function getNonce(addr: Address) { dispatch({ type: ADDRESS.SET_NONCE, address: addr.address, + coin: addr.coin, nonce: result }); } - - } }); } diff --git a/src/js/reducers/AccountsReducer.js b/src/js/reducers/AccountsReducer.js index f355e482..d90058df 100644 --- a/src/js/reducers/AccountsReducer.js +++ b/src/js/reducers/AccountsReducer.js @@ -19,9 +19,9 @@ const initialState: Array = []; const createAccount = (state: Array, action: any): Array => { - // TODO check witch checksum + // TODO check with device_id // check if account was created before - const exist: ?Account = state.find(addr => addr.address === action.address); + const exist: ?Account = state.find(addr => addr.address === action.address && addr.coin === action.coin); if (exist) { return state; } @@ -52,7 +52,7 @@ const forgetAccounts = (state: Array, action: any): Array => { } const setBalance = (state: Array, action: any): Array => { - const index: number = state.findIndex(addr => addr.address === action.address); + const index: number = state.findIndex(addr => addr.address === action.address && addr.coin === action.coin); const newState: Array = [ ...state ]; newState[index].loaded = true; newState[index].balance = action.balance; @@ -60,7 +60,7 @@ const setBalance = (state: Array, action: any): Array => { } const setNonce = (state: Array, action: any): Array => { - const index: number = state.findIndex(addr => addr.address === action.address); + const index: number = state.findIndex(addr => addr.address === action.address && addr.coin === action.coin); const newState: Array = [ ...state ]; newState[index].loaded = true; newState[index].nonce = action.nonce; diff --git a/src/js/reducers/LocalStorageReducer.js b/src/js/reducers/LocalStorageReducer.js index 4e1e2481..9983b6e1 100644 --- a/src/js/reducers/LocalStorageReducer.js +++ b/src/js/reducers/LocalStorageReducer.js @@ -7,16 +7,16 @@ type State = { initialized: boolean; error: any; config: any; - ethERC20: any; - ethTokens: any; + ERC20Abi: any; + tokens: any; } const initialState: State = { initialized: false, error: null, config: null, - ethERC20: null, - ethTokens: null, + ERC20Abi: null, + tokens: null, }; export default function localStorage(state: State = initialState, action: any): any { @@ -27,9 +27,9 @@ export default function localStorage(state: State = initialState, action: any): return { ...state, initialized: true, - config: action.appConfig, - ethERC20: action.ethERC20, - ethTokens: action.ethTokens, + config: action.config, + ERC20Abi: action.ERC20Abi, + tokens: action.tokens, error: null }