Skip to content

Commit

Permalink
Merge pull request #705 from nervosnetwork/rc/v0.1.0-alpha.12
Browse files Browse the repository at this point in the history
[ᚬmaster] Release v0.1.0 alpha.12
  • Loading branch information
ashchan authored Jul 19, 2019
2 parents cf6b006 + bec352c commit 95a10b9
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 148 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.1.0-alpha.11",
"version": "0.1.0-alpha.12",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nervosnetwork/neuron",
"productName": "Neuron",
"description": "CKB Neuron Wallet",
"version": "0.1.0-alpha.11",
"version": "0.1.0-alpha.12",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/neuron-ui",
"version": "0.1.0-alpha.11",
"version": "0.1.0-alpha.12",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/History/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useSearch = (search: string = '', walletID: string = '', dispatch:

dispatch(actionCreators.getTransactions({ ...params, keywords: params.keywords, walletID }))
}, [search, walletID, dispatch])
return { keywords, onKeywordsChange }
return { keywords, onKeywordsChange, setKeywords }
}

export default {
Expand Down
9 changes: 7 additions & 2 deletions packages/neuron-ui/src/components/History/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react'
import React, { useCallback, useEffect } from 'react'
import { RouteComponentProps } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Stack, SearchBox, getTheme } from 'office-ui-fabric-react'
Expand Down Expand Up @@ -42,7 +42,12 @@ const History = ({
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps>) => {
const [t] = useTranslation()

const { keywords, onKeywordsChange } = useSearch(search, id, dispatch)
const { keywords, onKeywordsChange, setKeywords } = useSearch(search, id, dispatch)
useEffect(() => {
if (id) {
setKeywords('')
}
}, [id, setKeywords])
const onSearch = useCallback(() => history.push(`${Routes.History}?keywords=${keywords}`), [history, keywords])

return (
Expand Down
9 changes: 5 additions & 4 deletions packages/neuron-ui/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,17 @@ const Overview = ({
<Text as="h1" variant={TITLE_FONT_SIZE}>
{name}
</Text>
<Stack horizontal>
<Stack horizontal horizontalAlign="space-between">
<PropertyList columns={balanceColumns} items={balanceItems} isHeaderVisible={false} />
<Stack tokens={{ childrenGap: 15 }}>
<div ref={blockchainInfoRef}>
<DefaultButton onClick={showBlockchainStatus} styles={{ root: { width: '200px' } }}>
Blockchain Status
{t('overview.blockchain-status')}
</DefaultButton>
</div>
<div ref={minerInfoRef}>
<DefaultButton onClick={showMinerInfo} styles={{ root: { width: '200px' } }}>
Miner Info
{t('overview.miner-info')}
</DefaultButton>
</div>
</Stack>
Expand All @@ -311,9 +311,10 @@ const Overview = ({
</Stack>
</Callout>
) : null}
{/* TODO: Implement this */}
{minerInfoRef.current ? (
<Callout target={minerInfoRef.current} hidden={!displayMinerInfo} onDismiss={hideMinerInfo} gapSpace={0}>
Miner Info
{t('overview.miner-info')}
</Callout>
) : null}
</Stack>
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/Receive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const Receive = ({
{t('receive.address-qrcode')}
</Text>
</Stack>
<Stack padding="15px">
<Stack tokens={{ padding: '15px' }}>
<QRCode value={accountAddress} size={400} />
</Stack>
</Modal>
Expand Down
24 changes: 9 additions & 15 deletions packages/neuron-ui/src/containers/Main/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,15 @@ export const useSyncChainData = ({ chainURL, dispatch }: { chainURL: string; dis

export const useOnCurrentWalletChange = ({
walletID,
chain,
pageNo,
pageSize,
dispatch,
history,
}: {
walletID: string
chain: State.Chain
pageNo: number
pageSize: number

dispatch: StateDispatch
history: any
}) => {
Expand All @@ -498,27 +501,18 @@ export const useOnCurrentWalletChange = ({
walletsCall.getAllAddresses(walletID)
transactionsCall.getAllByKeywords({
walletID,
keywords: chain.transactions.keywords,
pageNo: chain.transactions.pageNo,
pageSize: chain.transactions.pageSize,
keywords: '',
pageNo,
pageSize,
})
transactionsCall.get(walletID, chain.transaction.hash)
} else {
history.push(`${Routes.WalletWizard}${WalletWizardPath.Welcome}`)
dispatch({
type: NeuronWalletActions.Wallet,
payload: initStates.wallet,
})
}
}, [
walletID,
chain.transactions.pageNo,
chain.transactions.pageSize,
chain.transactions.keywords,
chain.transaction.hash,
dispatch,
history,
])
}, [walletID, pageNo, pageSize, dispatch, history])
}

export default {
Expand Down
13 changes: 10 additions & 3 deletions packages/neuron-ui/src/containers/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ const MainContent = ({
}: React.PropsWithoutRef<{ dispatch: StateDispatch } & RouteComponentProps>) => {
const neuronWalletState = useState()
const {
chain: { networkID },
wallet: { id: walletID },
chain: {
networkID,
transactions: { pageNo, pageSize },
},
settings: { networks },
} = neuronWalletState
const [, i18n] = useTranslation()
Expand All @@ -129,12 +133,15 @@ const MainContent = ({
chainURL,
dispatch,
})

useOnCurrentWalletChange({
walletID: neuronWalletState.wallet.id,
chain: neuronWalletState.chain,
walletID,
pageNo,
pageSize,
dispatch,
history,
})

return (
<>
{mainContents.map(container => (
Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
"datetime": "Date & Time",
"status": "Status",
"amount": "Amount",
"blockchain-status": "Blockchain Status",
"chain-identity": "Chain Identity",
"tip-block-number": "Block Number",
"epoch": "Epoch",
"difficulty": "Difficulty"
"difficulty": "Difficulty",
"miner-info": "Miner Info"
},
"wizard": {
"welcome-to-nervos-neuron": "Welcome to Neuron",
Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
"datetime": "时间",
"status": "状态",
"amount": "金额",
"blockchain-status": "链状态",
"chain-identity": "链的 ID",
"tip-block-number": "区块高度",
"epoch": "Epoch",
"difficulty": "难度"
"difficulty": "难度",
"miner-info": "挖矿信息"
},
"wizard": {
"welcome-to-nervos-ckb": "欢迎使用 Neuron",
Expand Down
8 changes: 4 additions & 4 deletions packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "Neuron",
"description": "CKB Neuron Wallet",
"homepage": "https://www.nervos.org/",
"version": "0.1.0-alpha.11",
"version": "0.1.0-alpha.12",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down Expand Up @@ -48,15 +48,15 @@
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.15.1",
"@nervosnetwork/neuron-ui": "0.1.0-alpha.11",
"@nervosnetwork/neuron-ui": "0.1.0-alpha.12",
"@types/async": "3.0.0",
"@types/electron-devtools-installer": "2.2.0",
"@types/elliptic": "6.4.8",
"@types/sqlite3": "3.1.5",
"@types/uuid": "3.4.4",
"devtron": "1.4.0",
"electron": "5.0.6",
"electron-builder": "21.0.14",
"electron": "5.0.7",
"electron-builder": "21.1.1",
"electron-devtools-installer": "2.2.4",
"electron-notarize": "0.1.1",
"lint-staged": "8.1.7",
Expand Down
17 changes: 8 additions & 9 deletions packages/neuron-wallet/src/controllers/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import NetworksService from '../../services/networks'
import WalletsService from '../../services/wallets'
import NodeService from '../../services/node'
import WalletsController from '../wallets'
import SyncInfoController from '../sync-info'

import { Controller as ControllerDecorator } from '../../decorators'
import { Channel, ResponseCode } from '../../utils/const'
Expand All @@ -35,16 +36,14 @@ export default class AppController {
walletsService.getAll(),
networksService.getCurrentID(),
networksService.getAll(),
new Promise(resolve => {
nodeService.tipNumberSubject.pipe(take(1)).subscribe(
tipNum => {
resolve(tipNum || '0')
},
() => {
resolve('0')
SyncInfoController.currentBlockNumber()
.then(res => {
if (res.status) {
return res.result.currentBlockNumber
}
)
}),
return '0'
})
.catch(() => '0'),
new Promise(resolve => {
nodeService.connectStatusSubject.pipe(take(1)).subscribe(
status => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReplaySubject } from 'rxjs'
import { debounceTime } from 'rxjs/operators'
import { sampleTime } from 'rxjs/operators'
import windowManager from '../window-manager'
import { Channel, ResponseCode } from '../../utils/const'

Expand All @@ -16,7 +16,7 @@ export class CurrentBlockSubject {
}

static subscribe() {
CurrentBlockSubject.subject.pipe(debounceTime(500)).subscribe(({ blockNumber }) => {
CurrentBlockSubject.subject.pipe(sampleTime(500)).subscribe(({ blockNumber }) => {
windowManager.broadcast(Channel.Chain, 'tipBlockNumber', {
status: ResponseCode.Success,
result: blockNumber,
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/services/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Core from '@nervosnetwork/ckb-sdk-core'
import { interval, BehaviorSubject } from 'rxjs'
import { distinctUntilChanged, flatMap, delay, retry } from 'rxjs/operators'
import { distinctUntilChanged, sampleTime, flatMap, delay, retry } from 'rxjs/operators'
import { ShouldBeTypeOf } from '../exceptions'
import windowManager from '../models/window-manager'
import { Channel, ResponseCode } from '../utils/const'
Expand Down Expand Up @@ -28,7 +28,7 @@ class NodeService {
}

public syncConnectStatus = () => {
this.connectStatusSubject.pipe(distinctUntilChanged()).subscribe(connectStatus => {
this.connectStatusSubject.pipe(sampleTime(10000)).subscribe(connectStatus => {
windowManager.broadcast(Channel.Chain, 'status', {
status: ResponseCode.Success,
result: connectStatus,
Expand Down
17 changes: 10 additions & 7 deletions packages/neuron-wallet/src/services/sync/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Block, BlockHeader } from '../../types/cell-types'
import RangeForCheck from './range-for-check'
import BlockNumber from './block-number'
import Utils from './utils'
import TransactionsService from '../transactions'

export default class Queue {
private q: any
Expand Down Expand Up @@ -38,8 +39,9 @@ export default class Queue {
this.q = async.queue(this.getWorker(), this.concurrent)
}

private regenerateQueue = () => {
this.q.kill()
private regenerateQueue = async () => {
this.kill()
await Utils.sleep(3000)
this.generateQueue()
}

Expand Down Expand Up @@ -84,7 +86,7 @@ export default class Queue {
const blocks: Block[] = await this.getBlocksService.getRangeBlocks(blockNumbers)
const blockHeaders: BlockHeader[] = blocks.map(block => block.header)

// TODO: 2. check blockHeaders
// 2. check blockHeaders
await this.checkBlockHeader(blockHeaders)

// 3. check and save
Expand All @@ -102,15 +104,16 @@ export default class Queue {
const checkResult = this.rangeForCheck.check(blockHeaders)
if (!checkResult.success) {
if (checkResult.type === 'first-not-match') {
// TODO: reset currentBlockNumber
const range = await this.rangeForCheck.getRange()
const rangeFirstBlockHeader: BlockHeader = range[0]
this.currentBlockNumber.updateCurrent(BigInt(rangeFirstBlockHeader.number))
this.regenerateQueue()
await this.currentBlockNumber.updateCurrent(BigInt(rangeFirstBlockHeader.number))
await this.rangeForCheck.setRange([])
await TransactionsService.deleteWhenFork(rangeFirstBlockHeader.number)
await this.regenerateQueue()
this.startBlockNumber = await this.currentBlockNumber.getCurrent()
this.batchPush()
} else if (checkResult.type === 'block-headers-not-match') {
// TODO: throw here and retry 5 times
// throw here and retry 5 times
throw new Error('chain forked')
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/neuron-wallet/src/services/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,21 @@ export default class TransactionsService {
.execute()
}

public static deleteWhenFork = async (blockNumber: string) => {
const txs = await getConnection()
.getRepository(TransactionEntity)
.createQueryBuilder('tx')
.where(
'CAST(tx.blockNumber AS UNSIGNED BIG INT) > CAST(:blockNumber AS UNSIGNED BIG INT) AND tx.status = :status',
{
blockNumber,
status: TransactionStatus.Success,
}
)
.getMany()
return getConnection().manager.remove(txs)
}

// update previousOutput's status to 'dead' if found
// calculate output lockHash, input lockHash and capacity
// when send a transaction, use TxSaveType.Sent
Expand Down
Loading

0 comments on commit 95a10b9

Please sign in to comment.