mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
backend not working
This commit is contained in:
parent
c3bcc5fe91
commit
12ab43ef41
@ -35,7 +35,7 @@ export type DiscoveryStartAction = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type DiscoveryWaitingAction = {
|
export type DiscoveryWaitingAction = {
|
||||||
type: typeof DISCOVERY.WAITING,
|
type: typeof DISCOVERY.WAITING_FOR_DEVICE | typeof DISCOVERY.WAITING_FOR_BACKEND,
|
||||||
device: TrezorDevice,
|
device: TrezorDevice,
|
||||||
network: string
|
network: string
|
||||||
}
|
}
|
||||||
@ -70,12 +70,30 @@ export const start = (device: TrezorDevice, network: string, ignoreCompleted?: b
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const web3 = getState().web3.find(w3 => w3.network === network);
|
||||||
|
if (!web3) {
|
||||||
|
console.error("Start discovery: Web3 does not exist", network)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!web3.web3.currentProvider.isConnected()) {
|
||||||
|
console.error("Start discovery: Web3 is not connected", network)
|
||||||
|
dispatch({
|
||||||
|
type: DISCOVERY.WAITING_FOR_BACKEND,
|
||||||
|
device,
|
||||||
|
network
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const discovery: State = getState().discovery;
|
const discovery: State = getState().discovery;
|
||||||
let discoveryProcess: ?Discovery = discovery.find(d => d.deviceState === device.state && d.network === network);
|
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_FOR_DEVICE,
|
||||||
device,
|
device,
|
||||||
network
|
network
|
||||||
});
|
});
|
||||||
@ -111,7 +129,7 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => {
|
|||||||
if (!coinToDiscover) return;
|
if (!coinToDiscover) return;
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: DISCOVERY.WAITING,
|
type: DISCOVERY.WAITING_FOR_DEVICE,
|
||||||
device,
|
device,
|
||||||
network
|
network
|
||||||
});
|
});
|
||||||
|
@ -18,6 +18,7 @@ import type {
|
|||||||
Action,
|
Action,
|
||||||
AsyncAction,
|
AsyncAction,
|
||||||
} from '../flowtype';
|
} from '../flowtype';
|
||||||
|
import type { ContractFactory } from 'web3';
|
||||||
|
|
||||||
import type { Account } from '../reducers/AccountsReducer';
|
import type { Account } from '../reducers/AccountsReducer';
|
||||||
import type { PendingTx } from '../reducers/PendingTxReducer';
|
import type { PendingTx } from '../reducers/PendingTxReducer';
|
||||||
@ -32,15 +33,15 @@ export type Web3Action = {
|
|||||||
export type Web3CreateAction = {
|
export type Web3CreateAction = {
|
||||||
type: typeof WEB3.CREATE,
|
type: typeof WEB3.CREATE,
|
||||||
network: string,
|
network: string,
|
||||||
web3: Web3, //(web3instance)
|
web3: Web3,
|
||||||
erc20: any,
|
erc20: ContractFactory,
|
||||||
chainId: string;
|
chainId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Web3UpdateBlockAction = {
|
export type Web3UpdateBlockAction = {
|
||||||
type: typeof WEB3.BLOCK_UPDATED,
|
type: typeof WEB3.BLOCK_UPDATED,
|
||||||
network: string,
|
network: string,
|
||||||
blockHash: any
|
blockHash: string
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Web3UpdateGasPriceAction = {
|
export type Web3UpdateGasPriceAction = {
|
||||||
@ -76,9 +77,18 @@ export function init(web3: ?Web3, coinIndex: number = 0): AsyncAction {
|
|||||||
if (currentHostIndex + 1 < urls.length) {
|
if (currentHostIndex + 1 < urls.length) {
|
||||||
web3host = urls[currentHostIndex + 1];
|
web3host = urls[currentHostIndex + 1];
|
||||||
} else {
|
} else {
|
||||||
console.error("TODO: Backend " + network + " not working");
|
console.error("TODO: Backend " + network + " not working", web3.currentProvider );
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: WEB3.CREATE,
|
||||||
|
network,
|
||||||
|
web3,
|
||||||
|
erc20: web3.eth.contract(ERC20Abi),
|
||||||
|
chainId: '0'
|
||||||
|
});
|
||||||
|
|
||||||
// try next coin
|
// try next coin
|
||||||
dispatch( init(web3, coinIndex + 1) );
|
dispatch( init(null, coinIndex + 1) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
export const START: 'discovery__start' = 'discovery__start';
|
export const START: 'discovery__start' = 'discovery__start';
|
||||||
export const STOP: 'discovery__stop' = 'discovery__stop';
|
export const STOP: 'discovery__stop' = 'discovery__stop';
|
||||||
export const COMPLETE: 'discovery__complete' = 'discovery__complete';
|
export const COMPLETE: 'discovery__complete' = 'discovery__complete';
|
||||||
export const WAITING: 'discovery__waiting' = 'discovery__waiting';
|
export const WAITING_FOR_DEVICE: 'discovery__waiting_for_device' = 'discovery__waiting_for_device';
|
||||||
|
export const WAITING_FOR_BACKEND: 'discovery__waiting_for_backend' = 'discovery__waiting_for_backend';
|
||||||
export const FROM_STORAGE: 'discovery__from_storage' = 'discovery__from_storage';
|
export const FROM_STORAGE: 'discovery__from_storage' = 'discovery__from_storage';
|
@ -58,7 +58,7 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
|
|||||||
const device = findDevice(props.devices, currentState.deviceState, currentState.deviceId, currentState.deviceInstance);
|
const device = findDevice(props.devices, currentState.deviceState, currentState.deviceId, currentState.deviceInstance);
|
||||||
if (!device) return;
|
if (!device) return;
|
||||||
const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === currentState.network);
|
const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === currentState.network);
|
||||||
if (!discovery) return;
|
// if (!discovery) return;
|
||||||
const account = props.accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.index && a.network === currentState.network);
|
const account = props.accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.index && a.network === currentState.network);
|
||||||
|
|
||||||
|
|
||||||
@ -68,10 +68,13 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
|
|||||||
deviceStatusNotification = <Notification className="info" title={ `Device ${ device.instanceLabel } is disconnected` } />;
|
deviceStatusNotification = <Notification className="info" title={ `Device ${ device.instanceLabel } is disconnected` } />;
|
||||||
} else if (!device.available) {
|
} else if (!device.available) {
|
||||||
deviceStatusNotification = <Notification className="info" title={ `Device ${ device.instanceLabel } is unavailable` } message="Change passphrase settings to use this device" />;
|
deviceStatusNotification = <Notification className="info" title={ `Device ${ device.instanceLabel } is unavailable` } message="Change passphrase settings to use this device" />;
|
||||||
} else if (!discovery.completed) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discovery && !discovery.completed && !deviceStatusNotification) {
|
||||||
deviceStatusNotification = <Notification className="info" title="Loading accounts" />;
|
deviceStatusNotification = <Notification className="info" title="Loading accounts" />;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.setState({
|
this.setState({
|
||||||
device,
|
device,
|
||||||
discovery,
|
discovery,
|
||||||
@ -112,7 +115,7 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
|
|||||||
if (device.available) {
|
if (device.available) {
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<Notification className="info" title="Loading accounts" />
|
<Notification className="info" title="Loading accounts..." />
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -137,6 +140,12 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
|
|||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else if (discovery.waitingForBackend) {
|
||||||
|
return (
|
||||||
|
<section>
|
||||||
|
<Notification className="warning" title="Backend not working" />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
} else if (discovery.completed) {
|
} else if (discovery.completed) {
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
|
@ -2,11 +2,17 @@ import type BigNumber from 'bignumber.js';
|
|||||||
import type { EthereumUnitT, EthereumAddressT } from 'ethereum-types';
|
import type { EthereumUnitT, EthereumAddressT } from 'ethereum-types';
|
||||||
|
|
||||||
declare module 'web3' {
|
declare module 'web3' {
|
||||||
declare type ProviderT = Object;
|
declare type ProviderT = {
|
||||||
|
host: string;
|
||||||
|
timeout: number;
|
||||||
|
isConnected: () => boolean;
|
||||||
|
send: (payload: any) => any;
|
||||||
|
sendAsync: (payload: any, callback: (error: Error, result: any) => void) => any;
|
||||||
|
};
|
||||||
|
|
||||||
declare class Web3T {
|
declare class Web3T {
|
||||||
static providers: {
|
static providers: {
|
||||||
HttpProvider: (url: string) => ProviderT;
|
HttpProvider: (host: string, timeout?: number) => ProviderT;
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(ProviderT): Web3T;
|
constructor(ProviderT): Web3T;
|
||||||
@ -54,7 +60,7 @@ declare module 'web3' {
|
|||||||
// constructor(abi: Array<Object>);
|
// constructor(abi: Array<Object>);
|
||||||
eth: Eth;
|
eth: Eth;
|
||||||
abi: Array<Object>;
|
abi: Array<Object>;
|
||||||
at: (address: string, callback: (error: Error, contract: Contract) => void) => Contract;
|
at: (address: string, callback: ?(error: Error, contract: Contract) => void) => Contract; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
declare export class Contract {
|
declare export class Contract {
|
||||||
|
@ -29,7 +29,7 @@ export type Discovery = {
|
|||||||
interrupted: boolean;
|
interrupted: boolean;
|
||||||
completed: boolean;
|
completed: boolean;
|
||||||
waitingForDevice: boolean;
|
waitingForDevice: boolean;
|
||||||
waitingForAuth?: boolean;
|
waitingForBackend: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type State = Array<Discovery>;
|
export type State = Array<Discovery>;
|
||||||
@ -50,7 +50,8 @@ const start = (state: State, action: DiscoveryStartAction): State => {
|
|||||||
accountIndex: 0,
|
accountIndex: 0,
|
||||||
interrupted: false,
|
interrupted: false,
|
||||||
completed: false,
|
completed: false,
|
||||||
waitingForDevice: false
|
waitingForDevice: false,
|
||||||
|
waitingForBackend: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
const newState: State = [ ...state ];
|
const newState: State = [ ...state ];
|
||||||
@ -92,7 +93,7 @@ const stop = (state: State, action: DiscoveryStopAction): State => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const waiting = (state: State, action: DiscoveryWaitingAction): State => {
|
const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State => {
|
||||||
|
|
||||||
const deviceState: string = action.device.state || '0';
|
const deviceState: string = action.device.state || '0';
|
||||||
const instance: Discovery = {
|
const instance: Discovery = {
|
||||||
@ -104,7 +105,34 @@ const waiting = (state: State, action: DiscoveryWaitingAction): State => {
|
|||||||
accountIndex: 0,
|
accountIndex: 0,
|
||||||
interrupted: false,
|
interrupted: false,
|
||||||
completed: false,
|
completed: false,
|
||||||
waitingForDevice: true
|
waitingForDevice: true,
|
||||||
|
waitingForBackend: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
const index: number = findIndex(state, action.network, deviceState);
|
||||||
|
const newState: State = [ ...state ];
|
||||||
|
if (index >= 0) {
|
||||||
|
newState[index] = instance;
|
||||||
|
} else {
|
||||||
|
newState.push(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newState;
|
||||||
|
}
|
||||||
|
|
||||||
|
const waitingForBackend = (state: State, action: DiscoveryWaitingAction): State => {
|
||||||
|
const deviceState: string = action.device.state || '0';
|
||||||
|
const instance: Discovery = {
|
||||||
|
network: action.network,
|
||||||
|
deviceState,
|
||||||
|
xpub: '',
|
||||||
|
hdKey: null,
|
||||||
|
basePath: [],
|
||||||
|
accountIndex: 0,
|
||||||
|
interrupted: false,
|
||||||
|
completed: false,
|
||||||
|
waitingForDevice: false,
|
||||||
|
waitingForBackend: true
|
||||||
}
|
}
|
||||||
|
|
||||||
const index: number = findIndex(state, action.network, deviceState);
|
const index: number = findIndex(state, action.network, deviceState);
|
||||||
@ -129,14 +157,17 @@ export default function discovery(state: State = initialState, action: Action):
|
|||||||
return stop(state, action);
|
return stop(state, action);
|
||||||
case DISCOVERY.COMPLETE :
|
case DISCOVERY.COMPLETE :
|
||||||
return complete(state, action);
|
return complete(state, action);
|
||||||
case DISCOVERY.WAITING :
|
case DISCOVERY.WAITING_FOR_DEVICE :
|
||||||
return waiting(state, action)
|
return waitingForDevice(state, action);
|
||||||
|
case DISCOVERY.WAITING_FOR_BACKEND :
|
||||||
|
return waitingForBackend(state, action);
|
||||||
case DISCOVERY.FROM_STORAGE :
|
case DISCOVERY.FROM_STORAGE :
|
||||||
return action.payload.map(d => {
|
return action.payload.map(d => {
|
||||||
return {
|
return {
|
||||||
...d,
|
...d,
|
||||||
interrupted: false,
|
interrupted: false,
|
||||||
waitingForDevice: false
|
waitingForDevice: false,
|
||||||
|
waitingForBackend: false,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
case CONNECT.FORGET :
|
case CONNECT.FORGET :
|
||||||
|
@ -12,14 +12,15 @@ import type {
|
|||||||
Web3UpdateBlockAction,
|
Web3UpdateBlockAction,
|
||||||
Web3UpdateGasPriceAction
|
Web3UpdateGasPriceAction
|
||||||
} from '../actions/Web3Actions';
|
} from '../actions/Web3Actions';
|
||||||
|
import type { ContractFactory } from 'web3';
|
||||||
|
|
||||||
export type Web3Instance = {
|
export type Web3Instance = {
|
||||||
network: string;
|
network: string;
|
||||||
web3: Web3;
|
web3: Web3;
|
||||||
chainId: number;
|
chainId: number;
|
||||||
latestBlock: any;
|
latestBlock: any;
|
||||||
gasPrice: string; //BigNumber
|
gasPrice: string;
|
||||||
erc20: any; //ContractFactory
|
erc20: ContractFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type State = Array<Web3Instance>;
|
export type State = Array<Web3Instance>;
|
||||||
|
@ -118,7 +118,6 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar
|
|||||||
case DISCOVERY.START :
|
case DISCOVERY.START :
|
||||||
case DISCOVERY.STOP :
|
case DISCOVERY.STOP :
|
||||||
case DISCOVERY.COMPLETE :
|
case DISCOVERY.COMPLETE :
|
||||||
// case DISCOVERY.WAITING :
|
|
||||||
save(api.dispatch, api.getState);
|
save(api.dispatch, api.getState);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user