diff --git a/src/app/tabs/runTab/contractDropdown.js b/src/app/tabs/runTab/contractDropdown.js index fa7d8a5fe8..42b828be55 100644 --- a/src/app/tabs/runTab/contractDropdown.js +++ b/src/app/tabs/runTab/contractDropdown.js @@ -19,6 +19,7 @@ class ContractDropdownUI { this.listenToEvents() this.ipfsCheckedState = false + this.exEnvironment = blockchain.getProvider() this.listenToContextChange() } @@ -49,31 +50,45 @@ class ContractDropdownUI { listenToContextChange () { this.blockchain.event.register('newExecutionContext', () => { - this.blockchain.updateNetwork((err, {id, name} = {}) => { + this.blockchain.updateNetwork((err, {name} = {}) => { if (err) { console.log(`can't detect network`) return } - const environment = this.blockchain.getProvider() - - if(environment === 'vm'){ - this.ipfsCheckedState = false - document.getElementById('deployAndRunPublishToIPFS').checked = false - }else if(environment === 'injected'){ - if(name === 'Main'){ - this.ipfsCheckedState = true - document.getElementById('deployAndRunPublishToIPFS').checked = true - }else{ - this.ipfsCheckedState = false - document.getElementById('deployAndRunPublishToIPFS').checked = false + this.exEnvironment = this.blockchain.getProvider() + this.networkName = name + + const savedConfig = window.localStorage.getItem(`ipfs/${this.exEnvironment}/${this.networkName}`) + + // check if an already selected option exist else use default workflow + if (savedConfig !== null) { + this.setCheckedState(savedConfig) + } else { + if (this.exEnvironment === 'vm') { + this.setCheckedState(false) + } else if (this.exEnvironment === 'injected') { + if(this.networkName === 'Main'){ + // select publish to ipfs by default for mainnet + this.setCheckedState(true) + } else { + this.setCheckedState(false) + } } } }) }) } + setCheckedState (value) { + value = value === 'true' ? true : value === 'false' ? false : value + this.ipfsCheckedState = value + document.getElementById('deployAndRunPublishToIPFS').checked = value + } + toggleCheckedState () { + if(this.exEnvironment === 'vm') this.networkName = 'VM' this.ipfsCheckedState = !this.ipfsCheckedState + window.localStorage.setItem(`ipfs/${this.exEnvironment}/${this.networkName}`, this.ipfsCheckedState) } render () { @@ -86,6 +101,14 @@ class ContractDropdownUI { this.createPanel = yo`
` this.orLabel = yo`