oxen-electron-gui-wallet/src/gateway/gateway.js
Mikunj bcf21c3804 Redesign
Main screen redesign

Removed dark mode styling and made it all dark.

Fix large button styling on navigation

Receive page styling

Startup pages redesign

Updating field stylings.
Fix value display in recieve

Updated footer.

Added service node page.

Added wallet settings.

Added disable prop to loki field.

Update settings page.
Added merging config with default daemon option incase user provides invalid port (empty, null, etc...)

Removed theme selection

Update wallet-select pages

Fixed converting numbers to string

Update layout on address page

Added loki logo.
Made header a bit smaller.

Updated wallet init styling.
Highlight primary address in receive.

updated packages.

Updated transaction styling.

Simpler tx json handling.

Added address validation

Fixed up wallet restoration

Default node to remote.
Added drop down button to the remote node input instead of having it as a seperate field.

Removed review page.
Center align welcome page.

Replaced ryo wallet images with loki image.

Updated transaction styling.

Fix wallet errors only showing once which causes the next error to just show the loading overlay.

Added staking

Fix up status display in footer.
remove is_ready as lokid doesn't return it.

Fixed balance display in receive.
Center unlock in wallet details.

Updated README
other updates.
2019-03-13 15:38:34 +11:00

159 lines
4.9 KiB
JavaScript

import { ipcRenderer } from "electron"
import { Notify, Dialog, Loading, LocalStorage } from "quasar"
import { EventEmitter } from "events"
import { SCEE } from "./SCEE-Node"
export class Gateway extends EventEmitter {
constructor (app, router) {
super()
this.app = app
this.router = router
this.token = null
this.scee = new SCEE()
let theme = LocalStorage.has("theme") ? LocalStorage.get.item("theme") : "dark"
this.app.store.commit("gateway/set_app_data", {
config: {
appearance: {
theme
}
}
})
this.app.store.watch(state => state.gateway.app.config.appearance.theme, (theme) => {
LocalStorage.set("theme", theme)
})
this.closeDialog = false
this.app.store.commit("gateway/set_app_data", {
status: {
code: 1 // Connecting to backend
}
})
ipcRenderer.on("initialize", (event, data) => {
this.token = data.token
setTimeout(() => {
this.ws = new WebSocket("ws://127.0.0.1:" + data.port)
this.ws.addEventListener("open", () => { this.open() })
this.ws.addEventListener("message", (e) => { this.receive(e.data) })
}, 1000)
})
ipcRenderer.on("confirmClose", () => {
this.confirmClose("Are you sure you want to exit?")
})
}
open () {
this.app.store.commit("gateway/set_app_data", {
status: {
code: 2 // Loading config
}
})
this.send("core", "init")
}
confirmClose (msg) {
if (this.closeDialog) {
return
}
this.closeDialog = true
Dialog.create({
title: "Exit",
message: msg,
ok: {
label: "EXIT"
},
cancel: {
flat: true,
label: "CANCEL",
color: this.app.store.state.gateway.app.config.appearance.theme == "dark" ? "white" : "dark"
}
}).then(() => {
this.closeDialog = false
Loading.hide()
this.router.replace({ path: "/quit" })
ipcRenderer.send("confirmClose")
}).catch(() => {
this.closeDialog = false
})
}
send (module, method, data = {}) {
let message = {
module,
method,
data
}
let encrypted_data = this.scee.encryptString(JSON.stringify(message), this.token)
this.ws.send(encrypted_data)
}
receive (message) {
// should wrap this in a try catch, and if fail redirect to error screen
// shouldn't happen outside of dev environment
let decrypted_data = JSON.parse(this.scee.decryptString(message, this.token))
if (typeof decrypted_data !== "object" ||
!decrypted_data.hasOwnProperty("event") ||
!decrypted_data.hasOwnProperty("data")) { return }
switch (decrypted_data.event) {
case "set_valid_address":
this.emit("validate_address", decrypted_data.data)
break
case "set_app_data":
this.app.store.commit("gateway/set_app_data", decrypted_data.data)
break
case "set_daemon_data":
this.app.store.commit("gateway/set_daemon_data", decrypted_data.data)
break
case "set_wallet_data":
case "set_wallet_error":
this.app.store.commit("gateway/set_wallet_data", decrypted_data.data)
break
case "reset_wallet_error":
this.app.store.dispatch("gateway/resetWalletStatus")
break
case "set_tx_status":
this.app.store.commit("gateway/set_tx_status", decrypted_data.data)
break
case "set_stake_status":
this.app.store.commit("gateway/set_stake_status", decrypted_data.data)
break
case "wallet_list":
this.app.store.commit("gateway/set_wallet_list", decrypted_data.data)
break
case "settings_changed_reboot":
this.confirmClose("Changes require restart. Would you like to exit now?")
break
case "show_notification":
let notification = {
type: "positive",
timeout: 1000,
message: ""
}
Notify.create(Object.assign(notification, decrypted_data.data))
break
case "return_to_wallet_select":
this.router.replace({ path: "/wallet-select" })
setTimeout(() => {
// short delay to prevent wallet data reaching the
// websocket moments after we close and reset data
this.app.store.dispatch("gateway/resetWalletData")
}, 250)
break
}
}
}