diff --git a/libs/remix-ui/run-tab/src/lib/actions/index.ts b/libs/remix-ui/run-tab/src/lib/actions/index.ts index f5a30c0cea..e3f6cd91ed 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -3,7 +3,7 @@ import React from 'react' import * as ethJSUtil from 'ethereumjs-util' import Web3 from 'web3' import { shortenAddress } from '@remix-ui/helper' -import { addProvider, displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, hidePopUp, removeProvider, setExecutionEnvironment, setExternalEndpoint, setGasLimit, setNetworkName, setSelectedAccount, setSendUnit, setSendValue } from './payload' +import { addProvider, displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, hidePopUp, removeProvider, setExecutionEnvironment, setExternalEndpoint, setGasLimit, setMatchPassphrase, setNetworkName, setPassphrase, setSelectedAccount, setSendUnit, setSendValue } from './payload' import { RunTab } from '../types/run-tab' let plugin: RunTab, dispatch: React.Dispatch @@ -74,8 +74,8 @@ const setupEvents = () => { // fillAccountsList() // }, 1000) // fillAccountsList() - setTimeout(() => { - fillAccountsList() + setTimeout(async () => { + await fillAccountsList() }, 0) } @@ -98,18 +98,21 @@ const fillAccountsList = async () => { dispatch(fetchAccountsListRequest()) const promise = plugin.blockchain.getAccounts() - promise.then((accounts: string[]) => { + promise.then(async (accounts: string[]) => { const loadedAccounts = {} if (!accounts) accounts = [] - accounts.forEach((account) => { - plugin.blockchain.getBalanceInEther(account, (err, balance) => { - if (err) return - const updated = shortenAddress(account, balance) - - loadedAccounts[account] = updated + await (Promise as any).allSettled(accounts.map((account) => { + return new Promise((resolve, reject) => { + plugin.blockchain.getBalanceInEther(account, (err, balance) => { + if (err) return reject(err) + const updated = shortenAddress(account, balance) + + loadedAccounts[account] = updated + resolve(account) + }) }) - }) + })) dispatch(fetchAccountsListSuccess(loadedAccounts)) }).catch((e) => { dispatch(fetchAccountsListFailed(e.message)) @@ -206,3 +209,34 @@ export const setWeb3Endpoint = (endpoint: string) => { export const clearPopUp = async () => { dispatch(hidePopUp()) } + +// eslint-disable-next-line no-undef +export const createNewBlockchainAccount = async (cbMessage: JSX.Element) => { + plugin.blockchain.newAccount( + '', + (cb) => { + dispatch(displayNotification('Enter Passphrase', cbMessage, 'OK', 'Cancel', async () => { + if (plugin.REACT_API.passphrase === plugin.REACT_API.matchPassphrase) { + cb(plugin.REACT_API.passphrase) + } else { + return dispatch(displayNotification('Error', 'Passphase does not match', 'OK', null)) + } + }, () => {})) + }, + async (error, address) => { + if (error) { + return dispatch(displayPopUp('Cannot create an account: ' + error)) + } + dispatch(displayPopUp(`account ${address} created`)) + await fillAccountsList() + } + ) +} + +export const setPassphrasePrompt = (passphrase: string) => { + dispatch(setPassphrase(passphrase)) +} + +export const setMatchPassphrasePrompt = (passphrase: string) => { + dispatch(setMatchPassphrase(passphrase)) +} diff --git a/libs/remix-ui/run-tab/src/lib/actions/payload.ts b/libs/remix-ui/run-tab/src/lib/actions/payload.ts index 09bedf03d9..8d47f7d060 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/payload.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/payload.ts @@ -115,3 +115,17 @@ export const hidePopUp = () => { type: 'HIDE_POPUP_MESSAGE' } } + +export const setPassphrase = (passphrase: string) => { + return { + type: 'SET_PASSPHRASE', + payload: passphrase + } +} + +export const setMatchPassphrase = (passphrase: string) => { + return { + type: 'SET_MATCH_PASSPHRASE', + payload: passphrase + } +} diff --git a/libs/remix-ui/run-tab/src/lib/components/account.tsx b/libs/remix-ui/run-tab/src/lib/components/account.tsx index 527aad815b..f164dd20ba 100644 --- a/libs/remix-ui/run-tab/src/lib/components/account.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/account.tsx @@ -55,24 +55,7 @@ export function AccountUI (props: AccountProps) { }, [props.selectExEnv, props.personalMode]) const newAccount = () => { - // dispatch createNewBlockchainAccount - // this.blockchain.newAccount( - // '', - // (cb) => { - // modalDialogCustom.promptPassphraseCreation((error, passphrase) => { - // if (error) { - // return modalDialogCustom.alert(error) - // } - // cb(passphrase) - // }, () => {}) - // }, - // (error, address) => { - // if (error) { - // return addTooltip('Cannot create an account: ' + error) - // } - // addTooltip(`account ${address} created`) - // } - // ) + props.createNewBlockchainAccount(passphrasePrompt()) } const signMessage = () => { @@ -122,6 +105,27 @@ export function AccountUI (props: AccountProps) { // }) } + const handlePassphrase = (e) => { + props.setPassphrase(e.target.value) + } + + const handleMatchPassphrase = (e) => { + props.setMatchPassphrase(e.target.value) + } + + const passphrasePrompt = () => { + return ( +
Please provide a Passphrase for the account creation +
+ +
+
+ +
+
+ ) + } + return (