Skip to content

Commit ed14e4c

Browse files
committed
Merge branch 'develop' into rc/v0.1.0-alpha.0
2 parents 04bd741 + c3fd9b7 commit ed14e4c

File tree

23 files changed

+203
-48
lines changed

23 files changed

+203
-48
lines changed

packages/neuron-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"grommet-icons": "4.2.0",
4242
"history": "4.9.0",
4343
"i18next": "15.1.3",
44+
"office-ui-fabric-react": "7.6.1",
4445
"qr.js": "0.0.0",
4546
"react": "16.8.6",
4647
"react-bootstrap": "1.0.0-beta.9",

packages/neuron-ui/src/components/GeneralSetting/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import { PrimaryButton } from 'office-ui-fabric-react'
23
import styled from 'styled-components'
34

45
const ContentPanel = styled.div`
@@ -10,7 +11,13 @@ const ContentPanel = styled.div`
1011
`
1112

1213
const General = () => {
13-
return <ContentPanel />
14+
return (
15+
<ContentPanel>
16+
<PrimaryButton data-automation-id="test" disabled={false} checked={false} allowDisabledFocus>
17+
This is a temporary button
18+
</PrimaryButton>
19+
</ContentPanel>
20+
)
1421
}
1522

1623
export default General

packages/neuron-ui/src/components/Transaction/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ const Transaction = (props: React.PropsWithoutRef<ContentProps & RouteComponentP
4444
</Card.Header>
4545
<Card.Body>
4646
{errorMsgs.transaction ? <Alert variant="warning">{t(`messages.${errorMsgs.transaction}`)}</Alert> : null}
47-
<Card.Text>
48-
<b>{`${t('history.amount')}: `}</b>
49-
{transaction.value}
50-
</Card.Text>
5147
<Card.Text>
5248
<div>
5349
<b>{`${t('history.date')}: `}</b>

packages/neuron-wallet/src/controllers/app/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default class AppController {
100100
}
101101

102102
public static navTo(url: string) {
103-
windowManager.sendToFocusedWindow(Channel.App, 'navTo', {
103+
windowManager.sendToMainWindow(Channel.App, 'navTo', {
104104
status: ResponseCode.Success,
105105
result: url,
106106
})
@@ -202,7 +202,7 @@ export default class AppController {
202202
preload: path.join(__dirname, '../../startup/preload.js'),
203203
},
204204
})
205-
win.loadURL(`${env.mainURL}/#/transaction/${hash}`)
205+
win.loadURL(`${env.mainURL}#/transaction/${hash}`)
206206
win.on('ready-to-show', () => {
207207
win.show()
208208
win.focus()

packages/neuron-wallet/src/controllers/transactions.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import WalletsService from '../services/wallets'
77
import { Controller as ControllerDecorator, CatchControllerError } from '../decorators'
88
import { Channel, ResponseCode } from '../utils/const'
99
import { TransactionNotFound, CurrentWalletNotSet, ServiceHasNoResponse } from '../exceptions'
10+
import LockUtils from '../models/lock-utils'
1011

1112
/**
1213
* @class TransactionsController
@@ -60,6 +61,31 @@ export default class TransactionsController {
6061

6162
if (!transaction) throw new TransactionNotFound(hash)
6263

64+
const wallet = WalletsService.getInstance().getCurrent()
65+
if (!wallet) throw new CurrentWalletNotSet()
66+
const addresses: string[] = (await AddressService.allAddressesByWalletId(wallet.id)).map(addr => addr.address)
67+
const lockHashes: string[] = await Promise.all(
68+
addresses.map(async addr => {
69+
return LockUtils.addressToLockHash(addr)
70+
})
71+
)
72+
73+
const outputCapacities: bigint = transaction
74+
.outputs!.filter(o => lockHashes.includes(o.lockHash!))
75+
.map(o => BigInt(o.capacity))
76+
.reduce((result, c) => result + c, BigInt(0))
77+
const inputCapacities: bigint = transaction
78+
.inputs!.filter(i => {
79+
if (i.lockHash) {
80+
return lockHashes.includes(i.lockHash)
81+
}
82+
return false
83+
})
84+
.map(i => BigInt(i.capacity))
85+
.reduce((result, c) => result + c, BigInt(0))
86+
const value: bigint = outputCapacities - inputCapacities
87+
transaction.value = value.toString()
88+
6389
return {
6490
status: ResponseCode.Success,
6591
result: transaction,

packages/neuron-wallet/src/controllers/wallets/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export default class WalletsController {
8888
extendedKey: accountExtendedPublicKey.serialize(),
8989
keystore,
9090
})
91+
92+
await walletsService.generateAddressesById(wallet.id)
93+
9194
return {
9295
status: ResponseCode.Success,
9396
result: {
@@ -107,16 +110,11 @@ export default class WalletsController {
107110
password: string
108111
mnemonic: string
109112
}): Promise<Controller.Response<Omit<WalletProperties, 'extendedKey'>>> {
110-
const response = await WalletsController.importMnemonic({
113+
return WalletsController.importMnemonic({
111114
name,
112115
password,
113116
mnemonic,
114117
})
115-
if (response && response.result) {
116-
const walletId = response.result.id
117-
await walletsService.generateAddressesById(walletId)
118-
}
119-
return response
120118
}
121119

122120
@CatchControllerError

packages/neuron-wallet/src/database/address/dao.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AddressType } from '../../models/keys/address'
44
import { getConnection } from './ormconfig'
55
import TransactionsService from '../../services/transactions'
66
import CellsService from '../../services/cells'
7-
import LockUtils from '../../utils/lock-utils'
7+
import LockUtils from '../../models/lock-utils'
88

99
export interface Address {
1010
walletId: string
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import FileService from '../../services/file'
2+
import { SystemScript } from '../../models/lock-utils'
3+
4+
const moduleName = 'cells'
5+
const fileName = 'meta-info.json'
6+
7+
export interface MetaInfo {
8+
genesisBlockHash: string
9+
systemScriptInfo: SystemScript
10+
}
11+
12+
export const updateMetaInfo = (metaInfo: MetaInfo) => {
13+
FileService.getInstance().writeFileSync(moduleName, fileName, JSON.stringify(metaInfo))
14+
}
15+
16+
export const getMetaInfo = (): MetaInfo => {
17+
const info = FileService.getInstance().readFileSync(moduleName, fileName)
18+
return JSON.parse(info)
19+
}

packages/neuron-wallet/src/main.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,30 @@ import i18n from './utils/i18n'
44
import { updateApplicationMenu } from './utils/application-menu'
55

66
import Router from './router'
7-
import createWindow from './startup/create-window'
7+
import WindowManager from './models/window-manager'
8+
import createMainWindow from './startup/create-main-window'
89
import createSyncBlockTask from './startup/sync-block-task/create'
910
import initConnection from './database/address/ormconfig'
1011
import WalletsService from './services/wallets'
1112

1213
const walletsService = WalletsService.getInstance()
1314

14-
let mainWindow: Electron.BrowserWindow | null
15-
1615
const router = new Router()
1716

1817
Object.defineProperty(app, 'router', {
1918
value: router,
2019
})
2120

2221
const openWindow = () => {
23-
if (!mainWindow) {
24-
mainWindow = createWindow()
25-
mainWindow.on('closed', () => {
22+
if (!WindowManager.mainWindow) {
23+
WindowManager.mainWindow = createMainWindow()
24+
WindowManager.mainWindow.on('closed', () => {
2625
if (process.platform !== 'darwin') {
2726
app.quit()
2827
}
29-
if (mainWindow) {
30-
mainWindow.removeAllListeners()
31-
mainWindow = null
28+
if (WindowManager.mainWindow) {
29+
WindowManager.mainWindow.removeAllListeners()
30+
WindowManager.mainWindow = null
3231
}
3332
})
3433
}

packages/neuron-wallet/src/utils/lock-utils.ts renamed to packages/neuron-wallet/src/models/lock-utils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ import env from '../env'
44

55
const { core } = NodeService.getInstance()
66

7+
export interface SystemScript {
8+
codeHash: string
9+
outPoint: OutPoint
10+
}
11+
712
export default class LockUtils {
8-
static systemScriptInfo: { codeHash: string; outPoint: OutPoint } | undefined
13+
static systemScriptInfo: SystemScript | undefined
914

10-
static async systemScript() {
15+
static async systemScript(): Promise<SystemScript> {
1116
if (this.systemScriptInfo) {
1217
return this.systemScriptInfo
1318
}
@@ -47,6 +52,10 @@ export default class LockUtils {
4752
return systemScriptInfo
4853
}
4954

55+
static setSystemScript(info: SystemScript) {
56+
LockUtils.systemScriptInfo = info
57+
}
58+
5059
// use SDK lockScriptToHash
5160
static lockScriptToHash = (lock: Script) => {
5261
const codeHash: string = lock!.codeHash!

0 commit comments

Comments
 (0)