mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
add deviceState to setBalance & setNonce actions
This commit is contained in:
parent
94c58d0b13
commit
8d851c5c8f
@ -29,6 +29,7 @@ export type AddressSetBalanceAction = {
|
|||||||
type: typeof ADDRESS.SET_BALANCE,
|
type: typeof ADDRESS.SET_BALANCE,
|
||||||
address: string,
|
address: string,
|
||||||
network: string,
|
network: string,
|
||||||
|
deviceState: string,
|
||||||
balance: string
|
balance: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,14 +37,26 @@ export type AddressSetNonceAction = {
|
|||||||
type: typeof ADDRESS.SET_NONCE,
|
type: typeof ADDRESS.SET_NONCE,
|
||||||
address: string,
|
address: string,
|
||||||
network: string,
|
network: string,
|
||||||
|
deviceState: string,
|
||||||
nonce: number
|
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 {
|
return {
|
||||||
type: ADDRESS.SET_BALANCE,
|
type: ADDRESS.SET_BALANCE,
|
||||||
address,
|
address,
|
||||||
network,
|
network,
|
||||||
|
deviceState,
|
||||||
balance
|
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);
|
const balance = await getBalanceAsync(web3instance.web3, ethAddress);
|
||||||
if (discoveryProcess.interrupted) return;
|
if (discoveryProcess.interrupted) return;
|
||||||
dispatch(
|
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 = [];
|
const userTokens = [];
|
||||||
@ -302,12 +302,7 @@ const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
|||||||
|
|
||||||
const nonce: number = await getNonceAsync(web3instance.web3, ethAddress);
|
const nonce: number = await getNonceAsync(web3instance.web3, ethAddress);
|
||||||
if (discoveryProcess.interrupted) return;
|
if (discoveryProcess.interrupted) return;
|
||||||
dispatch({
|
dispatch(AddressActions.setNonce(ethAddress, network, device.state || 'undefined', nonce));
|
||||||
type: ADDRESS.SET_NONCE,
|
|
||||||
address: ethAddress,
|
|
||||||
network,
|
|
||||||
nonce: nonce
|
|
||||||
});
|
|
||||||
|
|
||||||
const addressIsEmpty = nonce < 1 && !balance.greaterThan(0);
|
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) {
|
for (const account of accounts) {
|
||||||
const nonce = await getNonceAsync(web3, account.address);
|
const nonce = await getNonceAsync(web3, account.address);
|
||||||
if (nonce !== account.nonce) {
|
if (nonce !== account.nonce) {
|
||||||
dispatch({
|
dispatch(AddressActions.setNonce(account.address, account.network, account.deviceState, nonce));
|
||||||
type: ADDRESS.SET_NONCE,
|
|
||||||
address: account.address,
|
|
||||||
network: account.network,
|
|
||||||
nonce
|
|
||||||
});
|
|
||||||
|
|
||||||
// dispatch( getBalance(account) );
|
// dispatch( getBalance(account) );
|
||||||
// TODO: check if nonce was updated,
|
// TODO: check if nonce was updated,
|
||||||
@ -254,6 +249,7 @@ export function getBalance(account: Account): AsyncAction {
|
|||||||
dispatch(AddressActions.setBalance(
|
dispatch(AddressActions.setBalance(
|
||||||
account.address,
|
account.address,
|
||||||
account.network,
|
account.network,
|
||||||
|
account.deviceState,
|
||||||
newBalance
|
newBalance
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -296,12 +292,7 @@ export function getNonce(account: Account): AsyncAction {
|
|||||||
web3.eth.getTransactionCount(account.address, (error: Error, result: number) => {
|
web3.eth.getTransactionCount(account.address, (error: Error, result: number) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
if (account.nonce !== result) {
|
if (account.nonce !== result) {
|
||||||
dispatch({
|
dispatch(AddressActions.setNonce(account.address, account.network, account.deviceState, result));
|
||||||
type: ADDRESS.SET_NONCE,
|
|
||||||
address: account.address,
|
|
||||||
network: account.network,
|
|
||||||
nonce: result
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -66,7 +66,7 @@ const removeAccounts = (state: State, device: TrezorDevice): State => {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
const setBalance = (state: State, action: AddressSetBalanceAction): 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 ];
|
const newState: State = [ ...state ];
|
||||||
newState[index].loaded = true;
|
newState[index].loaded = true;
|
||||||
newState[index].balance = action.balance;
|
newState[index].balance = action.balance;
|
||||||
@ -74,7 +74,7 @@ const setBalance = (state: State, action: AddressSetBalanceAction): State => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setNonce = (state: State, action: AddressSetNonceAction): 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 ];
|
const newState: State = [ ...state ];
|
||||||
newState[index].loaded = true;
|
newState[index].loaded = true;
|
||||||
newState[index].nonce = action.nonce;
|
newState[index].nonce = action.nonce;
|
||||||
|
Loading…
Reference in New Issue
Block a user