Skip to content

Commit 3fa79d3

Browse files
authored
Merge branch 'master' into TerminalStyleImprovements
2 parents 4b4c647 + 895df62 commit 3fa79d3

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

apps/remix-ide/src/app/tabs/runTab/model/recorder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class Recorder {
259259
cb(err)
260260
}
261261
)
262-
}, () => { self.setListen(true); self.clearAll() })
262+
}, () => { self.setListen(true) })
263263
}
264264

265265
runScenario (json, continueCb, promptCb, alertCb, confirmationCb, logCallBack, cb) {

libs/remix-ui/helper/src/lib/remix-ui-helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export const createNonClashingNameAsync = async (name: string, fileManager, pref
3737
let exist = true
3838

3939
do {
40-
const isDuplicate = await fileManager.exists(name + _counter + prefix + '.' + ext)
40+
const isDuplicate = await fileManager.exists(name + (_counter || '') + prefix + '.' + ext)
4141

42-
if (isDuplicate) _counter = (_counter | 0) + 1
42+
if (isDuplicate) _counter = (_counter || 0) + 1
4343
else exist = false
4444
} while (exist)
4545
const counter = _counter || ''

libs/remix-ui/run-tab/src/lib/actions/index.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React from 'react'
33
import * as ethJSUtil from 'ethereumjs-util'
44
import Web3 from 'web3'
5-
import { addressToString, createNonClashingNameAsync, shortenAddress } from '@remix-ui/helper'
5+
import { addressToString, createNonClashingNameAsync, extractNameFromKey, shortenAddress } from '@remix-ui/helper'
66
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'
77
import { RunTab } from '../types/run-tab'
88
import { CompilerAbstract } from '@remix-project/remix-solidity'
@@ -622,38 +622,39 @@ export const runTransactions = (
622622
)
623623
}
624624

625-
const saveScenario = (promptCb, cb) => {
625+
const saveScenario = (newPath: string, provider, promptCb, cb) => {
626626
const txJSON = JSON.stringify(plugin.recorder.getAll(), null, 2)
627-
const path = plugin.fileManager.currentPath()
628-
629-
promptCb(path, async () => {
630-
const fileProvider = plugin.fileManager.fileProviderOf(path)
631627

632-
if (!fileProvider) return
633-
const newFile = path + '/' + plugin.REACT_API.recorder.pathToScenario
628+
promptCb(() => {
634629
try {
635-
const newPath = await createNonClashingNameAsync(newFile, plugin.fileManager)
636-
if (!fileProvider.set(newPath, txJSON)) return cb('Failed to create file ' + newFile)
637-
plugin.fileManager.open(newFile)
630+
if (!provider.set(newPath, txJSON)) return cb('Failed to create file ' + newPath)
631+
plugin.fileManager.open(newPath)
638632
} catch (error) {
639-
if (error) return cb('Failed to create file. ' + newFile + ' ' + error)
633+
if (error) return cb('Failed to create file. ' + newPath + ' ' + error)
640634
}
641635
})
642636
}
643637

644-
export const storeScenario = (prompt: (msg: string) => JSX.Element) => {
645-
saveScenario(
646-
(path, cb) => {
647-
dispatch(displayNotification('Save transactions as scenario', prompt('Transactions will be saved in a file under ' + path), 'Ok', 'Cancel', cb, null))
638+
export const storeScenario = async (prompt: (msg: string, defaultValue: string) => JSX.Element) => {
639+
const path = plugin.fileManager.currentPath()
640+
const fileProvider = plugin.fileManager.fileProviderOf(path)
641+
642+
if (!fileProvider) return displayNotification('Alert', 'Invalid File Provider', 'OK', null)
643+
const newPath = await createNonClashingNameAsync(path + '/' + plugin.REACT_API.recorder.pathToScenario, plugin.fileManager)
644+
const newName = extractNameFromKey(newPath)
645+
646+
saveScenario(newPath, fileProvider,
647+
(cb) => {
648+
dispatch(displayNotification('Save transactions as scenario', prompt('Transactions will be saved in a file under ' + path, newName), 'OK', 'Cancel', cb, null))
648649
},
649650
(error) => {
650-
if (error) return dispatch(displayNotification('Alert', error, 'Ok', null))
651+
if (error) return dispatch(displayNotification('Alert', error, 'OK', null))
651652
}
652653
)
653654
}
654655

655656
const runScenario = (file: string, gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element, confirmDialogContent: MainnetPrompt, logBuilder: (msg: string) => JSX.Element) => {
656-
if (!file) return dispatch(displayNotification('Alert', 'Unable to run scenerio, no specified scenario file', 'Ok', null))
657+
if (!file) return dispatch(displayNotification('Alert', 'Unable to run scenerio, no specified scenario file', 'OK', null))
657658

658659
plugin.fileManager.readFile(file).then((json) => {
659660
// TODO: there is still a UI dependency to remove here, it's still too coupled at this point to remove easily
@@ -664,7 +665,7 @@ const runScenario = (file: string, gasEstimationPrompt: (msg: string) => JSX.Ele
664665
}, (okCb, cancelCb) => {
665666
promptHandler(passphrasePrompt, okCb, cancelCb)
666667
}, (msg) => {
667-
dispatch(displayNotification('Alert', msg, 'Ok', null))
668+
dispatch(displayNotification('Alert', msg, 'OK', null))
668669
}, (network, tx, gasEstimation, continueTxExecution, cancelCb) => {
669670
confirmationHandler(confirmDialogContent, network, tx, gasEstimation, continueTxExecution, cancelCb)
670671
}, (msg: string) => {
@@ -673,11 +674,11 @@ const runScenario = (file: string, gasEstimationPrompt: (msg: string) => JSX.Ele
673674
return terminalLogger(log)
674675
}, (error, abi, address, contractName) => {
675676
if (error) {
676-
return dispatch(displayNotification('Alert', error, 'Ok', null))
677+
return dispatch(displayNotification('Alert', error, 'OK', null))
677678
}
678679
addInstance({ name: contractName, address, abi })
679680
})
680-
}).catch((error) => dispatch(displayNotification('Alert', error, 'Ok', null)))
681+
}).catch((error) => dispatch(displayNotification('Alert', error, 'OK', null)))
681682
}
682683

683684
export const runCurrentScenario = (gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element, confirmDialogContent: MainnetPrompt, logBuilder: (msg: string) => JSX.Element) => {

libs/remix-ui/run-tab/src/lib/run-tab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ export function RunTabUI (props: RunTabProps) {
172172
return <PassphrasePrompt message={message} setPassphrase={setPassphrasePrompt} defaultValue={runTab.passphrase} />
173173
}
174174

175-
const scenarioPrompt = (message: string) => {
176-
return <ScenarioPrompt message={message} setScenarioPath={updateScenarioPath} defaultValue={runTab.recorder.pathToScenario} />
175+
const scenarioPrompt = (message: string, defaultValue) => {
176+
return <ScenarioPrompt message={message} setScenarioPath={updateScenarioPath} defaultValue={defaultValue} />
177177
}
178178

179179
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) => {

libs/remix-ui/run-tab/src/lib/types/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ export interface ContractDropdownProps {
189189
}
190190

191191
export interface RecorderProps {
192-
storeScenario: (prompt: (msg: string) => JSX.Element) => void,
192+
storeScenario: (prompt: (msg: string, defaultValue: string) => JSX.Element) => void,
193193
runCurrentScenario: (gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element, confirmDialogContent: MainnetPrompt, logBuilder: (msg: string) => JSX.Element) => void,
194194
logBuilder: (msg: string) => JSX.Element,
195195
mainnetPrompt: MainnetPrompt,
196196
gasEstimationPrompt: (msg: string) => JSX.Element,
197197
passphrasePrompt: (msg: string) => JSX.Element,
198-
scenarioPrompt: (msg: string) => JSX.Element,
198+
scenarioPrompt: (msg: string, defaultValue: string) => JSX.Element,
199199
count: number
200200
}
201201

0 commit comments

Comments
 (0)