refactoring "coin" to "network" & "checksum" to "deviceState"

pull/2/merge
Szymon Lesisz 6 years ago
parent 666dae47c2
commit c268c16649

@ -21,8 +21,8 @@ export const init = (): any => {
const state: State = { const state: State = {
index: parseInt(urlParams.address), index: parseInt(urlParams.address),
checksum: selected.checksum, deviceState: selected.state,
coin: urlParams.coin, network: urlParams.network,
location: location.pathname location: location.pathname
}; };
@ -30,26 +30,6 @@ export const init = (): any => {
type: ACCOUNT.INIT, type: ACCOUNT.INIT,
state: state state: state
}); });
// let discoveryProcess: ?Discovery = getState().discovery.find(d => d.checksum === selected.checksum && d.coin === currentAccount.coin);
// const discovering: boolean = (!discoveryProcess || !discoveryProcess.completed);
// const state: State = {
// ...initialState,
// loaded: true,
// checksum: currentAccount.checksum,
// address: currentAccount.address,
// coin: urlParams.coin,
// balance: currentAccount.balance,
// discovering
// };
// dispatch({
// type: ACCOUNT.INIT,
// state
// });
} }
} }
@ -76,24 +56,6 @@ export const update = (newProps: any): any => {
}); });
return; return;
} }
// update comes from device
// const device = connect.devices.find(d => d.checksum === accountDetail.checksum);
// if (accountDetail.detail !== device) {
// console.warn("DEV UPDATE!!!!")
// }
// const discoveryProcess = discovery.find(d => d.checksum === device.checksum && d.coin === accountDetail.coin);
// const account = accounts.find(a => a.checksum === accountDetail.checksum && a.index === accountDetail.addressIndex && a.coin === accountDetail.coin);
// if (account && !accountDetail.address) {
// // update current address
// console.warn("ACC UPDATE!!!!")
// }
// isDeviceChanged
// isDiscoveryChanged
} }
} }

@ -34,8 +34,8 @@ export function loadTokensFromJSON(): any {
const ERC20Abi = await httpRequest('data/ERC20Abi.json', 'json'); const ERC20Abi = await httpRequest('data/ERC20Abi.json', 'json');
// load tokens // load tokens
const tokens = await config.coins.reduce(async (previousPromise: Promise<any>, coin: any): Promise<any> => { const tokens = await config.coins.reduce(async (promise: Promise<any>, coin: any): Promise<any> => {
const collection = await previousPromise; const collection = await promise;
const json: JSON = await httpRequest(coin.tokens, 'json'); const json: JSON = await httpRequest(coin.tokens, 'json');
collection[ coin.network ] = json; collection[ coin.network ] = json;
return collection; return collection;

@ -20,9 +20,9 @@ export const init = (): any => {
const state: State = { const state: State = {
...initialState, ...initialState,
checksum: selected.checksum, deviceState: selected.state,
accountIndex: parseInt(urlParams.address), accountIndex: parseInt(urlParams.address),
coin: urlParams.coin, network: urlParams.network,
location: location.pathname, location: location.pathname,
}; };
@ -78,7 +78,7 @@ export const showAddress = (address_n: string): any => {
device: { device: {
path: selected.path, path: selected.path,
instance: selected.instance, instance: selected.instance,
state: selected.checksum state: selected.state
}, },
path: address_n, path: address_n,
}); });

@ -46,7 +46,7 @@ export const calculateMaxAmount = (balance: string, gasPrice: string, gasLimit:
} }
export const getFeeLevels = (coin: string, gasPrice: BigNumber | string, gasLimit: string): Array<FeeLevel> => { export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLimit: string): Array<FeeLevel> => {
if (typeof gasPrice === 'string') gasPrice = new BigNumber(gasPrice); if (typeof gasPrice === 'string') gasPrice = new BigNumber(gasPrice);
const quarter: BigNumber = gasPrice.dividedBy(4); const quarter: BigNumber = gasPrice.dividedBy(4);
const high: string = gasPrice.plus(quarter.times(2)).toString(); const high: string = gasPrice.plus(quarter.times(2)).toString();
@ -56,17 +56,17 @@ export const getFeeLevels = (coin: string, gasPrice: BigNumber | string, gasLimi
{ {
value: 'High', value: 'High',
gasPrice: high, gasPrice: high,
label: `${ calculateFee(high, gasLimit) } ${ coin }` label: `${ calculateFee(high, gasLimit) } ${ symbol }`
}, },
{ {
value: 'Normal', value: 'Normal',
gasPrice: gasPrice.toString(), gasPrice: gasPrice.toString(),
label: `${ calculateFee(gasPrice.toString(), gasLimit) } ${ coin }` label: `${ calculateFee(gasPrice.toString(), gasLimit) } ${ symbol }`
}, },
{ {
value: 'Low', value: 'Low',
gasPrice: low, gasPrice: low,
label: `${ calculateFee(low, gasLimit) } ${ coin }` label: `${ calculateFee(low, gasLimit) } ${ symbol }`
}, },
{ {
value: 'Custom', value: 'Custom',
@ -77,10 +77,10 @@ export const getFeeLevels = (coin: string, gasPrice: BigNumber | string, gasLimi
} }
export const findBalance = (getState: any): string => { export const findBalance = (getState: any): string => {
const state = getState().sendForm; const state = getState().sendForm;
const account = getState().accounts.find(a => a.checksum === state.checksum && a.index === state.accountIndex && a.coin === state.coin); const account = getState().accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);
if (state.token !== state.coin) { if (state.token !== state.network) {
return getState().tokens.find(t => t.ethAddress === account.address && t.symbol === state.token).balance; return getState().tokens.find(t => t.ethAddress === account.address && t.symbol === state.token).balance;
} else { } else {
return account.balance; return account.balance;
@ -98,15 +98,15 @@ export const init = (): any => {
const selected = findSelectedDevice( getState().connect ); const selected = findSelectedDevice( getState().connect );
if (!selected) return; if (!selected) return;
const web3instance = getState().web3.find(w3 => w3.coin === urlParams.coin); const web3instance = getState().web3.find(w3 => w3.network === urlParams.network);
if (!web3instance) { if (!web3instance) {
// no backend for this coin // no backend for this network
//return; //return;
} }
// TODO: check if there are some unfinished tx in localStorage // TODO: check if there are some unfinished tx in localStorage
const { config } = getState().localStorage; const { config } = getState().localStorage;
const coin = config.coins.find(c => c.network === urlParams.coin); const coin = config.coins.find(c => c.network === urlParams.network);
const gasPrice: BigNumber = new BigNumber( EthereumjsUnits.convert(web3instance.gasPrice, 'wei', 'gwei') ) || new BigNumber(coin.defaultGasPrice); const gasPrice: BigNumber = new BigNumber( EthereumjsUnits.convert(web3instance.gasPrice, 'wei', 'gwei') ) || new BigNumber(coin.defaultGasPrice);
const gasLimit: string = coin.defaultGasLimit.toString(); const gasLimit: string = coin.defaultGasLimit.toString();
@ -116,11 +116,11 @@ export const init = (): any => {
const state: State = { const state: State = {
...initialState, ...initialState,
checksum: selected.checksum, deviceState: selected.state,
accountIndex: parseInt(urlParams.address), accountIndex: parseInt(urlParams.address),
coin: urlParams.coin, network: urlParams.network,
coinSymbol: coin.symbol, coinSymbol: coin.symbol,
token: urlParams.coin, token: urlParams.network,
location: location.pathname, location: location.pathname,
feeLevels, feeLevels,
@ -186,11 +186,11 @@ export const validation = (): any => {
} else if (!EthereumjsUtil.isValidAddress(state.address)) { } else if (!EthereumjsUtil.isValidAddress(state.address)) {
errors.address = 'Address is not valid'; errors.address = 'Address is not valid';
} else if (myAccount) { } else if (myAccount) {
if (myAccount.coin === state.coin) { if (myAccount.network === state.network) {
infos.address = `TREZOR Address #${ (myAccount.index + 1) }`; infos.address = `TREZOR Address #${ (myAccount.index + 1) }`;
} else { } else {
// TODO: load coins from config // TODO: load coins from config
warnings.address = `Looks like it's TREZOR address in Account #${ (myAccount.index + 1) } of ${ myAccount.coin.toUpperCase() }`; warnings.address = `Looks like it's TREZOR address in Account #${ (myAccount.index + 1) } of ${ myAccount.network.toUpperCase() } network`;
} }
} }
} }
@ -204,10 +204,10 @@ export const validation = (): any => {
} else if (state.amount.length > 0 && !state.amount.match(numberRegExp)) { } else if (state.amount.length > 0 && !state.amount.match(numberRegExp)) {
errors.amount = 'Amount is not a number'; errors.amount = 'Amount is not a number';
} else { } else {
const account = getState().accounts.find(a => a.checksum === state.checksum && a.index === state.accountIndex && a.coin === state.coin); const account = getState().accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);
let decimalRegExp; let decimalRegExp;
if (state.token !== state.coin) { if (state.token !== state.network) {
const token: any = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === state.token); const token: any = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === state.token);
if (parseInt(token.decimals) > 0) { if (parseInt(token.decimals) > 0) {
@ -270,7 +270,7 @@ export const validation = (): any => {
} }
// valid data // valid data
if (state.touched.data && state.coin === state.token && state.data.length > 0) { if (state.touched.data && state.network === state.token && state.data.length > 0) {
const re = /^[0-9A-Fa-f]+$/g; const re = /^[0-9A-Fa-f]+$/g;
//const re = /^[0-9A-Fa-f]{6}$/g; //const re = /^[0-9A-Fa-f]{6}$/g;
if (!re.test(state.data)) { if (!re.test(state.data)) {
@ -320,7 +320,7 @@ export const onAmountChange = (amount: string): any => {
const currentState: State = getState().sendForm; const currentState: State = getState().sendForm;
const touched = { ...currentState.touched }; const touched = { ...currentState.touched };
touched.amount = true; touched.amount = true;
const total: string = calculateTotal(currentState.token !== currentState.coin ? '0' : amount, currentState.gasPrice, currentState.gasLimit); const total: string = calculateTotal(currentState.token !== currentState.network ? '0' : amount, currentState.gasPrice, currentState.gasLimit);
const state: State = { const state: State = {
...currentState, ...currentState,
@ -345,20 +345,20 @@ export const onCurrencyChange = (currency: any): any => {
const currentState = getState().sendForm; const currentState = getState().sendForm;
const account = getState().accounts.find(a => a.checksum === currentState.checksum && a.index === currentState.accountIndex && a.coin === currentState.coin); const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (!account) { if (!account) {
// account not found // account not found
return; return;
} }
const { config } = getState().localStorage; const { config } = getState().localStorage;
const coin = config.coins.find(c => c.network === currentState.coin); const coin = config.coins.find(c => c.network === currentState.network);
let gasLimit: string = ''; let gasLimit: string = '';
let amount: string = currentState.amount; let amount: string = currentState.amount;
let total: string; let total: string;
if (currentState.coin !== currency.value) { if (currentState.network !== currency.value) {
gasLimit = coin.defaultGasLimitTokens.toString(); gasLimit = coin.defaultGasLimitTokens.toString();
if (currentState.setMax) { if (currentState.setMax) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currency.value).balance; const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currency.value).balance;
@ -401,7 +401,7 @@ export const onSetMax = (): any => {
const touched = { ...currentState.touched }; const touched = { ...currentState.touched };
touched.amount = true; touched.amount = true;
const account = getState().accounts.find(a => a.checksum === currentState.checksum && a.index === currentState.accountIndex && a.coin === currentState.coin); const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (!account) { if (!account) {
// account not found // account not found
return; return;
@ -410,7 +410,7 @@ export const onSetMax = (): any => {
let amount: string = currentState.amount; let amount: string = currentState.amount;
let total: string = currentState.total; let total: string = currentState.total;
if (!currentState.setMax) { if (!currentState.setMax) {
if (currentState.token !== currentState.coin) { if (currentState.token !== currentState.network) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance; const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
amount = tokenBalance; amount = tokenBalance;
total = calculateTotal('0', currentState.gasPrice, currentState.gasLimit); total = calculateTotal('0', currentState.gasPrice, currentState.gasLimit);
@ -459,15 +459,15 @@ export const onFeeLevelChange = (feeLevel: any): any => {
} }
if (currentState.setMax) { if (currentState.setMax) {
const account = getState().accounts.find(a => a.checksum === currentState.checksum && a.index === currentState.accountIndex && a.coin === currentState.coin); const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (state.token !== state.coin) { if (state.token !== state.network) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance; const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
state.amount = tokenBalance; state.amount = tokenBalance;
} else { } else {
state.amount = calculateMaxAmount(account.balance, state.gasPrice, state.gasLimit); state.amount = calculateMaxAmount(account.balance, state.gasPrice, state.gasLimit);
} }
} }
state.total = calculateTotal(state.token !== state.coin ? '0' : state.amount, state.gasPrice, state.gasLimit); state.total = calculateTotal(state.token !== state.network ? '0' : state.amount, state.gasPrice, state.gasLimit);
dispatch({ dispatch({
type: SEND.FEE_LEVEL_CHANGE, type: SEND.FEE_LEVEL_CHANGE,
@ -492,15 +492,15 @@ export const updateFeeLevels = (): any => {
}; };
if (currentState.setMax) { if (currentState.setMax) {
const account = getState().accounts.find(a => a.checksum === currentState.checksum && a.index === currentState.accountIndex && a.coin === currentState.coin); const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (state.token !== state.coin) { if (state.token !== state.network) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance; const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
state.amount = tokenBalance; state.amount = tokenBalance;
} else { } else {
state.amount = calculateMaxAmount(account.balance, state.gasPrice, state.gasLimit); state.amount = calculateMaxAmount(account.balance, state.gasPrice, state.gasLimit);
} }
} }
state.total = calculateTotal(state.token !== state.coin ? '0' : state.amount, state.gasPrice, state.gasLimit); state.total = calculateTotal(state.token !== state.network ? '0' : state.amount, state.gasPrice, state.gasLimit);
dispatch({ dispatch({
type: SEND.UPDATE_FEE_LEVELS, type: SEND.UPDATE_FEE_LEVELS,
@ -532,8 +532,8 @@ export const onGasPriceChange = (gasPrice: string): any => {
state.selectedFeeLevel = customLevel; state.selectedFeeLevel = customLevel;
if (currentState.setMax) { if (currentState.setMax) {
const account = getState().accounts.find(a => a.checksum === currentState.checksum && a.index === currentState.accountIndex && a.coin === currentState.coin); const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (state.token !== state.coin) { if (state.token !== state.network) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance; const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
state.amount = tokenBalance; state.amount = tokenBalance;
} else { } else {
@ -542,7 +542,7 @@ export const onGasPriceChange = (gasPrice: string): any => {
} }
} }
state.total = calculateTotal(state.token !== state.coin ? '0' : state.amount, state.gasPrice, state.gasLimit); state.total = calculateTotal(state.token !== state.network ? '0' : state.amount, state.gasPrice, state.gasLimit);
dispatch({ dispatch({
type: SEND.GAS_PRICE_CHANGE, type: SEND.GAS_PRICE_CHANGE,
@ -572,8 +572,8 @@ export const onGasLimitChange = (gasLimit: string): any => {
state.selectedFeeLevel = customLevel; state.selectedFeeLevel = customLevel;
if (currentState.setMax) { if (currentState.setMax) {
const account = getState().accounts.find(a => a.checksum === currentState.checksum && a.index === currentState.accountIndex && a.coin === currentState.coin); const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (state.token !== state.coin) { if (state.token !== state.network) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance; const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
state.amount = tokenBalance; state.amount = tokenBalance;
} else { } else {
@ -582,7 +582,7 @@ export const onGasLimitChange = (gasLimit: string): any => {
} }
} }
state.total = calculateTotal(state.token !== state.coin ? '0' : state.amount, state.gasPrice, state.gasLimit); state.total = calculateTotal(state.token !== state.network ? '0' : state.amount, state.gasPrice, state.gasLimit);
dispatch({ dispatch({
type: SEND.GAS_LIMIT_CHANGE, type: SEND.GAS_LIMIT_CHANGE,
@ -619,17 +619,17 @@ export const onSend = (): any => {
return async (dispatch, getState): Promise<any> => { return async (dispatch, getState): Promise<any> => {
const state: State = getState().sendForm; const state: State = getState().sendForm;
const web3instance = getState().web3.filter(w3 => w3.coin === state.coin)[0]; const web3instance = getState().web3.filter(w3 => w3.network === state.network)[0];
const web3 = web3instance.web3; const web3 = web3instance.web3;
const account = getState().accounts.find(a => a.checksum === state.checksum && a.index === state.accountIndex && a.coin === state.coin); const account = getState().accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);
const address_n = account.addressPath; const address_n = account.addressPath;
let data: string = ''; let data: string = '';
let txAmount = web3.toHex(web3.toWei(state.amount, 'ether')); let txAmount = web3.toHex(web3.toWei(state.amount, 'ether'));
let txAddress = state.address; let txAddress = state.address;
if (state.coin !== state.token) { if (state.network !== state.token) {
const tokens = getState().tokens const tokens = getState().tokens
const t = tokens.find(t => t.ethAddress === account.address && t.symbol === state.token); const t = tokens.find(t => t.ethAddress === account.address && t.symbol === state.token);
const contract = web3instance.erc20.at(t.address); const contract = web3instance.erc20.at(t.address);
@ -683,7 +683,7 @@ export const onSend = (): any => {
device: { device: {
path: selected.path, path: selected.path,
instance: selected.instance, instance: selected.instance,
state: selected.checksum state: selected.state
}, },
//path: "m/44'/60'/0'/0/0", //path: "m/44'/60'/0'/0/0",
path: txData.address_n, path: txData.address_n,
@ -719,7 +719,7 @@ export const onSend = (): any => {
// console.log("---->GASSS", txData, gasLimit2.toString() ); // console.log("---->GASSS", txData, gasLimit2.toString() );
const { config } = getState().localStorage; const { config } = getState().localStorage;
const selectedCoin = config.coins.find(c => c.network === state.coin); const selectedCoin = config.coins.find(c => c.network === state.network);
try { try {
const tx = new EthereumjsTx(txData); const tx = new EthereumjsTx(txData);

@ -24,9 +24,9 @@ export const init = (): any => {
const state: State = { const state: State = {
...initialState, ...initialState,
checksum: selected.checksum, deviceState: selected.state,
accountIndex: parseInt(urlParams.address), accountIndex: parseInt(urlParams.address),
coin: urlParams.coin, network: urlParams.network,
location: location.pathname, location: location.pathname,
}; };
@ -65,53 +65,13 @@ export const onDetailsToggle = (): any => {
} }
} }
// export const init = (address: string): any => {
// return (dispatch, getState): void => {
// const { location } = getState().router;
// const urlParams = location.params;
// const selected = findSelectedDevice(getState().connect);
// const accounts = getState().accounts;
// // const currentAccount = accounts.find(a => a.index === parseInt(urlParams.address) && a.coin === urlParams.coin && a.deviceId === urlParams.device && a.loaded);
// const currentAccount = accounts.find(a => a.index === parseInt(urlParams.address) && a.coin === urlParams.coin && a.checksum === selected.checksum);
// if (!currentAccount) {
// console.log("STATER", getState())
// // account not found
// return;
// }
// const web3instance = getState().web3.find(w3 => w3.coin === urlParams.coin);
// if (!web3instance) {
// // no backend for this coin
// return;
// }
// const state: State = {
// ...initialState,
// loaded: true,
// address: currentAccount.address,
// coin: urlParams.coin,
// balance: currentAccount.balance,
// };
// dispatch({
// type: SUMMARY.INIT,
// state
// });
// }
// }
export const loadTokens = (input: string, account: any): any => { export const loadTokens = (input: string, account: any): any => {
return async (dispatch, getState): Promise<any> => { return async (dispatch, getState): Promise<any> => {
if (input.length < 1) return null; if (input.length < 1) return null;
const tokens = getState().localStorage.tokens[ account.coin ]; const tokens = getState().localStorage.tokens[ account.network ];
const value = input.toLowerCase(); const value = input.toLowerCase();
const result = tokens.filter(t => const result = tokens.filter(t =>
t.symbol.toLowerCase().indexOf(value) >= 0 || t.symbol.toLowerCase().indexOf(value) >= 0 ||
@ -122,7 +82,7 @@ export const loadTokens = (input: string, account: any): any => {
if (result.length > 0) { if (result.length > 0) {
return { options: result }; return { options: result };
} else { } else {
const web3instance = getState().web3.find(w3 => w3.coin === account.coin); const web3instance = getState().web3.find(w3 => w3.network === account.network);
const info = await getTokenInfoAsync(web3instance.erc20, input); const info = await getTokenInfoAsync(web3instance.erc20, input);
info.address = input; info.address = input;
@ -148,13 +108,13 @@ export const loadTokens = (input: string, account: any): any => {
export const selectToken = (token: any, account: any): any => { export const selectToken = (token: any, account: any): any => {
return async (dispatch, getState): Promise<any> => { return async (dispatch, getState): Promise<any> => {
const web3instance = getState().web3.find(w3 => w3.coin === account.coin); const web3instance = getState().web3.find(w3 => w3.network === account.network);
dispatch({ dispatch({
type: TOKEN.ADD, type: TOKEN.ADD,
payload: { payload: {
...token, ...token,
ethAddress: account.address, ethAddress: account.address,
checksum: account.checksum deviceState: account.deviceState
} }
}); });
@ -195,9 +155,8 @@ export const onCustomTokenToggle = (): any => {
export const onCustomTokenAddressChange = (value: string): any => { export const onCustomTokenAddressChange = (value: string): any => {
// todo: // todo:
// -validate addres // -validate address
// - if adress is ok, try to fetch token info // - if adresss is ok, try to fetch token info
// - check if addres does not exist in predefined coins
// return { // return {
// type: ACTIONS.TOKENS_CUSTOM_ADDRESS_CHANGE, // type: ACTIONS.TOKENS_CUSTOM_ADDRESS_CHANGE,
// value // value

@ -55,15 +55,10 @@ export const init = (): any => {
try { try {
await TrezorConnect.init({ await TrezorConnect.init({
// transportReconnect: true,
// coinsSrc: './data/coins.json',
// firmwareReleasesSrc: './data/releases-1.json',
// transportConfigSrc: './data/config_signed.bin',
transportReconnect: false, transportReconnect: false,
// latestBridgeSrc: './data/latest.txt',
// connectSrc: 'https://localhost:8088/', // connectSrc: 'https://localhost:8088/',
connectSrc: 'https://sisyfos.trezor.io/', connectSrc: 'https://sisyfos.trezor.io/',
debug: true, debug: false,
popup: false, popup: false,
// webusb: false // webusb: false
}); });
@ -132,7 +127,7 @@ export const initConnectedDevice = (device: any): any => {
//dispatch( onSelectDevice(device) ); //dispatch( onSelectDevice(device) );
const selected = findSelectedDevice(getState().connect); const selected = findSelectedDevice(getState().connect);
if (selected && selected.checksum) { if (selected && selected.state) {
dispatch( onSelectDevice(device) ); dispatch( onSelectDevice(device) );
} else if (!selected) { } else if (!selected) {
dispatch( onSelectDevice(device) ); dispatch( onSelectDevice(device) );
@ -157,7 +152,7 @@ export function onSelectDevice(device: any): any {
} else if (device.instance) { } else if (device.instance) {
dispatch( push(`/device/${ device.features.device_id }:${ device.instance }`) ); dispatch( push(`/device/${ device.features.device_id }:${ device.instance }`) );
} else { } else {
//dispatch( push(`/device/${ device.features.device_id }/coin/etc/address/0`) ); //dispatch( push(`/device/${ device.features.device_id }/network/etc/address/0`) );
dispatch( push(`/device/${ device.features.device_id }`) ); dispatch( push(`/device/${ device.features.device_id }`) );
} }
} }
@ -219,7 +214,7 @@ export const getSelectedDeviceState = (): any => {
&& selected.connected && selected.connected
&& !selected.unacquired && !selected.unacquired
&& !selected.acquiring && !selected.acquiring
&& !selected.checksum) { && !selected.state) {
const response = await __getDeviceState(selected.path, selected.instance); const response = await __getDeviceState(selected.path, selected.instance);
@ -227,7 +222,7 @@ export const getSelectedDeviceState = (): any => {
dispatch({ dispatch({
type: CONNECT.AUTH_DEVICE, type: CONNECT.AUTH_DEVICE,
device: selected, device: selected,
checksum: response.payload.xpub state: response.payload.xpub
}); });
} else { } else {
dispatch({ dispatch({
@ -262,7 +257,7 @@ export const deviceDisconnect = (device: any): any => {
stopDiscoveryProcess(selected); stopDiscoveryProcess(selected);
} }
const affected = getState().connect.devices.filter(d => d.features && d.checksum && !d.remember && d.features.device_id === device.features.device_id); const affected = getState().connect.devices.filter(d => d.features && d.state && !d.remember && d.features.device_id === device.features.device_id);
if (affected.length > 0) { if (affected.length > 0) {
dispatch({ dispatch({
type: CONNECT.REMEMBER_REQUEST, type: CONNECT.REMEMBER_REQUEST,
@ -279,13 +274,13 @@ export const deviceDisconnect = (device: any): any => {
} }
} }
export const coinChanged = (coin: ?string): any => { export const coinChanged = (network: ?string): any => {
return (dispatch, getState): void => { return (dispatch, getState): void => {
const selected = findSelectedDevice(getState().connect); const selected = findSelectedDevice(getState().connect);
dispatch( stopDiscoveryProcess(selected) ); dispatch( stopDiscoveryProcess(selected) );
if (coin) { if (network) {
dispatch( startDiscoveryProcess(selected, coin) ); dispatch( startDiscoveryProcess(selected, network) );
} }
} }
} }
@ -297,10 +292,10 @@ export function acquire(): any {
const selected = findSelectedDevice(getState().connect); const selected = findSelectedDevice(getState().connect);
const saved = getState().connect.devices.map(d => { const saved = getState().connect.devices.map(d => {
if (d.checksum) { if (d.state) {
return { return {
instance: d.instance, instance: d.instance,
checksum: d.checksum state: d.state
} }
} else { } else {
return null; return null;
@ -329,7 +324,6 @@ export function acquire(): any {
if (response && response.success) { if (response && response.success) {
dispatch({ dispatch({
type: DEVICE.ACQUIRED, type: DEVICE.ACQUIRED,
// checksum: response
}) })
} else { } else {
// TODO: handle invalid pin? // TODO: handle invalid pin?
@ -360,11 +354,11 @@ export const forgetDevice = (device: any) => {
return (dispatch: any, getState: any): any => { return (dispatch: any, getState: any): any => {
// find accounts associated with this device // find accounts associated with this device
const accounts: Array<any> = getState().accounts.find(a => a.checksum === device.checksum); const accounts: Array<any> = getState().accounts.find(a => a.deviceState === device.state);
// find discovery processes associated with this device // find discovery processes associated with this device
const discovery: Array<any> = getState().discovery.find(d => d.checksum === device.checksum); const discovery: Array<any> = getState().discovery.find(d => d.deviceState === device.state);
} }
} }
@ -393,17 +387,17 @@ export const onDuplicateDevice = () => {
} }
} }
export const beginDiscoveryProcess = (device: any, coin: string): any => { export const beginDiscoveryProcess = (device: any, network: string): any => {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const { config } = getState().localStorage; const { config } = getState().localStorage;
const coinToDiscover = config.coins.find(c => c.network === coin); const coinToDiscover = config.coins.find(c => c.network === network);
// TODO: validate device checksum // TODO: validate device deviceState
// const checksum = await __acquire(device.path, device.instance); // const deviceState = await __acquire(device.path, device.instance);
// if (checksum && checksum.success) { // if (deviceState && deviceState.success) {
// if (checksum.payload.xpub !== device.checksum) { // if (deviceState.payload.xpub !== device.state) {
// console.error("Incorrect checksum!"); // console.error("Incorrect deviceState!");
// return; // return;
// } // }
// } // }
@ -413,7 +407,7 @@ export const beginDiscoveryProcess = (device: any, coin: string): any => {
device: { device: {
path: device.path, path: device.path,
instance: device.instance, instance: device.instance,
state: device.checksum state: device.state
}, },
path: coinToDiscover.bip44, path: coinToDiscover.bip44,
confirmation: false, confirmation: false,
@ -434,7 +428,7 @@ export const beginDiscoveryProcess = (device: any, coin: string): any => {
{ {
label: 'Try again', label: 'Try again',
callback: () => { callback: () => {
dispatch(startDiscoveryProcess(device, coin)) dispatch(startDiscoveryProcess(device, network))
} }
} }
] ]
@ -454,14 +448,14 @@ export const beginDiscoveryProcess = (device: any, coin: string): any => {
// send data to reducer // send data to reducer
dispatch({ dispatch({
type: DISCOVERY.START, type: DISCOVERY.START,
coin: coinToDiscover.network, network: coinToDiscover.network,
device, device,
xpub: response.payload.publicKey, xpub: response.payload.publicKey,
basePath, basePath,
hdKey, hdKey,
}); });
dispatch( startDiscoveryProcess(device, coin) ); dispatch( startDiscoveryProcess(device, network) );
} }
} }
@ -472,12 +466,12 @@ export const discoverAddress = (device: any, discoveryProcess: Discovery): any =
const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex); const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex);
const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex'); const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex');
const ethAddress: string = EthereumjsUtil.toChecksumAddress(publicAddress); const ethAddress: string = EthereumjsUtil.toChecksumAddress(publicAddress);
const coin = discoveryProcess.coin; const network = discoveryProcess.network;
dispatch({ dispatch({
type: ADDRESS.CREATE, type: ADDRESS.CREATE,
device, device,
coin, network,
index: discoveryProcess.accountIndex, index: discoveryProcess.accountIndex,
path, path,
address: ethAddress address: ethAddress
@ -490,7 +484,7 @@ export const discoverAddress = (device: any, discoveryProcess: Discovery): any =
device: { device: {
path: device.path, path: device.path,
instance: device.instance, instance: device.instance,
state: device.checksum state: device.state
}, },
path, path,
showOnTrezor: false showOnTrezor: false
@ -515,7 +509,7 @@ export const discoverAddress = (device: any, discoveryProcess: Discovery): any =
{ {
label: 'Try again', label: 'Try again',
callback: () => { callback: () => {
dispatch(startDiscoveryProcess(device, discoveryProcess.coin)) dispatch(startDiscoveryProcess(device, discoveryProcess.network))
} }
} }
] ]
@ -536,7 +530,7 @@ export const discoverAddress = (device: any, discoveryProcess: Discovery): any =
{ {
label: 'Try again', label: 'Try again',
callback: () => { callback: () => {
dispatch(startDiscoveryProcess(device, discoveryProcess.coin)) dispatch(startDiscoveryProcess(device, discoveryProcess.network))
} }
} }
] ]
@ -545,14 +539,14 @@ export const discoverAddress = (device: any, discoveryProcess: Discovery): any =
return; return;
} }
const web3instance = getState().web3.find(w3 => w3.coin === coin); const web3instance = getState().web3.find(w3 => w3.network === network);
const balance = await getBalanceAsync(web3instance.web3, ethAddress); const balance = await getBalanceAsync(web3instance.web3, ethAddress);
if (discoveryProcess.interrupted) return; if (discoveryProcess.interrupted) return;
dispatch({ dispatch({
type: ADDRESS.SET_BALANCE, type: ADDRESS.SET_BALANCE,
address: ethAddress, address: ethAddress,
coin, network,
balance: web3instance.web3.fromWei(balance.toString(), 'ether') balance: web3instance.web3.fromWei(balance.toString(), 'ether')
}); });
@ -579,14 +573,14 @@ export const discoverAddress = (device: any, discoveryProcess: Discovery): any =
dispatch({ dispatch({
type: ADDRESS.SET_NONCE, type: ADDRESS.SET_NONCE,
address: ethAddress, address: ethAddress,
coin, network,
nonce: nonce nonce: nonce
}); });
const addressIsEmpty = nonce < 1 && !balance.greaterThan(0); const addressIsEmpty = nonce < 1 && !balance.greaterThan(0);
if (!addressIsEmpty) { if (!addressIsEmpty) {
//dispatch( startDiscoveryProcess(device, discoveryProcess.coin) ); //dispatch( startDiscoveryProcess(device, discoveryProcess.network) );
dispatch( discoverAddress(device, discoveryProcess) ); dispatch( discoverAddress(device, discoveryProcess) );
} else { } else {
// release acquired sesssion // release acquired sesssion
@ -594,7 +588,7 @@ export const discoverAddress = (device: any, discoveryProcess: Discovery): any =
device: { device: {
path: device.path, path: device.path,
instance: device.instance, instance: device.instance,
state: device.checksum state: device.state
}, },
path: "m/44'/60'/0'/0", path: "m/44'/60'/0'/0",
confirmation: false, confirmation: false,
@ -605,13 +599,13 @@ export const discoverAddress = (device: any, discoveryProcess: Discovery): any =
dispatch({ dispatch({
type: DISCOVERY.COMPLETE, type: DISCOVERY.COMPLETE,
device, device,
coin network
}); });
} }
} }
} }
export function startDiscoveryProcess(device: any, coin: string, ignoreCompleted?: boolean): any { export function startDiscoveryProcess(device: any, network: string, ignoreCompleted?: boolean): any {
return (dispatch, getState) => { return (dispatch, getState) => {
const selected = findSelectedDevice(getState().connect); const selected = findSelectedDevice(getState().connect);
@ -622,37 +616,37 @@ export function startDiscoveryProcess(device: any, coin: string, ignoreCompleted
} else if (selected.path !== device.path) { } else if (selected.path !== device.path) {
console.error("Start discovery: requested device is not selected", device, selected) console.error("Start discovery: requested device is not selected", device, selected)
return; return;
} else if (!selected.checksum) { } else if (!selected.state) {
console.warn("Start discovery: Selected device wasn't authenticated yet...") console.warn("Start discovery: Selected device wasn't authenticated yet...")
return; return;
} }
const discovery = getState().discovery; const discovery = getState().discovery;
let discoveryProcess: ?Discovery = discovery.find(d => d.checksum === device.checksum && d.coin === coin); let discoveryProcess: ?Discovery = discovery.find(d => d.deviceState === device.state && d.network === network);
if (!selected.connected && (!discoveryProcess || !discoveryProcess.completed)) { if (!selected.connected && (!discoveryProcess || !discoveryProcess.completed)) {
dispatch({ dispatch({
type: DISCOVERY.WAITING, type: DISCOVERY.WAITING,
device, device,
coin network
}); });
return; return;
} }
if (!discoveryProcess) { if (!discoveryProcess) {
dispatch( beginDiscoveryProcess(device, coin) ); dispatch( beginDiscoveryProcess(device, network) );
return; return;
} else { } else {
if (discoveryProcess.completed && !ignoreCompleted) { if (discoveryProcess.completed && !ignoreCompleted) {
dispatch({ dispatch({
type: DISCOVERY.COMPLETE, type: DISCOVERY.COMPLETE,
device, device,
coin network
}); });
} else if (discoveryProcess.interrupted || discoveryProcess.waitingForDevice) { } else if (discoveryProcess.interrupted || discoveryProcess.waitingForDevice) {
// discovery cycle was interrupted // discovery cycle was interrupted
// start from beginning // start from beginning
dispatch( beginDiscoveryProcess(device, coin) ); dispatch( beginDiscoveryProcess(device, network) );
} else { } else {
dispatch( discoverAddress(device, discoveryProcess) ); dispatch( discoverAddress(device, discoveryProcess) );
} }
@ -665,16 +659,16 @@ export const restoreDiscovery = (): any => {
const selected = findSelectedDevice(getState().connect); const selected = findSelectedDevice(getState().connect);
if (selected && selected.connected && !selected.unacquired) { if (selected && selected.connected && !selected.unacquired) {
const discoveryProcess: ?Discovery = getState().discovery.find(d => d.checksum === selected.checksum && d.waitingForDevice); const discoveryProcess: ?Discovery = getState().discovery.find(d => d.deviceState === selected.state && d.waitingForDevice);
if (discoveryProcess) { if (discoveryProcess) {
dispatch( startDiscoveryProcess(selected, discoveryProcess.coin) ); dispatch( startDiscoveryProcess(selected, discoveryProcess.network) );
} }
} }
} }
} }
// there is no discovery process but it should be // there is no discovery process but it should be
// this is possible race condition when coin was changed in url but device wasn't authenticated yet // this is possible race condition when "network" was changed in url but device wasn't authenticated yet
// try to discovery after CONNECT.AUTH_DEVICE action // try to discovery after CONNECT.AUTH_DEVICE action
export const checkDiscoveryStatus = (): any => { export const checkDiscoveryStatus = (): any => {
return (dispatch, getState): void => { return (dispatch, getState): void => {
@ -682,10 +676,10 @@ export const checkDiscoveryStatus = (): any => {
if (!selected) return; if (!selected) return;
const urlParams = getState().router.location.params; const urlParams = getState().router.location.params;
if (urlParams.coin) { if (urlParams.network) {
const discoveryProcess: ?Discovery = getState().discovery.find(d => d.checksum === selected.checksum && d.coin === urlParams.coin); const discoveryProcess: ?Discovery = getState().discovery.find(d => d.deviceState === selected.state && d.network === urlParams.network);
if (!discoveryProcess) { if (!discoveryProcess) {
dispatch( startDiscoveryProcess(selected, urlParams.coin) ); dispatch( startDiscoveryProcess(selected, urlParams.network) );
} }
} }
} }
@ -706,6 +700,6 @@ export function stopDiscoveryProcess(device: any): any {
export function addAddress(): any { export function addAddress(): any {
return (dispatch, getState) => { return (dispatch, getState) => {
const selected = findSelectedDevice(getState().connect); const selected = findSelectedDevice(getState().connect);
dispatch( startDiscoveryProcess(selected, getState().router.location.params.coin, true) ); // TODO: coin nicer dispatch( startDiscoveryProcess(selected, getState().router.location.params.network, true) ); // TODO: network nicer
} }
} }

@ -65,7 +65,7 @@ export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod {
return; return;
} }
const coinName = coin.network; const network = coin.network;
const urls = coin.backends[0].urls; const urls = coin.backends[0].urls;
let web3host: string = urls[0]; let web3host: string = urls[0];
@ -77,7 +77,7 @@ export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod {
if (currentHostIndex + 1 < urls.length) { if (currentHostIndex + 1 < urls.length) {
web3host = urls[currentHostIndex + 1]; web3host = urls[currentHostIndex + 1];
} else { } else {
console.error("TODO: Backend " + coinName + " not working"); console.error("TODO: Backend " + network + " not working");
// try next coin // try next coin
dispatch( init(web3, coinIndex + 1) ); dispatch( init(web3, coinIndex + 1) );
return; return;
@ -111,7 +111,7 @@ export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod {
dispatch({ dispatch({
type: WEB3.CREATE, type: WEB3.CREATE,
name: coinName, network,
web3: instance, web3: instance,
erc20, erc20,
chainId: instance.version.network chainId: instance.version.network
@ -119,7 +119,7 @@ export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod {
dispatch({ dispatch({
type: WEB3.GAS_PRICE_UPDATED, type: WEB3.GAS_PRICE_UPDATED,
coin: coinName, network,
gasPrice gasPrice
}); });
@ -154,21 +154,21 @@ export function init(web3: ?Web3, coinIndex: number = 0): ActionMethod {
if (blockHash) { if (blockHash) {
dispatch({ dispatch({
type: WEB3.BLOCK_UPDATED, type: WEB3.BLOCK_UPDATED,
name: coinName, network,
blockHash blockHash
}); });
} }
// TODO: filter only current device // TODO: filter only current device
const accounts = getState().accounts.filter(a => a.coin === coinName); const accounts = getState().accounts.filter(a => a.network === network);
for (const addr of accounts) { for (const addr of accounts) {
dispatch( getBalance(addr) ); dispatch( getBalance(addr) );
dispatch( getNonce(addr) ); dispatch( getNonce(addr) );
} }
dispatch( getGasPrice(coinName) ); dispatch( getGasPrice(network) );
const pending = getState().pending.filter(p => p.coin === coinName); const pending = getState().pending.filter(p => p.network === network);
for (const tx of pending) { for (const tx of pending) {
dispatch( getTransactionReceipt(tx) ); dispatch( getTransactionReceipt(tx) );
} }
@ -236,19 +236,17 @@ export function initContracts(): ActionMethod {
} }
export function getGasPrice(coinName: string): ActionMethod { export function getGasPrice(network: string): ActionMethod {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const index: number = getState().web3.findIndex(w3 => { const index: number = getState().web3.findIndex(w3 => w3.network === network);
return w3.coin === coinName;
});
const web3 = getState().web3[ index ].web3; const web3 = getState().web3[ index ].web3;
web3.eth.getGasPrice((error, gasPrice) => { web3.eth.getGasPrice((error, gasPrice) => {
if (!error) { if (!error) {
dispatch({ dispatch({
type: WEB3.GAS_PRICE_UPDATED, type: WEB3.GAS_PRICE_UPDATED,
coin: coinName, network: network,
gasPrice gasPrice
}); });
} }
@ -259,7 +257,7 @@ export function getGasPrice(coinName: string): ActionMethod {
export function getBalance(addr: Address): ActionMethod { export function getBalance(addr: Address): ActionMethod {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const web3instance = getState().web3.filter(w3 => w3.coin === addr.coin)[0]; const web3instance = getState().web3.filter(w3 => w3.network === addr.network)[0];
const web3 = web3instance.web3; const web3 = web3instance.web3;
web3.eth.getBalance(addr.address, (error, balance) => { web3.eth.getBalance(addr.address, (error, balance) => {
@ -269,7 +267,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, network: addr.network,
balance: newBalance balance: newBalance
}); });
@ -284,7 +282,7 @@ export function getNonce(addr: Address) {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const web3instance = getState().web3.filter(w3 => w3.coin === addr.coin)[0]; const web3instance = getState().web3.filter(w3 => w3.network === addr.network)[0];
const web3 = web3instance.web3; const web3 = web3instance.web3;
web3.eth.getTransactionCount(addr.address, (error, result) => { web3.eth.getTransactionCount(addr.address, (error, result) => {
@ -293,7 +291,7 @@ export function getNonce(addr: Address) {
dispatch({ dispatch({
type: ADDRESS.SET_NONCE, type: ADDRESS.SET_NONCE,
address: addr.address, address: addr.address,
coin: addr.coin, network: addr.network,
nonce: result nonce: result
}); });
} }
@ -305,7 +303,7 @@ export function getNonce(addr: Address) {
export function getTransactionReceipt(tx: any): any { export function getTransactionReceipt(tx: any): any {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const web3instance = getState().web3.filter(w3 => w3.coin === tx.coin)[0]; const web3instance = getState().web3.filter(w3 => w3.network === tx.network)[0];
const web3 = web3instance.web3; const web3 = web3instance.web3;
//web3.eth.getTransactionReceipt(txid, (error, tx) => { //web3.eth.getTransactionReceipt(txid, (error, tx) => {

@ -6,9 +6,9 @@ import { findSelectedDevice } from '../../reducers/TrezorConnectReducer';
const ConfirmAddress = (props: any): any => { const ConfirmAddress = (props: any): any => {
const account = props.accounts.find(a => a.checksum === props.receive.checksum && a.index === props.receive.accountIndex && a.coin === props.receive.coin); const account = props.accounts.find(a => a.deviceState === props.receive.deviceState && a.index === props.receive.accountIndex && a.network === props.receive.network);
const { config } = props.localStorage; const { config } = props.localStorage;
const selectedCoin = config.coins.find(c => c.network === account.coin); const selectedCoin = config.coins.find(c => c.network === account.network);
return ( return (
<div className="confirm-address"> <div className="confirm-address">
@ -27,7 +27,7 @@ export default ConfirmAddress;
export const ConfirmUnverifiedAddress = (props: any): any => { export const ConfirmUnverifiedAddress = (props: any): any => {
const account = props.accounts.find(a => a.checksum === props.receive.checksum && a.index === props.receive.accountIndex && a.coin === props.receive.coin); const account = props.accounts.find(a => a.deviceState === props.receive.deviceState && a.index === props.receive.accountIndex && a.network === props.receive.network);
const { const {
onCancel onCancel

@ -7,7 +7,7 @@ const Confirmation = (props): any => {
const { const {
amount, amount,
address, address,
coin, network,
coinSymbol, coinSymbol,
token, token,
total, total,

@ -16,15 +16,14 @@ export default class Receive extends AbstractAccount {
const _render = (props: any): any => { const _render = (props: any): any => {
const { const {
checksum, deviceState,
accountIndex, accountIndex,
coin,
addressVerified, addressVerified,
addressUnverified, addressUnverified,
} = props.receive; } = props.receive;
const device = props.devices.find(d => d.checksum === checksum); const device = props.devices.find(d => d.state === deviceState);
const account = props.accounts.find(a => a.checksum === checksum && a.index === accountIndex && a.coin === coin); const account = props.accounts.find(a => a.deviceState === deviceState && a.index === accountIndex && a.network === network);
let qrCode = null; let qrCode = null;
let address = `${account.address.substring(0, 20)}...`; let address = `${account.address.substring(0, 20)}...`;

@ -22,13 +22,13 @@ export default class AbstractAccount extends Component {
const props = this.props; const props = this.props;
if (!state.checksum) { if (!state.deviceState) {
return (<section></section>); return (<section></section>);
} }
const device = this.props.devices.find(d => d.checksum === state.checksum); const device = this.props.devices.find(d => d.state === state.deviceState);
const discovery = props.discovery.find(d => d.checksum === device.checksum && d.coin === state.coin); const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === state.network);
const account = props.accounts.find(a => a.checksum === state.checksum && a.index === state.accountIndex && a.coin === state.coin); const account = props.accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);
if (!account) { if (!account) {
if (!discovery || discovery.waitingForDevice) { if (!discovery || discovery.waitingForDevice) {

@ -71,7 +71,7 @@ const AccountTabs = (props: any): any => {
const urlParams = props.match.params; const urlParams = props.match.params;
//const urlParams = props.match ? props.match.params : { address: '0' }; //const urlParams = props.match ? props.match.params : { address: '0' };
const basePath = `/device/${urlParams.device}/coin/${urlParams.coin}/address/${urlParams.address}`; const basePath = `/device/${urlParams.device}/network/${urlParams.network}/address/${urlParams.address}`;
return ( return (
<div className="account-tabs"> <div className="account-tabs">

@ -21,15 +21,15 @@ const AccountSelection = (props: any): any => {
const baseUrl: string = `/device/${location.params.device}`; const baseUrl: string = `/device/${location.params.device}`;
const { config } = props.localStorage; const { config } = props.localStorage;
const selectedCoin = config.coins.find(c => c.network === location.params.coin); const selectedCoin = config.coins.find(c => c.network === location.params.network);
const fiatRate = props.fiat.find(f => f.network === selectedCoin.network); const fiatRate = props.fiat.find(f => f.network === selectedCoin.network);
// console.warn("AccountSelectionRender", selected, props); // console.warn("AccountSelectionRender", selected, props);
const deviceAddresses: Array<any> = getAccounts(accounts, selected, location.params.coin); const deviceAddresses: Array<any> = getAccounts(accounts, selected, location.params.network);
let selectedAccounts = deviceAddresses.map((address, i) => { let selectedAccounts = deviceAddresses.map((address, i) => {
// const url: string = `${baseUrl}/coin/${location.params.coin}/address/${i}`; // const url: string = `${baseUrl}/network/${location.params.network}/address/${i}`;
const url: string = location.pathname.replace(/address+\/([0-9]*)/, `address/${i}`); const url: string = location.pathname.replace(/address+\/([0-9]*)/, `address/${i}`);
let balance: string = 'Loading...'; let balance: string = 'Loading...';
@ -64,7 +64,7 @@ const AccountSelection = (props: any): any => {
} }
let discoveryStatus = null; let discoveryStatus = null;
const discovery = props.discovery.find(d => d.checksum === selected.checksum && d.coin === location.params.coin); const discovery = props.discovery.find(d => d.deviceState === selected.state && d.network === location.params.network);
if (discovery) { if (discovery) {
if (discovery.completed) { if (discovery.completed) {

@ -52,7 +52,7 @@ const Aside = (props: any): any => {
if (props.deviceDropdownOpened) { if (props.deviceDropdownOpened) {
menu = <DeviceDropdown {...props} />; menu = <DeviceDropdown {...props} />;
} else if (location.params.coin) { } else if (location.params.network) {
menu = ( menu = (
<TransitionMenu animationType={"slide-left"}> <TransitionMenu animationType={"slide-left"}>
<AccountSelection { ...props} /> <AccountSelection { ...props} />

@ -9,7 +9,7 @@ const CoinSelection = (props: any): any => {
const { config } = props.localStorage; const { config } = props.localStorage;
const walletCoins = config.coins.map(item => { const walletCoins = config.coins.map(item => {
const url = `${ location.pathname }/coin/${ item.network }/address/0`; const url = `${ location.pathname }/network/${ item.network }/address/0`;
const className = `coin ${ item.network }` const className = `coin ${ item.network }`
return ( return (
<NavLink key={ item.network } to={ url } className={ className }> <NavLink key={ item.network } to={ url } className={ className }>

@ -7,7 +7,7 @@ import Tooltip from 'rc-tooltip';
const AdvancedForm = (props: any): any => { const AdvancedForm = (props: any): any => {
const { const {
coin, network,
token, token,
gasPrice, gasPrice,
gasLimit, gasLimit,
@ -115,7 +115,7 @@ const AdvancedForm = (props: any): any => {
<span className="what-is-it"></span> <span className="what-is-it"></span>
</Tooltip> </Tooltip>
</label> </label>
<textarea disabled={ coin !== token } value={ coin !== token ? '' : data } onChange={ event => onDataChange(event.target.value) }></textarea> <textarea disabled={ network !== token } value={ network !== token ? '' : data } onChange={ event => onDataChange(event.target.value) }></textarea>
{ errors.data ? (<span className="error">{ errors.data }</span>) : null } { errors.data ? (<span className="error">{ errors.data }</span>) : null }
</div> </div>

@ -7,8 +7,8 @@ import ScaleText from 'react-scale-text';
const PendingTransactions = (props: any): any => { const PendingTransactions = (props: any): any => {
const account = props.accounts.find(a => a.checksum === props.sendForm.checksum && a.index === props.sendForm.accountIndex && a.coin === props.sendForm.coin); const account = props.accounts.find(a => a.deviceState === props.sendForm.deviceState && a.index === props.sendForm.accountIndex && a.network === props.sendForm.network);
const pending = props.pending.filter(p => p.coin === account.coin && p.address === account.address); const pending = props.pending.filter(p => p.network === account.network && p.address === account.address);
if (pending.length < 1) return null; if (pending.length < 1) return null;
@ -21,7 +21,7 @@ const PendingTransactions = (props: any): any => {
let iconColor, symbol, name; let iconColor, symbol, name;
if (tx.token !== tx.coin) { if (tx.token !== tx.network) {
const token = tokens.find(t => t.symbol === tx.token); const token = tokens.find(t => t.symbol === tx.token);
iconColor = { iconColor = {
color: textColor.hex(token.name), color: textColor.hex(token.name),
@ -32,9 +32,9 @@ const PendingTransactions = (props: any): any => {
name = token.name; name = token.name;
} else { } else {
iconColor = { iconColor = {
color: textColor.hex(tx.coin), color: textColor.hex(tx.network),
background: bgColor.hex(tx.coin), background: bgColor.hex(tx.network),
borderColor: bgColor.hex(tx.coin) borderColor: bgColor.hex(tx.network)
} }
symbol = props.selectedCoin.symbol; symbol = props.selectedCoin.symbol;
name = props.selectedCoin.name; name = props.selectedCoin.name;

@ -18,16 +18,16 @@ export default class Send extends AbstractAccount {
const _render = (props: any): any => { const _render = (props: any): any => {
const device = props.devices.find(d => d.checksum === props.sendForm.checksum); const device = props.devices.find(device => device.state === props.sendForm.deviceState);
const discovery = props.discovery.find(d => d.checksum === device.checksum && d.coin === props.sendForm.coin); const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === props.sendForm.network);
const account = props.accounts.find(a => a.checksum === props.sendForm.checksum && a.index === props.sendForm.accountIndex && a.coin === props.sendForm.coin); const account = props.accounts.find(a => a.deviceState === props.sendForm.deviceState && a.index === props.sendForm.accountIndex && a.network === props.sendForm.network);
const addressTokens = props.tokens.filter(t => t.ethAddress === account.address); const addressTokens = props.tokens.filter(t => t.ethAddress === account.address);
const { const {
address, address,
amount, amount,
setMax, setMax,
coin, network,
coinSymbol, coinSymbol,
token, token,
feeLevels, feeLevels,
@ -53,7 +53,7 @@ const _render = (props: any): any => {
} = props.sendFormActions; } = props.sendFormActions;
const { config } = props.localStorage; const { config } = props.localStorage;
const selectedCoin = config.coins.find(c => c.network === coin); const selectedCoin = config.coins.find(c => c.network === network);
const fiatRate = props.fiat.find(f => f.network === selectedCoin.network); const fiatRate = props.fiat.find(f => f.network === selectedCoin.network);
const tokens = addressTokens.map(t => { const tokens = addressTokens.map(t => {
@ -81,13 +81,12 @@ const _render = (props: any): any => {
let buttonDisabled: boolean = Object.keys(errors).length > 0 || total === '0' || amount.length === 0 || address.length === 0 || sending; let buttonDisabled: boolean = Object.keys(errors).length > 0 || total === '0' || amount.length === 0 || address.length === 0 || sending;
let buttonLabel: string = 'Send'; let buttonLabel: string = 'Send';
if (coin !== token && amount.length > 0 && !errors.amount) { if (network !== token && amount.length > 0 && !errors.amount) {
buttonLabel += ` ${amount} ${ token.toUpperCase() }` buttonLabel += ` ${amount} ${ token.toUpperCase() }`
} else if (coin === token && total !== '0') { } else if (network === token && total !== '0') {
buttonLabel += ` ${total} ${ selectedCoin.symbol }`; buttonLabel += ` ${total} ${ selectedCoin.symbol }`;
} }
//const device = props.devices.find(d => d.checksum === currentAccount.checksum);
if (device && !device.connected) { if (device && !device.connected) {
buttonLabel = 'Device is not connected'; buttonLabel = 'Device is not connected';
buttonDisabled = true; buttonDisabled = true;

@ -19,9 +19,9 @@ export default class Summary extends AbstractAccount {
const _render = (props: any): any => { const _render = (props: any): any => {
const device = props.devices.find(d => d.checksum === props.summary.checksum); const device = props.devices.find(d => d.state === props.summary.deviceState);
const discovery = props.discovery.find(d => d.checksum === device.checksum && d.coin === props.summary.coin); const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === props.summary.network);
const account = props.accounts.find(a => a.checksum === props.summary.checksum && a.index === props.summary.accountIndex && a.coin === props.summary.coin); const account = props.accounts.find(a => a.deviceState === props.summary.deviceState && a.index === props.summary.accountIndex && a.network === props.summary.network);
const tokens = props.tokens.filter(t => t.ethAddress === account.address); const tokens = props.tokens.filter(t => t.ethAddress === account.address);
return ( return (
@ -31,12 +31,12 @@ const _render = (props: any): any => {
<Notification className="info" title={ `Device ${ device.instanceLabel } is disconnected` } /> <Notification className="info" title={ `Device ${ device.instanceLabel } is disconnected` } />
) : null } ) : null }
<h2 className={ `summary-header ${props.summary.coin}` }>Address #{ parseInt(props.match.params.address) + 1 }</h2> <h2 className={ `summary-header ${props.summary.network}` }>Address #{ parseInt(props.match.params.address) + 1 }</h2>
<SummaryDetails <SummaryDetails
summary={ props.summary } summary={ props.summary }
balance={ account.balance } balance={ account.balance }
coin={ props.summary.coin } network={ props.summary.network }
fiat={ props.fiat } fiat={ props.fiat }
localStorage={ props.localStorage } localStorage={ props.localStorage }
onToggle={ props.summaryActions.onDetailsToggle } /> onToggle={ props.summaryActions.onDetailsToggle } />

@ -13,7 +13,7 @@ const SummaryDetails = (props: any): any => {
); );
const { config } = props.localStorage; const { config } = props.localStorage;
const selectedCoin = config.coins.find(c => c.network === props.coin); const selectedCoin = config.coins.find(c => c.network === props.network);
const fiatRate = props.fiat.find(f => f.network === selectedCoin.network); const fiatRate = props.fiat.find(f => f.network === selectedCoin.network);
let balanceColumn = null; let balanceColumn = null;

@ -19,7 +19,7 @@ const Article = (props) => {
return ( return (
<article> <article>
<nav> <nav>
<Route path="/device/:device/coin/:coin/address/:address" component={ AccountTabs } /> <Route path="/device/:device/network/:network/address/:address" component={ AccountTabs } />
</nav> </nav>
<Notifications /> <Notifications />
<Log /> <Log />

@ -6,15 +6,15 @@ import * as CONNECT from '../actions/constants/TrezorConnect';
export type State = { export type State = {
+index: number; +index: number;
+checksum: ?string; +ch: ?string;
+coin: string; +network: string;
location: string; location: string;
} }
export const initialState: State = { export const initialState: State = {
index: 0, index: 0,
checksum: null, deviceState: null,
coin: '', network: '',
}; };

@ -6,8 +6,9 @@ import * as ADDRESS from '../actions/constants/Address';
export type Account = { export type Account = {
loaded: boolean; loaded: boolean;
+checksum: string; +network: string;
+coin: string; +deviceID: string;
+deviceState: ?string;
+index: number; +index: number;
+addressPath: Array<number>; +addressPath: Array<number>;
+address: string; +address: string;
@ -21,15 +22,17 @@ const createAccount = (state: Array<Account>, action: any): Array<Account> => {
// TODO check with device_id // 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 && addr.coin === action.coin); const exist: ?Account = state.find((account: Account) => account.address === action.address && account.network === action.network && account.deviceID === action.device.features.device_id);
console.warn("MAM?", exist, action)
if (exist) { if (exist) {
return state; return state;
} }
const address: Account = { const address: Account = {
loaded: false, loaded: false,
checksum: action.device.checksum, network: action.network,
coin: action.coin, deviceID: action.device.features.device_id,
deviceState: action.device.state,
index: action.index, index: action.index,
addressPath: action.path, addressPath: action.path,
address: action.address, address: action.address,
@ -43,16 +46,15 @@ const createAccount = (state: Array<Account>, action: any): Array<Account> => {
} }
const removeAccounts = (state: Array<Account>, action: any): Array<Account> => { const removeAccounts = (state: Array<Account>, action: any): Array<Account> => {
// TODO: all instances od device (multiple checksums) return state.filter(account => account.deviceID !== action.device.features.device_id);
return state.filter(addr => addr.checksum !== action.device.checksum);
} }
const forgetAccounts = (state: Array<Account>, action: any): Array<Account> => { const forgetAccounts = (state: Array<Account>, action: any): Array<Account> => {
return state.filter(addr => action.accounts.indexOf(addr) === -1); return state.filter(account => action.accounts.indexOf(account) === -1);
} }
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 && addr.coin === action.coin); const index: number = state.findIndex(account => account.address === action.address && account.network === action.network);
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 +62,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 && addr.coin === action.coin); const index: number = state.findIndex(account => account.address === action.address && account.network === action.network);
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;

@ -6,8 +6,8 @@ import * as ADDRESS from '../actions/constants/Address';
import * as CONNECT from '../actions/constants/TrezorConnect'; import * as CONNECT from '../actions/constants/TrezorConnect';
export type Discovery = { export type Discovery = {
coin: string; network: string;
checksum: string; deviceState: string;
xpub: string; xpub: string;
accountIndex: number; accountIndex: number;
interrupted: boolean; interrupted: boolean;
@ -18,14 +18,18 @@ export type Discovery = {
const initialState: Array<Discovery> = []; const initialState: Array<Discovery> = [];
const findIndex = (state: Array<Discovery>, network: string, deviceState: string): number => {
return state.findIndex(d => d.network === network && d.deviceState === deviceState);
}
const start = (state: Array<Discovery>, action: any): Array<Discovery> => { const start = (state: Array<Discovery>, action: any): Array<Discovery> => {
const instance: Discovery = { const instance: Discovery = {
coin: action.coin, network: action.network,
xpub: action.xpub, xpub: action.xpub,
hdKey: action.hdKey, hdKey: action.hdKey,
basePath: action.basePath, basePath: action.basePath,
checksum: action.device.checksum, deviceState: action.device.state,
accountIndex: 0, accountIndex: 0,
interrupted: false, interrupted: false,
completed: false, completed: false,
@ -33,12 +37,7 @@ const start = (state: Array<Discovery>, action: any): Array<Discovery> => {
} }
const newState: Array<Discovery> = [ ...state ]; const newState: Array<Discovery> = [ ...state ];
const index: number = state.findIndex(d => { const index: number = findIndex(state, action.network, action.device.state);
return d.coin === action.coin && d.checksum === action.device.checksum;
});
console.warn("START DISCO", index);
if (index >= 0) { if (index >= 0) {
newState[index] = instance; newState[index] = instance;
} else { } else {
@ -48,31 +47,27 @@ const start = (state: Array<Discovery>, action: any): Array<Discovery> => {
} }
const complete = (state: Array<Discovery>, action: any): Array<Discovery> => { const complete = (state: Array<Discovery>, action: any): Array<Discovery> => {
const index: number = state.findIndex(d => { const index: number = findIndex(state, action.network, action.device.state);
return d.coin === action.coin && d.checksum === action.device.checksum;
});
const newState: Array<Discovery> = [ ...state ]; const newState: Array<Discovery> = [ ...state ];
newState[index].completed = true; newState[index].completed = true;
return newState; return newState;
} }
const addressCreate = (state: Array<Discovery>, action: any): Array<Discovery> => { const addressCreate = (state: Array<Discovery>, action: any): Array<Discovery> => {
const index: number = state.findIndex(d => { const index: number = findIndex(state, action.network, action.device.state);
return d.coin === action.coin && d.checksum === action.device.checksum;
});
const newState: Array<Discovery> = [ ...state ]; const newState: Array<Discovery> = [ ...state ];
newState[index].accountIndex++; newState[index].accountIndex++;
return newState; return newState;
} }
const forgetDiscovery = (state: Array<Discovery>, action: any): Array<Discovery> => { const forgetDiscovery = (state: Array<Discovery>, action: any): Array<Discovery> => {
return state.filter(d => d.checksum !== action.device.checksum); return state.filter(d => d.deviceState !== action.device.state);
} }
const stop = (state: Array<Discovery>, action: any): Array<Discovery> => { const stop = (state: Array<Discovery>, action: any): Array<Discovery> => {
const newState: Array<Discovery> = [ ...state ]; const newState: Array<Discovery> = [ ...state ];
return newState.map( (d: Discovery) => { return newState.map( (d: Discovery) => {
if (d.checksum === action.device.checksum && !d.completed) { if (d.deviceState === action.device.state && !d.completed) {
d.interrupted = true; d.interrupted = true;
d.waitingForDevice = false; d.waitingForDevice = false;
} }
@ -83,8 +78,8 @@ const stop = (state: Array<Discovery>, action: any): Array<Discovery> => {
const waiting = (state: Array<Discovery>, action: any): Array<Discovery> => { const waiting = (state: Array<Discovery>, action: any): Array<Discovery> => {
const instance: Discovery = { const instance: Discovery = {
coin: action.coin, network: action.network,
checksum: action.device.checksum, deviceState: action.device.state,
xpub: '', xpub: '',
accountIndex: 0, accountIndex: 0,
interrupted: false, interrupted: false,
@ -92,10 +87,7 @@ const waiting = (state: Array<Discovery>, action: any): Array<Discovery> => {
waitingForDevice: true waitingForDevice: true
} }
const index: number = state.findIndex(d => { const index: number = findIndex(state, action.network, action.device.state);
return d.coin === action.coin && d.checksum === action.device.checksum;
});
const newState: Array<Discovery> = [ ...state ]; const newState: Array<Discovery> = [ ...state ];
if (index >= 0) { if (index >= 0) {
newState[index] = instance; newState[index] = instance;

@ -6,7 +6,7 @@ import * as WEB3 from '../actions/constants/Web3';
export type PendingTx = { export type PendingTx = {
+id: string; +id: string;
+coin: string; +network: string;
+token: string; +token: string;
+amount: string; +amount: string;
+address: string; +address: string;
@ -18,7 +18,7 @@ const add = (state: Array<PendingTx>, action: any) => {
const newState = [ ...state ]; const newState = [ ...state ];
newState.push({ newState.push({
id: action.txid, id: action.txid,
coin: action.address.coin, network: action.address.network,
token: action.token, token: action.token,
amount: action.amount, amount: action.amount,
address: action.address.address, address: action.address.address,

@ -4,18 +4,18 @@
import * as RECEIVE from '../actions/constants/receive'; import * as RECEIVE from '../actions/constants/receive';
export type State = { export type State = {
+checksum: ?string; +deviceState: ?string;
+accountIndex: ?number; +accountIndex: ?number;
+coin: ?string; +network: ?string;
location: string; location: string;
addressVerified: boolean; addressVerified: boolean;
adressUnverified: boolean; adressUnverified: boolean;
} }
export const initialState: State = { export const initialState: State = {
checksum: null, deviceState: null,
accountIndex: null, accountIndex: null,
coin: null, network: null,
location: '', location: '',
addressVerified: false, addressVerified: false,
addressUnverified: false, addressUnverified: false,

@ -10,9 +10,9 @@ import BigNumber from 'bignumber.js';
import { getFeeLevels } from '../actions/SendFormActions'; import { getFeeLevels } from '../actions/SendFormActions';
export type State = { export type State = {
+checksum: ?string; +deviceState: ?string;
+accountIndex: number; +accountIndex: number;
+coin: string; +network: string;
+coinSymbol: string; +coinSymbol: string;
token: string; token: string;
location: string; location: string;
@ -50,9 +50,9 @@ export type FeeLevel = {
export const initialState: State = { export const initialState: State = {
checksum: null, deviceState: null,
accountIndex: 0, accountIndex: 0,
coin: '', network: '',
coinSymbol: '', coinSymbol: '',
token: '', token: '',
location: '', location: '',
@ -88,13 +88,13 @@ const onGasPriceUpdated = (state: State, action: any): State => {
} }
const newPrice = getRandomInt(10, 50).toString(); const newPrice = getRandomInt(10, 50).toString();
//const newPrice = EthereumjsUnits.convert(action.gasPrice, 'wei', 'gwei'); //const newPrice = EthereumjsUnits.convert(action.gasPrice, 'wei', 'gwei');
if (action.coin === state.coin && newPrice !== state.recommendedGasPrice) { if (action.network === state.network && newPrice !== state.recommendedGasPrice) {
const newState: State = { ...state }; const newState: State = { ...state };
if (!state.untouched) { if (!state.untouched) {
newState.gasPriceNeedsUpdate = true; newState.gasPriceNeedsUpdate = true;
newState.recommendedGasPrice = newPrice; newState.recommendedGasPrice = newPrice;
} else { } else {
const newFeeLevels = getFeeLevels(state.coin, newPrice, state.gasLimit); const newFeeLevels = getFeeLevels(state.network, newPrice, state.gasLimit);
const selectedFeeLevel = newFeeLevels.find(f => f.value === 'Normal'); const selectedFeeLevel = newFeeLevels.find(f => f.value === 'Normal');
newState.recommendedGasPrice = newPrice; newState.recommendedGasPrice = newPrice;
newState.feeLevels = newFeeLevels; newState.feeLevels = newFeeLevels;

@ -4,9 +4,9 @@
import * as SUMMARY from '../actions/constants/summary'; import * as SUMMARY from '../actions/constants/summary';
export type State = { export type State = {
+checksum: ?string; +deviceState: ?string;
+accountIndex: ?number; +accountIndex: ?number;
+coin: ?string; +network: ?string;
location: string; location: string;
details: boolean; details: boolean;
@ -14,9 +14,9 @@ export type State = {
} }
export const initialState: State = { export const initialState: State = {
checksum: null, deviceState: null,
accountIndex: null, accountIndex: null,
coin: null, network: null,
location: '', location: '',
details: true, details: true,

@ -6,7 +6,7 @@ import * as TOKEN from '../actions/constants/Token';
export type Token = { export type Token = {
loaded: boolean; loaded: boolean;
+checksum: string; +deviceState: string;
+name: string; +name: string;
+symbol: string; +symbol: string;
+address: string; +address: string;
@ -31,7 +31,7 @@ const create = (state: Array<Token>, payload: any): Array<Token> => {
const newState: Array<Token> = [ ...state ]; const newState: Array<Token> = [ ...state ];
const token: Token = { const token: Token = {
loaded: false, loaded: false,
checksum: payload.checksum, deviceState: payload.deviceState,
name: payload.name, name: payload.name,
symbol: payload.symbol, symbol: payload.symbol,
address: payload.address, address: payload.address,
@ -44,7 +44,7 @@ const create = (state: Array<Token>, payload: any): Array<Token> => {
} }
const forget = (state: Array<Token>, action: any): Array<Token> => { const forget = (state: Array<Token>, action: any): Array<Token> => {
return state.filter(t => t.checksum !== action.device.checksum); return state.filter(t => t.deviceState !== action.device.deviceState);
} }
const remove = (state: Array<Token>, action: any): Array<Token> => { const remove = (state: Array<Token>, action: any): Array<Token> => {

@ -9,7 +9,7 @@ export type TrezorDevice = {
connected: boolean; connected: boolean;
path: string; path: string;
+label: string; +label: string;
+checksum: string; +state: string;
+instance?: number; +instance?: number;
instanceLabel: string; instanceLabel: string;
features?: Object; features?: Object;
@ -81,12 +81,12 @@ const mergeDevices = (current: TrezorDevice, upcoming: Object): TrezorDevice =>
remember: typeof upcoming.remember === 'boolean' ? upcoming.remember : current.remember, remember: typeof upcoming.remember === 'boolean' ? upcoming.remember : current.remember,
instance: current.instance, instance: current.instance,
instanceLabel: current.instanceLabel, instanceLabel: current.instanceLabel,
checksum: current.checksum, state: current.state,
acquiring: typeof upcoming.acquiring === 'boolean' ? upcoming.acquiring : current.acquiring, acquiring: typeof upcoming.acquiring === 'boolean' ? upcoming.acquiring : current.acquiring,
ts: new Date().getTime(), ts: new Date().getTime(),
} }
if (upcoming.unacquired && current.checksum) { if (upcoming.unacquired && current.state) {
dev.instanceLabel = current.instanceLabel; dev.instanceLabel = current.instanceLabel;
dev.features = current.features; dev.features = current.features;
dev.label = current.label; dev.label = current.label;
@ -135,7 +135,7 @@ const addDevice = (state: State, device: Object): State => {
connected: true, connected: true,
path: device.path, path: device.path,
label: device.label, label: device.label,
checksum: null, state: null,
// instance: 0, // instance: 0,
instanceLabel: device.label, instanceLabel: device.label,
ts: 0, ts: 0,
@ -157,7 +157,7 @@ const setDeviceState = (state: State, action: any): State => {
if (index > -1) { if (index > -1) {
const changedDevice: TrezorDevice = { const changedDevice: TrezorDevice = {
...newState.devices[index], ...newState.devices[index],
checksum: action.checksum state: action.state
}; };
newState.devices[index] = changedDevice; newState.devices[index] = changedDevice;
//newState.selectedDevice = changedDevice; //newState.selectedDevice = changedDevice;
@ -219,7 +219,7 @@ const disconnectDevice = (state: State, device: Object): State => {
const otherDevices: Array<TrezorDevice> = state.devices.filter(d => affectedDevices.indexOf(d) === -1); const otherDevices: Array<TrezorDevice> = state.devices.filter(d => affectedDevices.indexOf(d) === -1);
if (affectedDevices.length > 0) { if (affectedDevices.length > 0) {
const acquiredDevices = affectedDevices.filter(d => !d.unacquired && d.checksum); const acquiredDevices = affectedDevices.filter(d => !d.unacquired && d.state);
newState.devices = otherDevices.concat( acquiredDevices.map(d => { newState.devices = otherDevices.concat( acquiredDevices.map(d => {
d.connected = false; d.connected = false;
d.isUsedElsewhere = false; d.isUsedElsewhere = false;
@ -276,7 +276,7 @@ const duplicate = (state: State, device: any): State => {
// if (affectedDevices.length > 0) { // if (affectedDevices.length > 0) {
const newDevice: TrezorDevice = { const newDevice: TrezorDevice = {
...device, ...device,
checksum: null, state: null,
remember: device.remember, remember: device.remember,
connected: device.connected, connected: device.connected,
path: device.path, path: device.path,

@ -8,7 +8,7 @@ const WIDTH: number = 1080;
const HEIGHT: number = 1920; const HEIGHT: number = 1920;
type State = { type State = {
coin: string; network: string;
device: string; device: string;
} }

@ -1,70 +0,0 @@
/* @flow */
'use strict';
import Web3 from 'web3';
import { UI, DEVICE } from 'trezor-connect';
import * as ACTIONS from '../actions';
import * as STORAGE from '../actions/constants/LocalStorage';
import * as WEB3 from '../actions/constants/Web3';
type State = {
web3: Web3;
url: Array<string>;
customUrl: string;
tokens: JSON;
abi: JSON;
gasPrice: any;
latestBlock: any;
fiatRate: ?string;
}
const initialState: State = {
web3: null,
url: [
'https://ropsten.infura.io/QGyVKozSUEh2YhL4s2G4',
'https://api.myetherapi.com/rop',
'https://pyrus2.ubiqscan.io',
],
customUrl: 's',
gasPrice: 0,
latestBlock: 0,
};
export default function web3(state: State = initialState, action: any): any {
switch (action.type) {
case 'rate__update' :
return {
...state,
fiatRate: action.rate.price_usd
}
case STORAGE.READY :
return {
...state,
tokens: action.tokens,
abi: action.abi
}
case WEB3.READY :
return {
...state,
web3: action.web3
}
case WEB3.BLOCK_UPDATED :
return {
...state,
latestBlock: action.blockHash
}
case WEB3.GAS_PRICE_UPDATED :
return {
...state,
gasPrice: action.gasPrice
}
default:
return state;
}
}

@ -7,7 +7,7 @@ import * as STORAGE from '../actions/constants/LocalStorage';
import * as WEB3 from '../actions/constants/Web3'; import * as WEB3 from '../actions/constants/Web3';
type Web3Instance = { type Web3Instance = {
coin: string; network: string;
web3: Web3; web3: Web3;
chainId: number; chainId: number;
latestBlock: any; latestBlock: any;
@ -19,7 +19,7 @@ const initialState: Array<Web3Instance> = [];
const createWeb3 = (state: Array<Web3Instance>, action: any): Array<Web3Instance> => { const createWeb3 = (state: Array<Web3Instance>, action: any): Array<Web3Instance> => {
const instance: Web3Instance = { const instance: Web3Instance = {
coin: action.name, network: action.network,
web3: action.web3, web3: action.web3,
chainId: parseInt(action.chainId), chainId: parseInt(action.chainId),
latestBlock: '0', latestBlock: '0',
@ -32,18 +32,14 @@ const createWeb3 = (state: Array<Web3Instance>, action: any): Array<Web3Instance
} }
const updateLatestBlock = (state: Array<Web3Instance>, action: any): Array<Web3Instance> => { const updateLatestBlock = (state: Array<Web3Instance>, action: any): Array<Web3Instance> => {
const index: number = state.findIndex(w3 => { const index: number = state.findIndex(w3 => w3.network === action.network);
return w3.coin === action.name;
});
const newState: Array<Web3Instance> = [ ...state ]; const newState: Array<Web3Instance> = [ ...state ];
newState[index].latestBlock = action.blockHash; newState[index].latestBlock = action.blockHash;
return newState; return newState;
} }
const updateGasPrice = (state: Array<Web3Instance>, action: any): Array<Web3Instance> => { const updateGasPrice = (state: Array<Web3Instance>, action: any): Array<Web3Instance> => {
const index: number = state.findIndex(w3 => { const index: number = state.findIndex(w3 => w3.network === action.network);
return w3.coin === action.coin;
});
const newState: Array<Web3Instance> = [ ...state ]; const newState: Array<Web3Instance> = [ ...state ];
newState[index].gasPrice = action.gasPrice; newState[index].gasPrice = action.gasPrice;
return newState; return newState;

@ -35,14 +35,14 @@ export default (
<Route> <Route>
<WalletContainer> <WalletContainer>
<Route exact path="/device/:device/" component={ DashboardContainer } /> <Route exact path="/device/:device/" component={ DashboardContainer } />
<Route exact path="/device/:device/coin/:coin" component={ DashboardContainer } /> <Route exact path="/device/:device/network/:network" component={ DashboardContainer } />
<Route exact path="/device/:device/acquire" component={ AcquireContainer } /> <Route exact path="/device/:device/acquire" component={ AcquireContainer } />
<Route exact path="/device/:device/bootloader" component={ BootloaderContainer } /> <Route exact path="/device/:device/bootloader" component={ BootloaderContainer } />
<Route exact path="/device/:device/coin/:coin/address/:address" component={ SummaryContainer } /> <Route exact path="/device/:device/network/:network/address/:address" component={ SummaryContainer } />
<Route path="/device/:device/coin/:coin/address/:address/send" component={ SendFormContainer } /> <Route path="/device/:device/network/:network/address/:address/send" component={ SendFormContainer } />
<Route path="/device/:device/coin/:coin/address/:address/send/override" component={ SendFormContainer } /> <Route path="/device/:device/network/:network/address/:address/send/override" component={ SendFormContainer } />
<Route path="/device/:device/coin/:coin/address/:address/receive" component={ ReceiveContainer } /> <Route path="/device/:device/network/:network/address/:address/receive" component={ ReceiveContainer } />
<Route path="/device/:device/coin/:coin/address/:address/signverify" component={ SignVerifyContainer } /> <Route path="/device/:device/network/:network/address/:address/signverify" component={ SignVerifyContainer } />
{/* <Route path="/device/:device/address/:address/history" component={ HistoryContainer } /> */} {/* <Route path="/device/:device/address/:address/history" component={ HistoryContainer } /> */}
</WalletContainer> </WalletContainer>

@ -20,7 +20,7 @@ import * as WEB3 from '../actions/constants/Web3';
const findAccounts = (devices, accounts) => { const findAccounts = (devices, accounts) => {
return devices.reduce((arr, dev) => { return devices.reduce((arr, dev) => {
return arr.concat(accounts.filter(a => a.checksum === dev.checksum)); return arr.concat(accounts.filter(a => a.deviceState === dev.state));
}, []); }, []);
} }
@ -32,7 +32,7 @@ const findTokens = (accounts, tokens) => {
const findDiscovery = (devices, discovery) => { const findDiscovery = (devices, discovery) => {
return devices.reduce((arr, dev) => { return devices.reduce((arr, dev) => {
return arr.concat(discovery.filter(a => a.checksum === dev.checksum)); return arr.concat(discovery.filter(a => a.deviceState === dev.state));
}, []); }, []);
} }

@ -48,9 +48,9 @@ const validation = (store: any, params: UrlParams): boolean => {
if (!device) return false; if (!device) return false;
} }
if (params.hasOwnProperty('coin')) { if (params.hasOwnProperty('network')) {
const { config } = store.getState().localStorage; const { config } = store.getState().localStorage;
const coin = config.coins.find(c => c.network === params.coin); const coin = config.coins.find(coin => coin.network === params.network);
if (!coin) return false; if (!coin) return false;
if (!params.address) return false; if (!params.address) return false;
} }
@ -84,7 +84,7 @@ const RouterService = (store: any) => (next: any) => (action: any) => {
initSearch: action.payload.search initSearch: action.payload.search
} }
// check if there are initial parameters in url (coin) // check if there are initial parameters in url (network/ device / account)
if (action.payload.search.length > 0) { if (action.payload.search.length > 0) {
// save it in WalletReducer, after device detection will redirect to this request // save it in WalletReducer, after device detection will redirect to this request
redirectPath = '/'; redirectPath = '/';
@ -125,11 +125,11 @@ const RouterService = (store: any) => (next: any) => (action: any) => {
}); });
} }
if (requestedParams.coin !== currentParams.coin) { if (requestedParams.network !== currentParams.network) {
store.dispatch({ store.dispatch({
type: CONNECT.COIN_CHANGED, type: CONNECT.COIN_CHANGED,
payload: { payload: {
coin: requestedParams.coin network: requestedParams.network
} }
}); });
} }

@ -1,219 +0,0 @@
/* @flow */
'use strict';
import { LOCATION_CHANGE, push } from 'react-router-redux';
import TrezorConnect, { TRANSPORT, DEVICE_EVENT, UI_EVENT, UI, DEVICE } from 'trezor-connect';
import * as TrezorConnectActions from '../actions/TrezorConnectActions';
import * as ModalActions from '../actions/ModalActions';
import { init as initWeb3 } from '../actions/Web3Actions';
import * as WEB3 from '../actions/constants/Web3';
import * as STORAGE from '../actions/constants/LocalStorage';
import * as CONNECT from '../actions/constants/TrezorConnect';
const initSelectedDevice = async (store: any, device: any): void => {
const { selectedDevice } = store.getState().connect;
console.log("WHATSUP?", device, selectedDevice)
// if we are in LandingPage view switch it to Wallet
if (selectedDevice && selectedDevice.path === device.path && selectedDevice.instance === device.instance) {
if (selectedDevice.unacquired || selectedDevice.isUsedElsewhere) {
store.dispatch( push(`/device/${ selectedDevice.path }/acquire`) );
} else {
if (device.features.bootloader_mode) {
store.dispatch( push(`/device/${ selectedDevice.path }/bootloader`) );
} else {
if (device.instance) {
store.dispatch( push(`/device/${ device.features.device_id }:${ device.instance }`) );
} else {
store.dispatch( push(`/device/${ device.features.device_id }`) );
}
// if (!selectedDevice.initialized && selectedDevice.connected) {
// const response = await TrezorConnect.getPublicKey({
// selectedDevice: selectedDevice.path,
// instance: selectedDevice.instance,
// path: "m/1'/0'/0'",
// confirmation: false
// });
// if (response && response.success) {
// const xpub = response.payload.xpub;
// store.dispatch({
// type: CONNECT.AUTH_DEVICE,
// device: selectedDevice,
// xpub
// });
// } else {
// // TODO: error
// }
// console.log("INIT SELECTED!", device, response)
// }
//store.dispatch( push(`/device/${ device.features.device_id }/coin/eth/address/0/send`) );
//store.dispatch( push(`/device/${ device.features.device_id }/coin/eth/address/0`) );
// store.dispatch( push(`/device/${ device.features.device_id }`) );
// store.dispatch( TrezorConnectActions.startDiscoveryProcess(device) );
// get xpub to force
}
}
}
}
const TrezorConnectService = (store: any) => (next: any) => (action: any) => {
if (action.type === DEVICE.DISCONNECT) {
const previous = store.getState().connect.selectedDevice;
next(action);
if (previous && action.device.path === previous.path) {
if (previous.unacquired) {
} else if (previous.initialized) {
// interrupt discovery process
store.dispatch( TrezorConnectActions.stopDiscoveryProcess(previous) );
if (!previous.remember) {
store.dispatch(ModalActions.askForRemember(previous));
}
}
}
return;
}
if (action.type === DEVICE.ACQUIRED) {
const { selectedDevice } = store.getState().connect;
initSelectedDevice(store, selectedDevice);
}
if (action.type === DEVICE.CHANGED) {
const previousSelectedDevice = store.getState().connect.selectedDevice;
// Pass actions BEFORE
next(action);
if (previousSelectedDevice && action.device.path === previousSelectedDevice.path) {
//console.warn("TODO: Handle device changed, interrupt running async action (like discovery)", action.device);
}
} else if (action.type === DEVICE.DISCONNECT || action.type === CONNECT.SELECT_DEVICE) {
const previousSelectedDevice = store.getState().connect.selectedDevice;
// Pass actions BEFORE
next(action);
const { devices, selectedDevice } = store.getState().connect;
if (!selectedDevice) {
store.dispatch( push('/') );
} else if (previousSelectedDevice.path !== selectedDevice.path || previousSelectedDevice.instance !== selectedDevice.instance) {
// interrupt discovery process
store.dispatch( TrezorConnectActions.stopDiscoveryProcess(previousSelectedDevice) );
initSelectedDevice(store, selectedDevice);
}
} else if (action.type === TRANSPORT.ERROR) {
next(action);
store.dispatch( push('/') );
} else {
// Pass all actions through by default
next(action);
}
if (action.type === STORAGE.READY) {
// TODO: check offline devices
// set listeners
TrezorConnect.on(DEVICE_EVENT, (event: DeviceMessage): void => {
// post event to TrezorConnectReducer
store.dispatch({
type: event.type,
device: event.payload
});
});
const version: Object = TrezorConnect.getVersion();
if (version.type === 'library') {
// handle UI events only if TrezorConnect isn't using popup
TrezorConnect.on(UI_EVENT, (type: string, data: any): void => {
// post event to reducers
store.dispatch({
type,
data
});
});
}
// init TrezorConnect library
TrezorConnect.init({
hostname: 'localhost', // TODO: controll it in Connect
transport_reconnect: false,
})
.then(() => {
// post action inited
//store.dispatch({ type: 'WEB3_START' });
setTimeout(() => {
store.dispatch( initWeb3() );
}, 2000)
})
.catch(error => {
store.dispatch({
type: CONNECT.INITIALIZATION_ERROR,
error
})
});
} else if (action.type === WEB3.READY) {
const handleDeviceConnect = (device) => {
initSelectedDevice(store, device);
}
const handleDeviceDisconnect = (device) => {
// remove addresses and discovery from state
store.dispatch( TrezorConnectActions.remove(device) );
}
TrezorConnect.on(DEVICE.CONNECT, handleDeviceConnect);
TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect);
TrezorConnect.on(DEVICE.DISCONNECT, handleDeviceDisconnect);
TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceDisconnect);
// solve possible race condition:
// device was connected before Web3 initialized so we need to force DEVICE.CONNECT event on them
const { devices } = store.getState().connect;
for (let d of devices) {
handleDeviceConnect(d);
}
}
};
export default TrezorConnectService;

@ -114,7 +114,7 @@ const TrezorConnectService = (store: any) => (next: any) => (action: any) => {
store.dispatch( TrezorConnectActions.getSelectedDeviceState() ); store.dispatch( TrezorConnectActions.getSelectedDeviceState() );
} else if (action.type === CONNECT.COIN_CHANGED) { } else if (action.type === CONNECT.COIN_CHANGED) {
store.dispatch( TrezorConnectActions.coinChanged( action.payload.coin ) ); store.dispatch( TrezorConnectActions.coinChanged( action.payload.network ) );
} }
} }

@ -2,11 +2,11 @@
'use strict'; 'use strict';
export const getAccounts = (accounts: Array<any>, device: any, coin: ?string): Array<any> => { export const getAccounts = (accounts: Array<any>, device: any, network: ?string): Array<any> => {
if (coin) { if (network) {
return accounts.filter((addr) => addr.checksum === device.checksum && addr.coin === coin); return accounts.filter((addr) => addr.deviceState === device.state && addr.network === network);
} else { } else {
return accounts.filter((addr) => addr.checksum === device.checksum); return accounts.filter((addr) => addr.deviceState === device.state);
} }
} }
Loading…
Cancel
Save