diff options
author | Chi Kei Chan <chikeichan@gmail.com> | 2017-09-22 09:44:52 +0800 |
---|---|---|
committer | Chi Kei Chan <chikeichan@gmail.com> | 2017-09-22 09:44:52 +0800 |
commit | 3ec2f534632426876c28b22c58cbbf14b4904d97 (patch) | |
tree | ed84f2703e86a29a7db43a4ecabac308a0cbe7bb /ui/app/actions.js | |
parent | 24fd16b1bee31352ef7f364804eb5f06c08c3bf6 (diff) | |
download | tangerine-wallet-browser-3ec2f534632426876c28b22c58cbbf14b4904d97.tar tangerine-wallet-browser-3ec2f534632426876c28b22c58cbbf14b4904d97.tar.gz tangerine-wallet-browser-3ec2f534632426876c28b22c58cbbf14b4904d97.tar.bz2 tangerine-wallet-browser-3ec2f534632426876c28b22c58cbbf14b4904d97.tar.lz tangerine-wallet-browser-3ec2f534632426876c28b22c58cbbf14b4904d97.tar.xz tangerine-wallet-browser-3ec2f534632426876c28b22c58cbbf14b4904d97.tar.zst tangerine-wallet-browser-3ec2f534632426876c28b22c58cbbf14b4904d97.zip |
Integrate Add Token
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r-- | ui/app/actions.js | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 678c68a6a..1231fc296 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -147,6 +147,7 @@ var actions = { SHOW_ADD_TOKEN_PAGE: 'SHOW_ADD_TOKEN_PAGE', showAddTokenPage, addToken, + addTokens, setRpcTarget: setRpcTarget, setDefaultRpcTarget: setDefaultRpcTarget, setProviderType: setProviderType, @@ -700,18 +701,40 @@ function showAddTokenPage () { function addToken (address, symbol, decimals) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - background.addToken(address, symbol, decimals, (err) => { - dispatch(actions.hideLoadingIndication()) - if (err) { - return dispatch(actions.displayWarning(err.message)) - } - setTimeout(() => { - dispatch(actions.goHome()) - }, 250) + return new Promise((resolve, reject) => { + background.addToken(address, symbol, decimals, (err) => { + dispatch(actions.hideLoadingIndication()) + if (err) { + dispatch(actions.displayWarning(err.message)) + reject(err) + } + resolve() + // setTimeout(() => { + // dispatch(actions.goHome()) + // }, 250) + }) }) } } +function addTokens (tokens) { + return dispatch => { + if (Array.isArray(tokens)) { + return Promise.all(tokens.map(({ address, symbol, decimals }) => ( + dispatch(addToken(address, symbol, decimals)) + ))) + } else { + return Promise.all( + Object + .entries(tokens) + .map(([_, { address, symbol, decimals }]) => ( + dispatch(addToken(address, symbol, decimals)) + )) + ) + } + } +} + function goBackToInitView () { return { type: actions.BACK_TO_INIT_MENU, |