Skip to content

Commit 837c154

Browse files
committed
feat(neuron-ui): show alert when amount is less than 61 CKB on sending transaction
1 parent 476a918 commit 837c154

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

packages/neuron-ui/src/components/Send/hooks.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IDropdownOption } from 'office-ui-fabric-react'
44
import { AppActions, StateDispatch } from 'states/stateProvider/reducer'
55

66
import { Message } from 'utils/const'
7-
import { verifyAddress } from 'utils/validators'
7+
import { verifyAddress, verifyAmountRange } from 'utils/validators'
88
import { TransactionOutput } from '.'
99

1010
const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutput[]; dispatch: StateDispatch }) => {
@@ -30,6 +30,10 @@ const validateTransactionParams = ({ items, dispatch }: { items: TransactionOutp
3030
errorAction.payload.content = Message.InvalidAmount
3131
return true
3232
}
33+
if (!verifyAmountRange(item.amount)) {
34+
errorAction.payload.content = Message.AmountTooSmall
35+
return true
36+
}
3337
const [, decimal = ''] = item.amount.split('.')
3438
if (decimal.length > 8) {
3539
errorAction.payload.content = Message.InvalidAmount

packages/neuron-ui/src/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@
216216
"error": "Error",
217217
"invalid-mnemonic": "Invalid mnemonic words",
218218
"camera-not-available-or-disabled": "Camera is unavailable or disabled",
219-
"can-not-find-the-default-address": "Cannot find the default address"
219+
"can-not-find-the-default-address": "Cannot find the default address",
220+
"amount-too-small": "Amount should not be less than 61 CKB"
220221
},
221222
"sync": {
222223
"syncing": "Syncing",

packages/neuron-ui/src/locales/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@
216216
"error": "错误",
217217
"invalid-mnemonic": "助记词不合法",
218218
"camera-not-available-or-disabled": "摄像头不可用或被禁用",
219-
"can-not-find-the-default-address": "未获得默认地址"
219+
"can-not-find-the-default-address": "未获得默认地址",
220+
"amount-too-small": "金额应不小于 61 CKB"
220221
},
221222
"sync": {
222223
"syncing": "同步中",

packages/neuron-ui/src/utils/const.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const MAX_NETWORK_NAME_LENGTH = 28
22
export const ADDRESS_LENGTH = 50
33
export const MIN_PASSWORD_LENGTH = 8
44
export const MAX_PASSWORD_LENGTH = 50
5+
export const MIN_AMOUNT = 61
56
export const PAGE_SIZE = 15
67
export const UNREMOVABLE_NETWORK = 'Testnet'
78
export const UNREMOVABLE_NETWORK_ID = '0'
@@ -58,6 +59,7 @@ export enum Message {
5859
AmountNotEnough = 'messages.amount-not-enough',
5960
IsUnremovable = 'messages.is-unremovable',
6061
ProtocolRequired = 'messages.protocol-required',
62+
AmountTooSmall = 'messages.amount-too-small',
6163
}
6264

6365
export enum MnemonicAction {

packages/neuron-ui/src/utils/validators.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ADDRESS_LENGTH, MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH } from './const'
1+
import { ADDRESS_LENGTH, MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH, MIN_AMOUNT } from './const'
22

33
export const verifyAddress = (address: string): boolean => {
44
// TODO: verify address, prd required
@@ -22,7 +22,12 @@ export const verifyWalletSubmission = ({
2222
)
2323
}
2424

25+
export const verifyAmountRange = (amount: string) => {
26+
return +amount >= MIN_AMOUNT
27+
}
28+
2529
export default {
2630
verifyAddress,
2731
verifyWalletSubmission,
32+
verifyAmountRange,
2833
}

0 commit comments

Comments
 (0)