Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ module.exports = {
"no-plusplus": [0],
"no-console": [2, {
"allow": ["warn", "error", "info"]
}]
}],
"lines-between-class-members": ["error", "always", { exceptAfterSingleLine: true }]
},
"globals": {
"BigInt": "readonly"
Expand Down
2 changes: 0 additions & 2 deletions packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"bip39": "3.0.2",
"chalk": "2.4.2",
"crypto-browserify": "3.12.0",
"electron-store": "3.2.0",
"electron-window-state": "5.0.3",
"i18next": "15.0.5",
"reflect-metadata": "0.1.13",
Expand All @@ -73,7 +72,6 @@
"@nervosnetwork/neuron-ui": "0.1.0",
"@types/bip39": "2.4.2",
"@types/electron-devtools-installer": "2.2.0",
"@types/electron-store": "1.3.0",
"@types/sqlite3": "3.1.5",
"@types/uuid": "3.4.4",
"devtron": "1.4.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/neuron-wallet/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import path from 'path'
import os from 'os'
import { app as electronApp } from 'electron'

const fakeApp = {
getPath(path: string): string {
return path
getPath(aPath: string): string {
return path.join(os.tmpdir(), aPath)
},
}
const app = electronApp || fakeApp
Expand Down
44 changes: 22 additions & 22 deletions packages/neuron-wallet/src/controllers/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import WalletsService from '../services/wallets'
import { WalletData } from '../store/walletStore'
import WalletsService, { Wallet, WalletProperties } from '../services/wallets'
import { ChannelResponse, ResponseCode } from '.'
import windowManage from '../utils/windowManage'
import { Channel } from '../utils/const'
Expand All @@ -22,7 +21,7 @@ export enum WalletsMethod {
class WalletsController {
static service = new WalletsService()

public static getAll = (): ChannelResponse<WalletData[]> => {
public static getAll = (): ChannelResponse<Wallet[]> => {
const wallets = WalletsController.service.getAll()
if (wallets) {
return {
Expand All @@ -36,7 +35,7 @@ class WalletsController {
}
}

public static get = (id: string): ChannelResponse<WalletData> => {
public static get = (id: string): ChannelResponse<Wallet> => {
const wallet = WalletsController.service.get(id)
if (wallet) {
return {
Expand Down Expand Up @@ -76,7 +75,7 @@ class WalletsController {
mnemonic: string
receivingAddressNumber: number
changeAddressNumber: number
}): Promise<ChannelResponse<WalletData>> => {
}): Promise<ChannelResponse<Wallet>> => {
try {
const key = await Key.fromMnemonic(mnemonic, password, receivingAddressNumber, changeAddressNumber)
const wallet = WalletsController.service.create({
Expand Down Expand Up @@ -109,7 +108,7 @@ class WalletsController {
mnemonic: string
receivingAddressNumber: number
changeAddressNumber: number
}): Promise<ChannelResponse<WalletData>> => {
}): Promise<ChannelResponse<Wallet>> => {
const res = await WalletsController.importMnemonic({
name,
password,
Expand All @@ -132,7 +131,7 @@ class WalletsController {
keystore: string
receivingAddressNumber: number
changeAddressNumber: number
}): ChannelResponse<WalletData> => {
}): ChannelResponse<Wallet> => {
try {
const key = Key.fromKeystore(keystore, password, receivingAddressNumber, changeAddressNumber)
const wallet = WalletsController.service.create({
Expand All @@ -153,6 +152,7 @@ class WalletsController {
}
}

// TODO: update addresses?
public static update = ({
id,
name,
Expand All @@ -163,17 +163,17 @@ class WalletsController {
password: string
name: string
newPassword?: string
}): ChannelResponse<WalletData> => {
}): ChannelResponse<Wallet> => {
try {
const wallet = WalletsController.service.get(id)
if (wallet) {
if (WalletsController.service.validate({ id, password })) {
wallet.name = name
const props: WalletProperties = { name, addresses: wallet.addresses, keystore: null }
if (newPassword) {
const key = Key.fromKeystore(JSON.stringify(wallet!.keystore), password)
wallet.keystore = key.toKeystore(JSON.stringify(key.keysData!), newPassword)
const key = Key.fromKeystore(JSON.stringify(wallet!.loadKeystore()), password)
props.keystore = key.toKeystore(JSON.stringify(key.keysData!), newPassword)
}
WalletsController.service.update(id, wallet)
WalletsController.service.update(id, props)
windowManage.broadcast(Channel.Wallets, WalletsMethod.GetAll, WalletsController.getAll())
return {
status: ResponseCode.Success,
Expand Down Expand Up @@ -204,7 +204,7 @@ class WalletsController {
status: ResponseCode.Success,
result: {
allWallets: WalletsController.service.getAll(),
activeWallet: WalletsController.service.getActive(),
activeWallet: WalletsController.service.getCurrent(),
},
}
}
Expand Down Expand Up @@ -235,8 +235,8 @@ class WalletsController {
}

public static getActive = () => {
try {
const activeWallet = WalletsController.service.getActive()
const activeWallet = WalletsController.service.getCurrent()
if (activeWallet) {
return {
status: ResponseCode.Success,
result: {
Expand All @@ -247,21 +247,21 @@ class WalletsController {
},
},
}
} catch (e) {
return {
status: ResponseCode.Fail,
msg: 'No active wallet',
}
}

return {
status: ResponseCode.Fail,
msg: 'No active wallet',
}
}

public static activate = (id: string) => {
const success = WalletsController.service.setActive(id)
const success = WalletsController.service.setCurrent(id)
if (success) {
windowManage.broadcast(Channel.Wallets, WalletsMethod.GetActive, WalletsController.getActive())
return {
status: ResponseCode.Success,
result: WalletsController.service.getActive(),
result: WalletsController.service.getCurrent(),
}
}
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/keys/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as bip39 from 'bip39'
import crypto from 'crypto-browserify'
import scryptsy from 'scrypt.js'
import SHA3 from 'sha3'
import { v4 } from 'uuid'
import { v4 as uuid } from 'uuid'
import Address, { HDAddress } from '../services/addresses'
import { Keystore, KdfParams, KeysData } from './keystore'

Expand Down Expand Up @@ -193,7 +193,7 @@ export default class Key {
.replace('0x', '')
return {
version: 0,
id: v4(),
id: uuid(),
crypto: {
ciphertext: ciphertext.toString('hex'),
cipherparams: {
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 } from 'uuid'
import { v4 as uuid } from 'uuid'

export const transactions = Array.from({
length: 200,
Expand Down Expand Up @@ -27,7 +27,7 @@ export interface Wallet {

const generateWallet = () => {
const walletName = `wallet${parseInt((Math.random() * 1000).toString(), 10)}`
const walletID = v4()
const walletID = uuid()
return {
name: walletName,
id: walletID,
Expand Down
7 changes: 3 additions & 4 deletions packages/neuron-wallet/src/services/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import TransactionsService from './transactions'
import WalletService from './wallets'
import nodeService from '../startup/nodeService'
import HD from '../keys/hd'
import { KeysData } from '../keys/keystore'
// TODO: Should use service
import WalletStore from '../store/walletStore'
import nodeService from '../startup/nodeService'

const {
utils: { AddressPrefix, AddressType: Type, AddressBinIdx, pubkeyToAddress },
Expand Down Expand Up @@ -67,7 +66,7 @@ class Address {
}

public static allAddresses = () =>
new WalletStore().getAllWallets().reduce((total: HDAddress[], cur) => {
new WalletService().getAll().reduce((total: HDAddress[], cur) => {
return [...total, ...cur.addresses.change, ...cur.addresses.receiving]
}, [])

Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/services/networks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 } from 'uuid'
import { v4 as uuid } from 'uuid'
import Store from '../utils/store'
import env from '../env'

Expand Down Expand Up @@ -83,7 +83,7 @@ export default class NetworksService extends Store {
throw new Error('Network name exists')
}
const newOne = {
id: v4(),
id: uuid(),
name,
remote,
type,
Expand Down
Loading