1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

Sendform coinsymbol & set max fix

This commit is contained in:
Szymon Lesisz 2018-05-09 16:36:25 +02:00
parent 13b8d90c72
commit eaa6e19050
3 changed files with 12 additions and 15 deletions

View File

@ -195,7 +195,7 @@ export const init = (): ThunkAction => {
...initialState, ...initialState,
network: coin.network, network: coin.network,
coinSymbol: coin.symbol, coinSymbol: coin.symbol,
token: coin.network, token: coin.symbol,
feeLevels, feeLevels,
selectedFeeLevel: feeLevels.find(f => f.value === 'Normal'), selectedFeeLevel: feeLevels.find(f => f.value === 'Normal'),
recommendedGasPrice: gasPrice.toString(), recommendedGasPrice: gasPrice.toString(),
@ -384,7 +384,7 @@ export const onAmountChange = (amount: string): ThunkAction => {
const accountState: AccountState = getState().abstractAccount; const accountState: AccountState = getState().abstractAccount;
const currentState: State = getState().sendForm; const currentState: State = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network; const isToken: boolean = currentState.token !== currentState.coinSymbol;
const touched = { ...currentState.touched }; const touched = { ...currentState.touched };
touched.amount = true; touched.amount = true;
const total: string = calculateTotal(isToken ? '0' : amount, currentState.gasPrice, currentState.gasLimit); const total: string = calculateTotal(isToken ? '0' : amount, currentState.gasPrice, currentState.gasLimit);
@ -410,7 +410,7 @@ export const onCurrencyChange = (currency: any): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => { return (dispatch: Dispatch, getState: GetState): void => {
const accountState: AccountState = getState().abstractAccount; const accountState: AccountState = getState().abstractAccount;
const currentState: State = getState().sendForm; const currentState: State = getState().sendForm;
const isToken: boolean = currency.value !== accountState.network; const isToken: boolean = currency.value !== currentState.coinSymbol;
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network); const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (!account) { if (!account) {
@ -418,10 +418,7 @@ export const onCurrencyChange = (currency: any): ThunkAction => {
return; return;
} }
const { config } = getState().localStorage; const coin: Coin = accountState.coin;
if (!config) return;
const coin: ?Coin = config.coins.find(c => c.network === accountState.network);
if (!coin) return;
let gasLimit: string = ''; let gasLimit: string = '';
let amount: string = currentState.amount; let amount: string = currentState.amount;
@ -430,7 +427,7 @@ export const onCurrencyChange = (currency: any): ThunkAction => {
if (isToken) { if (isToken) {
gasLimit = coin.defaultGasLimitTokens.toString(); gasLimit = coin.defaultGasLimitTokens.toString();
if (currentState.setMax) { if (currentState.setMax) {
const token: ?Token = findToken(getState().tokens, account.address, currentState.token, accountState.deviceState); const token: ?Token = findToken(getState().tokens, account.address, currency.value, accountState.deviceState);
if (!token) return; if (!token) return;
amount = token.balance; amount = token.balance;
} }
@ -471,7 +468,7 @@ export const onSetMax = (): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => { return (dispatch: Dispatch, getState: GetState): void => {
const accountState: AccountState = getState().abstractAccount; const accountState: AccountState = getState().abstractAccount;
const currentState: State = getState().sendForm; const currentState: State = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network; const isToken: boolean = currentState.token !== currentState.coinSymbol;
const touched = { ...currentState.touched }; const touched = { ...currentState.touched };
touched.amount = true; touched.amount = true;
@ -516,7 +513,7 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => { return (dispatch: Dispatch, getState: GetState): void => {
const accountState: AccountState = getState().abstractAccount; const accountState: AccountState = getState().abstractAccount;
const currentState: State = getState().sendForm; const currentState: State = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network; const isToken: boolean = currentState.token !== currentState.coinSymbol;
const { config } = getState().localStorage; const { config } = getState().localStorage;
if (!config) return; if (!config) return;
@ -569,7 +566,7 @@ export const updateFeeLevels = (): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => { return (dispatch: Dispatch, getState: GetState): void => {
const accountState: AccountState = getState().abstractAccount; const accountState: AccountState = getState().abstractAccount;
const currentState: State = getState().sendForm; const currentState: State = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network; const isToken: boolean = currentState.token !== currentState.coinSymbol;
const feeLevels: Array<FeeLevel> = getFeeLevels(currentState.coinSymbol, currentState.recommendedGasPrice, currentState.gasLimit); const feeLevels: Array<FeeLevel> = getFeeLevels(currentState.coinSymbol, currentState.recommendedGasPrice, currentState.gasLimit);
const selectedFeeLevel: ?FeeLevel = feeLevels.find(f => f.value === currentState.selectedFeeLevel.value); const selectedFeeLevel: ?FeeLevel = feeLevels.find(f => f.value === currentState.selectedFeeLevel.value);
@ -658,7 +655,7 @@ export const onGasLimitChange = (gasLimit: string): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => { return (dispatch: Dispatch, getState: GetState): void => {
const accountState: AccountState = getState().abstractAccount; const accountState: AccountState = getState().abstractAccount;
const currentState: State = getState().sendForm; const currentState: State = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network; const isToken: boolean = currentState.token !== currentState.coinSymbol;
const touched = { ...currentState.touched }; const touched = { ...currentState.touched };
touched.gasLimit = true; touched.gasLimit = true;
@ -733,7 +730,7 @@ export const onSend = (): AsyncAction => {
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network); const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (!account || !web3instance) return; if (!account || !web3instance) return;
const isToken: boolean = currentState.token !== accountState.network; const isToken: boolean = currentState.token !== currentState.coinSymbol;
const web3 = web3instance.web3; const web3 = web3instance.web3;
const address_n = account.addressPath; const address_n = account.addressPath;

View File

@ -23,7 +23,7 @@ const Confirmation = (props: Props) => {
</div> </div>
<div className="content"> <div className="content">
<label>Send </label> <label>Send </label>
<p>{ `${amount} ${ coinSymbol }` }</p> <p>{ `${amount} ${ token }` }</p>
<label>To</label> <label>To</label>
<p>{ address }</p> <p>{ address }</p>
<label>Fee</label> <label>Fee</label>

View File

@ -66,7 +66,7 @@ const _render = (props: Props, state: AccountState): React$Element<string> => {
const tokens = addressTokens.map(t => { const tokens = addressTokens.map(t => {
return { value: t.symbol, label: t.symbol }; return { value: t.symbol, label: t.symbol };
}); });
tokens.unshift({ value: selectedCoin.network, label: selectedCoin.symbol }); tokens.unshift({ value: selectedCoin.symbol, label: selectedCoin.symbol });
const setMaxClassName: string = setMax ? 'set-max enabled' : 'set-max'; const setMaxClassName: string = setMax ? 'set-max enabled' : 'set-max';