Skip to content

Commit

Permalink
chore: dao error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 7, 2019
1 parent 22ee960 commit 55dc8d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/neuron-wallet/src/exceptions/dao.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import i18n from 'utils/i18n'

export class CellIsNotYetLive extends Error {
constructor() {
super(i18n.t('messages.cell-is-not-yet-live'))
}
}

export class TransactionIsNotCommittedYet extends Error {
constructor() {
super(i18n.t('messages.transaction-is-not-committed-yet'))
}
}
2 changes: 2 additions & 0 deletions packages/neuron-wallet/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export default {
'should-be-type-of': '{{field}} should be type of {{type}}',
'invalid-keystore': 'Keystore is invalid',
'invalid-json': 'Invalid JSON file',
'cell-is-not-yet-live': 'Cell is not yet live!',
'transaction-is-not-committed-yet': 'Transaction is not committed yet!'
},
contextMenu: {
select: 'Select',
Expand Down
2 changes: 2 additions & 0 deletions packages/neuron-wallet/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default {
'should-be-type-of': '{{field}} 应该为 {{type}} 类型',
'invalid-keystore': 'Keystore 格式不正确',
'invalid-json': 'JSON 文件格式不正确',
'cell-is-not-yet-live': 'Cell 尚未激活',
'transaction-is-not-committed-yet': '交易未提交'
},
contextMenu: {
select: '选择',
Expand Down
9 changes: 5 additions & 4 deletions packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import TypeConvert from 'types/type-convert'
import DaoUtils from 'models/dao-utils'
import { WitnessArgs } from 'types/cell-types'
import FeeMode from 'models/fee-mode'
import { CellIsNotYetLive, TransactionIsNotCommittedYet } from 'exceptions/dao'

const { core } = NodeService.getInstance()
const fileService = FileService.getInstance()
Expand Down Expand Up @@ -511,11 +512,11 @@ export default class WalletService {

const cellStatus = await core.rpc.getLiveCell(outPoint, false)
if (cellStatus.status !== 'live') {
throw new Error('Cell is not yet live!')
throw new CellIsNotYetLive()
}
const tx = await core.rpc.getTransaction(outPoint.txHash)
if (tx.txStatus.status !== 'committed') {
throw new Error('Transaction is not committed yet!')
throw new TransactionIsNotCommittedYet()
}

const addressInfos = await this.getAddressInfos(walletID)
Expand Down Expand Up @@ -625,11 +626,11 @@ export default class WalletService {

const cellStatus = await core.rpc.getLiveCell(withdrawingOutPoint, true)
if (cellStatus.status !== 'live') {
throw new Error('Cell is not yet live!')
throw new CellIsNotYetLive()
}
const tx = await core.rpc.getTransaction(withdrawingOutPoint.txHash)
if (tx.txStatus.status !== 'committed') {
throw new Error('Transaction is not committed yet!')
throw new TransactionIsNotCommittedYet()
}
const content = cellStatus.cell.data!.content
const buf = Buffer.from(content.slice(2), 'hex')
Expand Down

0 comments on commit 55dc8d8

Please sign in to comment.