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