Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant