mirror of
https://github.com/trezor/trezor-wallet
synced 2025-02-17 18:42:01 +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": [
|
"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",
|
"name": "Ethereum Ropsten",
|
||||||
"symbol": "tETH",
|
"symbol": "tETH",
|
||||||
@ -51,6 +73,7 @@
|
|||||||
"defaultGasPrice": 64,
|
"defaultGasPrice": 64,
|
||||||
"defaultGasLimit": 21000,
|
"defaultGasLimit": 21000,
|
||||||
"defaultGasLimitTokens": 200000,
|
"defaultGasLimitTokens": 200000,
|
||||||
|
"tokens": "./data/ropstenTokens.json",
|
||||||
"backends": [
|
"backends": [
|
||||||
{
|
{
|
||||||
"name": "TREZOR Wallet - Ethereum",
|
"name": "TREZOR Wallet - Ethereum",
|
||||||
@ -70,6 +93,7 @@
|
|||||||
"defaultGasPrice": 64,
|
"defaultGasPrice": 64,
|
||||||
"defaultGasLimit": 21000,
|
"defaultGasLimit": 21000,
|
||||||
"defaultGasLimitTokens": 200000,
|
"defaultGasLimitTokens": 200000,
|
||||||
|
"tokens": "./data/rinkebyTokens.json",
|
||||||
"backends": [
|
"backends": [
|
||||||
{
|
{
|
||||||
"name": "TREZOR Wallet - Ethereum",
|
"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 {
|
export function loadTokensFromJSON(): any {
|
||||||
return async (dispatch, getState) => {
|
return async (dispatch, getState) => {
|
||||||
try {
|
try {
|
||||||
const appConfig = await httpRequest('data/appConfig.json', 'json');
|
const config = await httpRequest('data/appConfig.json', 'json');
|
||||||
const ethTokens = await httpRequest('data/ethTokens.json', 'json');
|
const ERC20Abi = await httpRequest('data/ERC20Abi.json', 'json');
|
||||||
const ethERC20 = await httpRequest('data/ethERC20.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');
|
const devices: ?string = get('devices');
|
||||||
if (devices) {
|
if (devices) {
|
||||||
@ -50,11 +60,11 @@ export function loadTokensFromJSON(): any {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokens: ?string = get('tokens');
|
const userTokens: ?string = get('tokens');
|
||||||
if (tokens) {
|
if (userTokens) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: TOKEN.FROM_STORAGE,
|
type: TOKEN.FROM_STORAGE,
|
||||||
payload: JSON.parse(tokens)
|
payload: JSON.parse(userTokens)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,9 +87,9 @@ export function loadTokensFromJSON(): any {
|
|||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: STORAGE.READY,
|
type: STORAGE.READY,
|
||||||
appConfig,
|
config,
|
||||||
ethTokens,
|
tokens,
|
||||||
ethERC20
|
ERC20Abi
|
||||||
})
|
})
|
||||||
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
@ -111,16 +111,13 @@ export const loadTokens = (input: string, account: any): any => {
|
|||||||
|
|
||||||
if (input.length < 1) return null;
|
if (input.length < 1) return null;
|
||||||
|
|
||||||
// TODO (eth tokens, etc tokens, ropsten tokens ...)
|
const tokens = getState().localStorage.tokens[ account.coin ];
|
||||||
const { ethTokens } = getState().localStorage;
|
|
||||||
|
|
||||||
const value = input.toLowerCase();
|
const value = input.toLowerCase();
|
||||||
const result = ethTokens.filter(t =>
|
const result = tokens.filter(t =>
|
||||||
t.symbol.toLowerCase().indexOf(value) >= 0 ||
|
t.symbol.toLowerCase().indexOf(value) >= 0 ||
|
||||||
t.address.toLowerCase().indexOf(value) >= 0 ||
|
t.address.toLowerCase().indexOf(value) >= 0 ||
|
||||||
t.name.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) {
|
if (result.length > 0) {
|
||||||
return { options: result };
|
return { options: result };
|
||||||
|
@ -54,7 +54,7 @@ type Web3Action = {
|
|||||||
export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod {
|
export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod {
|
||||||
return async (dispatch, getState) => {
|
return async (dispatch, getState) => {
|
||||||
|
|
||||||
const { config, ethERC20 } = getState().localStorage;
|
const { config, ERC20Abi } = getState().localStorage;
|
||||||
|
|
||||||
const coin = config.coins[ coinIndex ];
|
const coin = config.coins[ coinIndex ];
|
||||||
if (!coin) {
|
if (!coin) {
|
||||||
@ -107,7 +107,7 @@ export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod {
|
|||||||
dispatch( init(instance, coinIndex) );
|
dispatch( init(instance, coinIndex) );
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const erc20 = instance.eth.contract(ethERC20);
|
const erc20 = instance.eth.contract(ERC20Abi);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: WEB3.CREATE,
|
type: WEB3.CREATE,
|
||||||
@ -269,6 +269,7 @@ export function getBalance(addr: Address): ActionMethod {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: ADDRESS.SET_BALANCE,
|
type: ADDRESS.SET_BALANCE,
|
||||||
address: addr.address,
|
address: addr.address,
|
||||||
|
coin: addr.coin,
|
||||||
balance: newBalance
|
balance: newBalance
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -292,11 +293,10 @@ export function getNonce(addr: Address) {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: ADDRESS.SET_NONCE,
|
type: ADDRESS.SET_NONCE,
|
||||||
address: addr.address,
|
address: addr.address,
|
||||||
|
coin: addr.coin,
|
||||||
nonce: result
|
nonce: result
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ const initialState: Array<Account> = [];
|
|||||||
|
|
||||||
const createAccount = (state: Array<Account>, action: any): 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
|
// 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) {
|
if (exist) {
|
||||||
return state;
|
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 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 ];
|
const newState: Array<Account> = [ ...state ];
|
||||||
newState[index].loaded = true;
|
newState[index].loaded = true;
|
||||||
newState[index].balance = action.balance;
|
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 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 ];
|
const newState: Array<Account> = [ ...state ];
|
||||||
newState[index].loaded = true;
|
newState[index].loaded = true;
|
||||||
newState[index].nonce = action.nonce;
|
newState[index].nonce = action.nonce;
|
||||||
|
@ -7,16 +7,16 @@ type State = {
|
|||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
error: any;
|
error: any;
|
||||||
config: any;
|
config: any;
|
||||||
ethERC20: any;
|
ERC20Abi: any;
|
||||||
ethTokens: any;
|
tokens: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: State = {
|
const initialState: State = {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
error: null,
|
error: null,
|
||||||
config: null,
|
config: null,
|
||||||
ethERC20: null,
|
ERC20Abi: null,
|
||||||
ethTokens: null,
|
tokens: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function localStorage(state: State = initialState, action: any): any {
|
export default function localStorage(state: State = initialState, action: any): any {
|
||||||
@ -27,9 +27,9 @@ export default function localStorage(state: State = initialState, action: any):
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
initialized: true,
|
initialized: true,
|
||||||
config: action.appConfig,
|
config: action.config,
|
||||||
ethERC20: action.ethERC20,
|
ERC20Abi: action.ERC20Abi,
|
||||||
ethTokens: action.ethTokens,
|
tokens: action.tokens,
|
||||||
error: null
|
error: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user