Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement component for changing node url #1568

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ ipcMain.on('shutdown-finished', () => {
app.exit()
})

ipcMain.on('close-wallet', () => {
win.hide()
if (walletProcess) {
kill(walletProcess.pid)
}
app.exit()
})

// check if the second instance in locked
const lock = app.requestSingleInstanceLock()

Expand Down Expand Up @@ -486,7 +494,6 @@ autoUpdater.on('update-available', () => {
autoUpdater
.downloadUpdate()
.then(path => {
win.webContents.send('log', `${path}`)
console.log('Release path to download', path)
})
.catch(e => {
Expand All @@ -512,6 +519,24 @@ autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall()
})

ipcMain.on('change-node-url', async (event, url) => {
await overwriteWalletDefaultConfigFile(url)
app.relaunch()
win.webContents.send('closeWallet')
})

// Overwrite wallet config file only when new version is downloaded
function overwriteWalletDefaultConfigFile(url) {
const regex = /^node_url = ".*"$/gm
fs.writeFileSync(
path.join(SHEIKAH_PATH, WITNET_CONFIG_FILE_NAME),
fs
.readFileSync(path.join(SHEIKAH_PATH, WITNET_CONFIG_FILE_NAME))
.toString()
.replace(regex, `node_url = "${url}"\n`),
)
}

// Overwrite wallet config file only when new version is downloaded
function overwriteWalletConfigFile() {
fs.writeFileSync(
Expand Down
23 changes: 23 additions & 0 deletions src/components/NodeUrlSettings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<div>
<el-input v-model="nodeUrl" />
<el-button type="primary" @click="setLocalNodeUrl(nodeUrl)">
Change and restart
</el-button>
</div>
</template>

<script>
import { setLocalNodeUrl } from '@/ipcHandlers'
export default {
name: 'Send',
data() {
return {
nodeUrl: null,
}
},
methods: {
setLocalNodeUrl,
},
}
</script>
13 changes: 13 additions & 0 deletions src/ipcHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ ipcRenderer.on('shutdown', async () => {
ipcRenderer.send('shutdown-finished')
})

ipcRenderer.on('closeWallet', async () => {
await store.dispatch('shutdown')
ipcRenderer.send('close-wallet')
})

ipcRenderer.on('log', async (event, message) => {
console.log(message)
})

ipcRenderer.on('running', async (event, message) => {
store.commit('setMessage', { message: 'Running wallet' })
})
Expand All @@ -16,6 +25,10 @@ ipcRenderer.on('downloading', async () => {
store.commit('setMessage', { message: 'Updating wallet backend' })
})

export function setLocalNodeUrl(url) {
ipcRenderer.send('change-node-url', url)
}

ipcRenderer.on('loaded', async (e, message) => {
if (Array.isArray(message) && message[0].isDefaultWallet) {
store.commit('setWalletOwner', { isDefaultWallet: true })
Expand Down