check for valid min/max length of memeo before executing transaction

This commit is contained in:
Moriz Wahl 2022-03-24 14:36:16 +01:00
parent 6fe7e4c9a2
commit 30543942d8

View File

@ -34,6 +34,9 @@ import { virtualLinkTransaction, virtualDecayTransaction } from '@/util/virtualT
import Decimal from 'decimal.js-light'
import { calculateDecay } from '@/util/decay'
const MEMO_MAX_CHARS = 255
const MEMO_MIN_CHARS = 5
export const executeTransaction = async (
amount: Decimal,
memo: string,
@ -45,6 +48,14 @@ export const executeTransaction = async (
throw new Error('Sender and Recipient are the same.')
}
if (memo.length > MEMO_MAX_CHARS) {
throw new Error(`memo text is too long (${MEMO_MAX_CHARS} characters maximum)`)
}
if (memo.length < MEMO_MIN_CHARS) {
throw new Error(`memo text is too short (${MEMO_MIN_CHARS} characters minimum)`)
}
// validate amount
const receivedCallDate = new Date()
const sendBalance = await calculateBalance(sender.id, amount.mul(-1), receivedCallDate)