From 3cf20f6485b3341eaf42d57eb723a4392bb03f09 Mon Sep 17 00:00:00 2001 From: David Disu Date: Mon, 17 Jan 2022 09:42:25 +0100 Subject: [PATCH 1/2] Fix recorder bugs --- .../helper/src/lib/remix-ui-helper.ts | 4 +-- .../remix-ui/run-tab/src/lib/actions/index.ts | 35 ++++++++++--------- libs/remix-ui/run-tab/src/lib/run-tab.tsx | 4 +-- libs/remix-ui/run-tab/src/lib/types/index.ts | 4 +-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/libs/remix-ui/helper/src/lib/remix-ui-helper.ts b/libs/remix-ui/helper/src/lib/remix-ui-helper.ts index 779709c75c..4b9eb28d1c 100644 --- a/libs/remix-ui/helper/src/lib/remix-ui-helper.ts +++ b/libs/remix-ui/helper/src/lib/remix-ui-helper.ts @@ -37,9 +37,9 @@ export const createNonClashingNameAsync = async (name: string, fileManager, pref let exist = true do { - const isDuplicate = await fileManager.exists(name + _counter + prefix + '.' + ext) + const isDuplicate = await fileManager.exists(name + (_counter || '') + prefix + '.' + ext) - if (isDuplicate) _counter = (_counter | 0) + 1 + if (isDuplicate) _counter = (_counter || 0) + 1 else exist = false } while (exist) const counter = _counter || '' 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 7937e8bc0e..5a1a96fb2f 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -2,7 +2,7 @@ import React from 'react' import * as ethJSUtil from 'ethereumjs-util' import Web3 from 'web3' -import { addressToString, createNonClashingNameAsync, shortenAddress } from '@remix-ui/helper' +import { addressToString, createNonClashingNameAsync, extractNameFromKey, shortenAddress } from '@remix-ui/helper' import { addNewInstance, addProvider, clearAllInstances, clearRecorderCount, displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, fetchContractListSuccess, hidePopUp, removeExistingInstance, removeProvider, resetUdapp, setBaseFeePerGas, setConfirmSettings, setCurrentFile, setDecodedResponse, setEnvToasterContent, setExecutionEnvironment, setExternalEndpoint, setGasLimit, setGasPrice, setGasPriceStatus, setLoadType, setMatchPassphrase, setMaxFee, setMaxPriorityFee, setNetworkName, setPassphrase, setPathToScenario, setRecorderCount, setSelectedAccount, setSendUnit, setSendValue, setTxFeeContent, setWeb3Dialog } from './payload' import { RunTab } from '../types/run-tab' import { CompilerAbstract } from '@remix-project/remix-solidity' @@ -622,32 +622,33 @@ export const runTransactions = ( ) } -const saveScenario = (promptCb, cb) => { +const saveScenario = (newPath: string, provider, promptCb, cb) => { const txJSON = JSON.stringify(plugin.recorder.getAll(), null, 2) - const path = plugin.fileManager.currentPath() - - promptCb(path, async () => { - const fileProvider = plugin.fileManager.fileProviderOf(path) - if (!fileProvider) return - const newFile = path + '/' + plugin.REACT_API.recorder.pathToScenario + promptCb(() => { try { - const newPath = await createNonClashingNameAsync(newFile, plugin.fileManager) - if (!fileProvider.set(newPath, txJSON)) return cb('Failed to create file ' + newFile) - plugin.fileManager.open(newFile) + if (!provider.set(newPath, txJSON)) return cb('Failed to create file ' + newPath) + plugin.fileManager.open(newPath) } catch (error) { - if (error) return cb('Failed to create file. ' + newFile + ' ' + error) + if (error) return cb('Failed to create file. ' + newPath + ' ' + error) } }) } -export const storeScenario = (prompt: (msg: string) => JSX.Element) => { - saveScenario( - (path, cb) => { - dispatch(displayNotification('Save transactions as scenario', prompt('Transactions will be saved in a file under ' + path), 'Ok', 'Cancel', cb, null)) +export const storeScenario = async (prompt: (msg: string, defaultValue: string) => JSX.Element) => { + const path = plugin.fileManager.currentPath() + const fileProvider = plugin.fileManager.fileProviderOf(path) + + if (!fileProvider) return displayNotification('Alert', 'Invalid File Provider', 'Ok', null) + const newPath = await createNonClashingNameAsync(path + '/' + plugin.REACT_API.recorder.pathToScenario, plugin.fileManager) + const newName = extractNameFromKey(newPath) + + saveScenario(newPath, fileProvider, + (cb) => { + dispatch(displayNotification('Save transactions as scenario', prompt('Transactions will be saved in a file under ' + path, newName), 'OK', 'Cancel', cb, null)) }, (error) => { - if (error) return dispatch(displayNotification('Alert', error, 'Ok', null)) + if (error) return dispatch(displayNotification('Alert', error, 'OK', null)) } ) } diff --git a/libs/remix-ui/run-tab/src/lib/run-tab.tsx b/libs/remix-ui/run-tab/src/lib/run-tab.tsx index 19700f43fa..3dc10d1e52 100644 --- a/libs/remix-ui/run-tab/src/lib/run-tab.tsx +++ b/libs/remix-ui/run-tab/src/lib/run-tab.tsx @@ -172,8 +172,8 @@ export function RunTabUI (props: RunTabProps) { return } - const scenarioPrompt = (message: string) => { - return + const scenarioPrompt = (message: string, defaultValue) => { + return } const mainnetPrompt = (tx: Tx, network: Network, amount: string, gasEstimation: string, gasFees: (maxFee: string, cb: (txFeeText: string, priceStatus: boolean) => void) => void, determineGasPrice: (cb: (txFeeText: string, gasPriceValue: string, gasPriceStatus: boolean) => void) => void) => { diff --git a/libs/remix-ui/run-tab/src/lib/types/index.ts b/libs/remix-ui/run-tab/src/lib/types/index.ts index 0647fca2fd..b2d5c1fe88 100644 --- a/libs/remix-ui/run-tab/src/lib/types/index.ts +++ b/libs/remix-ui/run-tab/src/lib/types/index.ts @@ -189,13 +189,13 @@ export interface ContractDropdownProps { } export interface RecorderProps { - storeScenario: (prompt: (msg: string) => JSX.Element) => void, + storeScenario: (prompt: (msg: string, defaultValue: string) => JSX.Element) => void, runCurrentScenario: (gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element, confirmDialogContent: MainnetPrompt, logBuilder: (msg: string) => JSX.Element) => void, logBuilder: (msg: string) => JSX.Element, mainnetPrompt: MainnetPrompt, gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element, - scenarioPrompt: (msg: string) => JSX.Element, + scenarioPrompt: (msg: string, defaultValue: string) => JSX.Element, count: number } From ba6c07a4e657997ca1e8707a49e6797599572d84 Mon Sep 17 00:00:00 2001 From: David Disu Date: Tue, 18 Jan 2022 06:30:02 +0100 Subject: [PATCH 2/2] Modified modal OK text and Keep existing saved recorder transactions --- apps/remix-ide/src/app/tabs/runTab/model/recorder.js | 2 +- libs/remix-ui/run-tab/src/lib/actions/index.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/runTab/model/recorder.js b/apps/remix-ide/src/app/tabs/runTab/model/recorder.js index f9a5d9aa78..a8b71b815e 100644 --- a/apps/remix-ide/src/app/tabs/runTab/model/recorder.js +++ b/apps/remix-ide/src/app/tabs/runTab/model/recorder.js @@ -259,7 +259,7 @@ class Recorder { cb(err) } ) - }, () => { self.setListen(true); self.clearAll() }) + }, () => { self.setListen(true) }) } runScenario (json, continueCb, promptCb, alertCb, confirmationCb, logCallBack, cb) { 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 5a1a96fb2f..44ce22a873 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -639,7 +639,7 @@ export const storeScenario = async (prompt: (msg: string, defaultValue: string) const path = plugin.fileManager.currentPath() const fileProvider = plugin.fileManager.fileProviderOf(path) - if (!fileProvider) return displayNotification('Alert', 'Invalid File Provider', 'Ok', null) + if (!fileProvider) return displayNotification('Alert', 'Invalid File Provider', 'OK', null) const newPath = await createNonClashingNameAsync(path + '/' + plugin.REACT_API.recorder.pathToScenario, plugin.fileManager) const newName = extractNameFromKey(newPath) @@ -654,7 +654,7 @@ export const storeScenario = async (prompt: (msg: string, defaultValue: string) } const runScenario = (file: string, gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element, confirmDialogContent: MainnetPrompt, logBuilder: (msg: string) => JSX.Element) => { - if (!file) return dispatch(displayNotification('Alert', 'Unable to run scenerio, no specified scenario file', 'Ok', null)) + if (!file) return dispatch(displayNotification('Alert', 'Unable to run scenerio, no specified scenario file', 'OK', null)) plugin.fileManager.readFile(file).then((json) => { // TODO: there is still a UI dependency to remove here, it's still too coupled at this point to remove easily @@ -665,7 +665,7 @@ const runScenario = (file: string, gasEstimationPrompt: (msg: string) => JSX.Ele }, (okCb, cancelCb) => { promptHandler(passphrasePrompt, okCb, cancelCb) }, (msg) => { - dispatch(displayNotification('Alert', msg, 'Ok', null)) + dispatch(displayNotification('Alert', msg, 'OK', null)) }, (network, tx, gasEstimation, continueTxExecution, cancelCb) => { confirmationHandler(confirmDialogContent, network, tx, gasEstimation, continueTxExecution, cancelCb) }, (msg: string) => { @@ -674,11 +674,11 @@ const runScenario = (file: string, gasEstimationPrompt: (msg: string) => JSX.Ele return terminalLogger(log) }, (error, abi, address, contractName) => { if (error) { - return dispatch(displayNotification('Alert', error, 'Ok', null)) + return dispatch(displayNotification('Alert', error, 'OK', null)) } addInstance({ name: contractName, address, abi }) }) - }).catch((error) => dispatch(displayNotification('Alert', error, 'Ok', null))) + }).catch((error) => dispatch(displayNotification('Alert', error, 'OK', null))) } export const runCurrentScenario = (gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element, confirmDialogContent: MainnetPrompt, logBuilder: (msg: string) => JSX.Element) => {