add deviceState to setBalance & setNonce actions

pull/2/merge
Szymon Lesisz 6 years ago
parent 94c58d0b13
commit 8d851c5c8f

@ -29,6 +29,7 @@ export type AddressSetBalanceAction = {
type: typeof ADDRESS.SET_BALANCE,
address: string,
network: string,
deviceState: string,
balance: string
}
@ -36,14 +37,26 @@ export type AddressSetNonceAction = {
type: typeof ADDRESS.SET_NONCE,
address: string,
network: string,
deviceState: string,
nonce: number
}
export const setBalance = (address: string, network: string, balance: string): Action => {
export const setBalance = (address: string, network: string, deviceState: string, balance: string): Action => {
return {
type: ADDRESS.SET_BALANCE,
address,
network,
deviceState,
balance
}
}
export const setNonce = (address: string, network: string, deviceState: string, nonce: number): Action => {
return {
type: ADDRESS.SET_NONCE,
address,
network,
deviceState,
nonce
}
}

@ -285,7 +285,7 @@ const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): Asy
const balance = await getBalanceAsync(web3instance.web3, ethAddress);
if (discoveryProcess.interrupted) return;
dispatch(
AddressActions.setBalance(ethAddress, network, web3instance.web3.fromWei(balance.toString(), 'ether'))
AddressActions.setBalance(ethAddress, network, device.state || 'undefined', web3instance.web3.fromWei(balance.toString(), 'ether'))
);
const userTokens = [];
@ -302,12 +302,7 @@ const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): Asy
const nonce: number = await getNonceAsync(web3instance.web3, ethAddress);
if (discoveryProcess.interrupted) return;
dispatch({
type: ADDRESS.SET_NONCE,
address: ethAddress,
network,
nonce: nonce
});
dispatch(AddressActions.setNonce(ethAddress, network, device.state || 'undefined', nonce));
const addressIsEmpty = nonce < 1 && !balance.greaterThan(0);

@ -172,12 +172,7 @@ export function init(instance: ?Web3, coinIndex: number = 0): AsyncAction {
for (const account of accounts) {
const nonce = await getNonceAsync(web3, account.address);
if (nonce !== account.nonce) {
dispatch({
type: ADDRESS.SET_NONCE,
address: account.address,
network: account.network,
nonce
});
dispatch(AddressActions.setNonce(account.address, account.network, account.deviceState, nonce));
// dispatch( getBalance(account) );
// TODO: check if nonce was updated,
@ -254,6 +249,7 @@ export function getBalance(account: Account): AsyncAction {
dispatch(AddressActions.setBalance(
account.address,
account.network,
account.deviceState,
newBalance
));
@ -296,12 +292,7 @@ export function getNonce(account: Account): AsyncAction {
web3.eth.getTransactionCount(account.address, (error: Error, result: number) => {
if (!error) {
if (account.nonce !== result) {
dispatch({
type: ADDRESS.SET_NONCE,
address: account.address,
network: account.network,
nonce: result
});
dispatch(AddressActions.setNonce(account.address, account.network, account.deviceState, result));
}
}
});

@ -66,7 +66,7 @@ const removeAccounts = (state: State, device: TrezorDevice): State => {
// }
const setBalance = (state: State, action: AddressSetBalanceAction): State => {
const index: number = state.findIndex(account => account.address === action.address && account.network === action.network);
const index: number = state.findIndex(account => account.address === action.address && account.network === action.network && account.deviceState === action.deviceState);
const newState: State = [ ...state ];
newState[index].loaded = true;
newState[index].balance = action.balance;
@ -74,7 +74,7 @@ const setBalance = (state: State, action: AddressSetBalanceAction): State => {
}
const setNonce = (state: State, action: AddressSetNonceAction): State => {
const index: number = state.findIndex(account => account.address === action.address && account.network === action.network);
const index: number = state.findIndex(account => account.address === action.address && account.network === action.network && account.deviceState === action.deviceState);
const newState: State = [ ...state ];
newState[index].loaded = true;
newState[index].nonce = action.nonce;

Loading…
Cancel
Save