mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
unique tokens definitions for different networks
This commit is contained in:
parent
c3c51d2c91
commit
5f47c285dc
@ -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",
|
||||
|
14
src/data/ethereumClassicTokens.json
Normal file
14
src/data/ethereumClassicTokens.json
Normal file
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"address": "0x6F6DEb5db0C4994A8283A01D6CFeEB27Fc3bBe9C",
|
||||
"name": "SmartBillions",
|
||||
"symbol": "Smart",
|
||||
"decimals": 0
|
||||
},
|
||||
{
|
||||
"address": "0x5ace17f87c7391e5792a7683069a8025b83bbd85",
|
||||
"name": "SmartBillions Token",
|
||||
"symbol": "PLAY",
|
||||
"decimals": 0
|
||||
}
|
||||
]
|
20
src/data/rinkebyTokens.json
Normal file
20
src/data/rinkebyTokens.json
Normal file
@ -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
|
||||
}
|
||||
]
|
8
src/data/ropstenTokens.json
Normal file
8
src/data/ropstenTokens.json
Normal file
@ -0,0 +1,8 @@
|
||||
[
|
||||
{
|
||||
"address":"0x95D7321EdCe519419ba1DbC60A89bAfbF55EAC0D",
|
||||
"name": "PLASMA",
|
||||
"symbol" :"PLASMA",
|
||||
"decimals": 6
|
||||
}
|
||||
]
|
@ -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<any>, coin: any): Promise<any> => {
|
||||
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) {
|
||||
|
@ -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 };
|
||||
|
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ const initialState: Array<Account> = [];
|
||||
|
||||
const createAccount = (state: Array<Account>, action: any): Array<Account> => {
|
||||
|
||||
// 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<Account>, action: any): Array<Account> => {
|
||||
}
|
||||
|
||||
const setBalance = (state: Array<Account>, action: any): Array<Account> => {
|
||||
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<Account> = [ ...state ];
|
||||
newState[index].loaded = true;
|
||||
newState[index].balance = action.balance;
|
||||
@ -60,7 +60,7 @@ const setBalance = (state: Array<Account>, action: any): Array<Account> => {
|
||||
}
|
||||
|
||||
const setNonce = (state: Array<Account>, action: any): Array<Account> => {
|
||||
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<Account> = [ ...state ];
|
||||
newState[index].loaded = true;
|
||||
newState[index].nonce = action.nonce;
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user