Skip to content

Commit

Permalink
Merge pull request #174 from MickWang/master
Browse files Browse the repository at this point in the history
 not allow to set keystore path to the installation location;
  • Loading branch information
MickWang authored Jul 19, 2019
2 parents e0cc336 + 21b801f commit d1f1f4f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/common/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {

SetPaths: {
name: 'Keystore File Path',
tips: '*The keystore.db file stores your encrypted private keys. Please make sure your computer is safe and make a backup of your keystore.db file. You need to set a file path for your keystore.',
tips: '*The keystore.db file stores your encrypted private keys. Please make sure your computer is safe and make a backup of your keystore.db file. You need to set a file path for your keystore. Please do not set to the installation location of OWallet.',
close: 'Close',
enter: 'Set file path'
},
Expand Down Expand Up @@ -419,7 +419,7 @@ export default {
en: 'English',
zh: '中文',
pathTit: 'Path: ',
path: 'Save keystore file path',
path: 'Save keystore file path(Please do not set to the installation location of OWallet!)',
change: 'Change',
setNetworkSuccess: 'The network has been set to: ',
wallets: 'Wallets',
Expand All @@ -428,7 +428,9 @@ export default {
help: 'Help',
settings: 'Settings',
nodeAddress: 'Node address',
setNodeSuccess: 'The node address has been set t: '
setNodeSuccess: 'The node address has been set t: ',
notInstallationPath: 'Please do not set to the installation location of OWallet.',
notSetPath: 'You did not set the keystore path.'
},

ledgerWallet: {
Expand Down
10 changes: 6 additions & 4 deletions src/common/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {

SetPaths: {
name: '钱包文件存储路径',
tips: '* 钱包文件keystore.db保存着您的加密私钥,请确保您的PC安全和做好keystore.db文件的备份。您需要设置keystore文件的保存路径。',
tips: '* 钱包文件keystore.db保存着您的加密私钥,请确保您的PC安全和做好keystore.db文件的备份。您需要设置keystore文件的保存路径。请不要设置到OWallet的安装位置以免更新时被覆盖。',
close: '关闭',
enter: '去设置'
},
Expand Down Expand Up @@ -224,7 +224,7 @@ export default {
pksLte2: '联合支付人数量不能少于2人。',
invalidPk: '输入的公钥不正确',
duplicatePks: '联合支付人中不能有重复的公钥',
duplicatePks: '联合支付人中不能有重复的名称'
duplicateNames: '联合支付人中不能有重复的名称'
},

importSharedWallet: {
Expand Down Expand Up @@ -418,7 +418,7 @@ export default {
en: 'English',
zh: '中文',
pathTit: '当前路径: ',
path: '钱包保存路径',
path: '钱包保存路径(请不要设到OWallet的安装位置!)',
change: '修改',
setNetworkSuccess: '网络成功设置为:',
wallets: '钱包',
Expand All @@ -427,7 +427,9 @@ export default {
help: '帮助',
settings: '设置',
nodeAddress: '节点',
setNodeSuccess: '节点成功设置为:'
setNodeSuccess: '节点成功设置为:',
notInstallationPath: '请不要设置到Owallet的安装位置。',
notSetPath: '未设置keystore保存路径。'
},
ledgerWallet: {
nameOfLedgerWallet: 'Ledger钱包名称',
Expand Down
28 changes: 26 additions & 2 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
TEST_NET,
MAIN_NET,
MAIN_NET_LIST,
DEFAULT_SCRYPT
DEFAULT_SCRYPT,
TEST_NET_LIST
} from './consts'
import axios from 'axios'
import store from '../renderer/store'
Expand All @@ -18,6 +19,9 @@ const {
BrowserWindow
} = require('electron').remote;

const os = require('os')
const fs = require('fs')

export function open(url) {
try {
opn(url)
Expand Down Expand Up @@ -54,7 +58,12 @@ export function getNodeUrl() {
// const net = localStorage.getItem('net');
// return net === 'TEST_NET' ? TEST_NET + ':20334' : MAIN_NET + ':20334'
// return 'http://139.219.128.220:20334' //for test
const node = localStorage.getItem('nodeAddress') || MAIN_NET_LIST[0]
const net = localStorage.getItem('net')
let node = localStorage.getItem('nodeAddress');
if(!node) {
node = net === 'TEST_NET' ? TEST_NET_LIST[0] : MAIN_NET_LIST[0]
}
// const node = localStorage.getItem('nodeAddress') || MAIN_NET_LIST[0]
return node + ':20334';
}

Expand Down Expand Up @@ -174,4 +183,19 @@ export function getTokenBalanceUrl(token_type, address) {
const api = `/v2/addresses/${address}/${token_type}/balances`
const url = getExplorerUrl() + api;
return url;
}

export function validateKeystorePath(path) {
const system = os.platform();
if(system.indexOf('win') > -1) {
const files = fs.readdirSync(path)
if(files && files.indexOf('resources') > -1 && files.indexOf('OWallet.exe') > -1) {
return false;
}
const cwd = process.cwd();
if(path && (path === cwd || path.indexOf(cwd) > -1)) {
return false;
}
}
return true;
}
10 changes: 10 additions & 0 deletions src/renderer/components/Modals/SetPath.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script>
import $ from 'jquery'
import {mapState} from 'vuex'
import { validateKeystorePath } from '../../../core/utils'
const {dialog} = require('electron').remote;
Expand All @@ -34,6 +35,15 @@
alert('You did not set the path')
return;
}
if (filePath === undefined) {
// alert('You did not set the path')
this.$message.warning(this.$t('setting.notSetPath'))
return;
}
if (!validateKeystorePath(filePath[0])) {
this.$message.warning(this.$t('setting.notInstallationPath'))
return;
}
localStorage.setItem('savePath', filePath)
localStorage.setItem('isSavePath', 'true')
window.location.reload();//reset dbService
Expand Down
9 changes: 8 additions & 1 deletion src/renderer/components/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
import Breadcrumb from './Breadcrumb'
import LangStorage from './../../core/lang'
import { TEST_NET_LIST, MAIN_NET_LIST, TEST_NET} from '../../core/consts'
import { validateKeystorePath, validateAddress } from '../../core/utils'
const {dialog} = require('electron').remote;
export default {
name: 'Setting',
data() {
Expand Down Expand Up @@ -95,7 +97,12 @@
setSavePath() {
dialog.showOpenDialog({properties: ['openDirectory','createDirectory']}, (filePath) => {
if (filePath === undefined) {
alert('You did not set the path')
// alert('You did not set the path')
this.$message.warning(this.$t('setting.notSetPath'))
return;
}
if (!validateKeystorePath(filePath[0])) {
this.$message.warning(this.$t('setting.notInstallationPath'))
return;
}
localStorage.setItem('savePath', filePath[0])
Expand Down

0 comments on commit d1f1f4f

Please sign in to comment.