You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
wow-lite-wallet/src/main/config.js

76 lines
2.0 KiB

const fs = require('fs');
export class Config {
constructor(wowdir) {
this._path_cfg = `${wowdir}/wowlight.json`;
this.create();
this.data = this.load();
}
load(){
if (!fs.existsSync(this._path_cfg)) {
console.log('no file yo');
return {};
}
let contents = fs.readFileSync(this._path_cfg, 'utf8');
return JSON.parse(contents);
}
create(){
if (fs.existsSync(this._path_cfg)) {
return;
}
let data = JSON.stringify({
"node": "node.wowne.ro:34568",
"nodes": [
{"address": "node.wowne.ro:34568", "location": "New Jersey, United States", "region": "US"},
{"address": "node.pwned.systems:34568", "location": "Amsterdam, The Netherlands", "region": "EU"},
{"address": "node.wownero.com:34568", "location": "Montreal, Canada", "region": "US"},
{"address": "localhost:34568", 'location': "", "region": "*"}
],
"wallet_path": ""
});
fs.writeFileSync(this._path_cfg, JSON.stringify(data));
console.log(`${this._path_cfg} written`);
}
save(){
fs.writeFileSync(this._path_cfg, JSON.stringify(this.data, null, 4));
console.log(`${this._path_cfg} written`);
}
selectNode(node){
if (typeof this.data === 'string' || this.data instanceof String){
this.data = JSON.parse(this.data);
}
node = node.trim();
if(node === ''){
return;
}
console.log('NEW NODE: ' + node);
this.data.node = node;
this.save();
return true;
}
saveLastWalletPath(path){
if (typeof this.data === 'string' || this.data instanceof String){
this.data = JSON.parse(this.data);
}
if(path === ''){
return;
}
this.data.wallet_path = path;
this.save();
}
}