From 55d2f8f3a178e94fd7c2b591a0eb7963bfd171a3 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 4 Mar 2020 16:04:05 +0000 Subject: [PATCH] Stored config in localstorage --- src/app/tabs/runTab/contractDropdown.js | 53 ++++++++++++++++++------- 1 file changed, 38 insertions(+), 15 deletions(-) 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`
or
` + if(this.exEnvironment === 'vm') this.networkName = 'VM' + const savedConfig = window.localStorage.getItem(`ipfs/${this.exEnvironment}/${this.networkName}`) + + this.ipfsCheckedState = savedConfig === 'true' ? true : false + const ipfsCheckbox = this.ipfsCheckedState === true + ? yo`` + : yo`` + let el = yo`
@@ -101,7 +124,7 @@ class ContractDropdownUI {
- + ${ipfsCheckbox}
@@ -149,7 +172,7 @@ class ContractDropdownUI { const selectedContract = this.getSelectedContract() const clickCallback = async (valArray, inputsValues) => { var selectedContract = this.getSelectedContract() - this.createInstance(selectedContract, inputsValues) + await this.createInstance(selectedContract, inputsValues) if (this.ipfsCheckedState) { publishToStorage('ipfs', this.runView.fileProvider, this.runView.fileManager, selectedContract) }