From f470ce5daafe41f05c1bc735288099e279a678c4 Mon Sep 17 00:00:00 2001 From: Polybius93 <99192647+Polybius93@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:06:41 +0100 Subject: [PATCH] feat: add minimum limit for burn amount (#226) --- package.json | 2 +- .../transaction-screen.transaction-form.tsx | 10 ++++++++-- yarn.lock | 8 ++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 9e7e530..360bdd5 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "concurrently": "^8.2.2", "d3": "^7.9.0", "decimal.js": "^10.4.3", - "dlc-btc-lib": "2.5.1", + "dlc-btc-lib": "2.5.4", "dotenv": "^16.3.1", "ethers": "5.7.2", "formik": "^2.4.5", diff --git a/src/app/components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form.tsx b/src/app/components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form.tsx index f5a4a71..aae7278 100644 --- a/src/app/components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form.tsx +++ b/src/app/components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form.tsx @@ -34,11 +34,17 @@ function validateDepositAmount( return error; } -function validateBurnAmount(value: number, valueMinted: number): string | undefined { +function validateBurnAmount( + value: number, + valueMinted: number, + depositLimit: { minimumDeposit: number; maximumDeposit: number } +): string | undefined { let error; if (!value) { error = 'Please enter a valid amount of iBTC'; + } else if (depositLimit && value < depositLimit.minimumDeposit) { + error = `You can't burn less than ${depositLimit.minimumDeposit} BTC`; } else if (valueMinted && value > valueMinted) { error = `You can't burn more than ${valueMinted} iBTC`; } @@ -61,7 +67,7 @@ function validateFormAmount( case 'mint': return validateDepositAmount(value, depositLimit); case 'burn': - return validateBurnAmount(value, vault.valueMinted); + return validateBurnAmount(value, vault.valueMinted, depositLimit); } } diff --git a/yarn.lock b/yarn.lock index 135c23f..b5c28a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5220,10 +5220,10 @@ dir-glob@^3.0.1: dependencies: path-type "^4.0.0" -dlc-btc-lib@2.5.1: - version "2.5.1" - resolved "https://registry.yarnpkg.com/dlc-btc-lib/-/dlc-btc-lib-2.5.1.tgz#b1eb33c0a56a244fcb109da4704854cf8a585c15" - integrity sha512-YRfIsfsgzmUcepowZYaLjY/1E2MJbN5zIhEhS1NgiJsDBjNVAiZTHLY7RiX3eNValgFSnsY3IpUyF6piPap72A== +dlc-btc-lib@2.5.4: + version "2.5.4" + resolved "https://registry.yarnpkg.com/dlc-btc-lib/-/dlc-btc-lib-2.5.4.tgz#265dcc14f3a6f090bb19dbb9753c36359f65b615" + integrity sha512-EYm7pupdooxexGlTuljsCU31hl3v0OoA4Oers8Anwf4FkZPsItIxFMV2HpFy/cmDlGuwtzKw9RNLXun10KcLLg== dependencies: "@dfns/sdk" "^0.5.9" "@dfns/sdk-browser" "^0.5.9"