Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

convert ETH/WETH not waits for transaction #569

Open
JoaoCampos89 opened this issue Oct 9, 2019 · 0 comments
Open

convert ETH/WETH not waits for transaction #569

JoaoCampos89 opened this issue Oct 9, 2019 · 0 comments

Comments

@JoaoCampos89
Copy link

The Converting ETH <--> WETH process does not wait for the transaction to complete, giving to the user the feeling that the transaction is almost instant.
How to solve the issue:
store/blockchain/actions.ts

export const updateTokenBalances: ThunkCreator<Promise<any>> = (txHash?: string) => {
    return async (dispatch, getState, { getWeb3Wrapper }) => {
        const state = getState();
        const ethAccount = getEthAccount(state);
        const knownTokens = getKnownTokens();
        const wethToken = knownTokens.getWethToken();
        const web3Wrapper = await getWeb3Wrapper();
        if (txHash) {
            const tx = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
        }
        const allTokenBalances = await tokensToTokenBalances([...knownTokens.getTokens(), wethToken], ethAccount);
        const wethBalance = allTokenBalances.find(b => b.token.symbol === wethToken.symbol);
        const tokenBalances = allTokenBalances.filter(b => b.token.symbol !== wethToken.symbol);
        dispatch(setTokenBalances(tokenBalances));
        const ethBalance = await web3Wrapper.getBalanceInWeiAsync(ethAccount);
        if (wethBalance) {
            dispatch(setWethBalance(wethBalance.balance));
        }
        dispatch(setEthBalance(ethBalance));
        return ethBalance;
    };
};

if txhash is passed as argument we wait to the transaction to complete before update token balances

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant