Skip to content

Commit

Permalink
feat(neuron-ui): show alert when amount is less than 61 CKB on sendin…
Browse files Browse the repository at this point in the history
…g transaction
  • Loading branch information
Keith-CY committed Jul 27, 2019
1 parent 476a918 commit 837c154
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/neuron-ui/src/components/Send/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IDropdownOption } from 'office-ui-fabric-react'
import { AppActions, StateDispatch } from 'states/stateProvider/reducer'

import { Message } from 'utils/const'
import { verifyAddress } from 'utils/validators'
import { verifyAddress, verifyAmountRange } from 'utils/validators'
import { TransactionOutput } from '.'

const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutput[]; dispatch: StateDispatch }) => {
Expand All @@ -30,6 +30,10 @@ const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutp
errorAction.payload.content = Message.InvalidAmount
return true
}
if (!verifyAmountRange(item.amount)) {
errorAction.payload.content = Message.AmountTooSmall
return true
}
const [, decimal = ''] = item.amount.split('.')
if (decimal.length > 8) {
errorAction.payload.content = Message.InvalidAmount
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@
"error": "Error",
"invalid-mnemonic": "Invalid mnemonic words",
"camera-not-available-or-disabled": "Camera is unavailable or disabled",
"can-not-find-the-default-address": "Cannot find the default address"
"can-not-find-the-default-address": "Cannot find the default address",
"amount-too-small": "Amount should not be less than 61 CKB"
},
"sync": {
"syncing": "Syncing",
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@
"error": "错误",
"invalid-mnemonic": "助记词不合法",
"camera-not-available-or-disabled": "摄像头不可用或被禁用",
"can-not-find-the-default-address": "未获得默认地址"
"can-not-find-the-default-address": "未获得默认地址",
"amount-too-small": "金额应不小于 61 CKB"
},
"sync": {
"syncing": "同步中",
Expand Down
2 changes: 2 additions & 0 deletions packages/neuron-ui/src/utils/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const MAX_NETWORK_NAME_LENGTH = 28
export const ADDRESS_LENGTH = 50
export const MIN_PASSWORD_LENGTH = 8
export const MAX_PASSWORD_LENGTH = 50
export const MIN_AMOUNT = 61
export const PAGE_SIZE = 15
export const UNREMOVABLE_NETWORK = 'Testnet'
export const UNREMOVABLE_NETWORK_ID = '0'
Expand Down Expand Up @@ -58,6 +59,7 @@ export enum Message {
AmountNotEnough = 'messages.amount-not-enough',
IsUnremovable = 'messages.is-unremovable',
ProtocolRequired = 'messages.protocol-required',
AmountTooSmall = 'messages.amount-too-small',
}

export enum MnemonicAction {
Expand Down
7 changes: 6 additions & 1 deletion packages/neuron-ui/src/utils/validators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ADDRESS_LENGTH, MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH } from './const'
import { ADDRESS_LENGTH, MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH, MIN_AMOUNT } from './const'

export const verifyAddress = (address: string): boolean => {
// TODO: verify address, prd required
Expand All @@ -22,7 +22,12 @@ export const verifyWalletSubmission = ({
)
}

export const verifyAmountRange = (amount: string) => {
return +amount >= MIN_AMOUNT
}

export default {
verifyAddress,
verifyWalletSubmission,
verifyAmountRange,
}

0 comments on commit 837c154

Please sign in to comment.