22import React from 'react'
33import * as ethJSUtil from 'ethereumjs-util'
44import Web3 from 'web3'
5- import { addressToString , createNonClashingNameAsync , shortenAddress } from '@remix-ui/helper'
5+ import { addressToString , createNonClashingNameAsync , extractNameFromKey , shortenAddress } from '@remix-ui/helper'
66import { 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'
77import { RunTab } from '../types/run-tab'
88import { 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
655656const 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
683684export const runCurrentScenario = ( gasEstimationPrompt : ( msg : string ) => JSX . Element , passphrasePrompt : ( msg : string ) => JSX . Element , confirmDialogContent : MainnetPrompt , logBuilder : ( msg : string ) => JSX . Element ) => {
0 commit comments