From cca538ddf5af9dee6547d5f31d770c67f019d7bc Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Tue, 16 Aug 2022 01:11:49 +0530 Subject: [PATCH] added balance check for converting assets --- index.html | 19 +++++++++++-------- scripts/fn_ui.js | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 03558f0..c5f26e1 100644 --- a/index.html +++ b/index.html @@ -513,14 +513,17 @@ 0.00 - +
+ +
diff --git a/scripts/fn_ui.js b/scripts/fn_ui.js index 2a98f17..94c0b49 100644 --- a/scripts/fn_ui.js +++ b/scripts/fn_ui.js @@ -1393,4 +1393,28 @@ getRef('send_transaction').onclick = evt => { }).finally(_ => { buttonLoader('send_transaction', false) }) +} + +function convertAsset() { + buttonLoader('convert_asset_button', true) + const fromAsset = getRef('from_asset_selector').value; + const fromAmount = parseFloat(getRef('from_amount').value.trim()); + if (fromAsset === 'BTC') { + btc_api.getBalance(btc_api.convert.legacy2bech(myFloID)).then(btcBalance => { + if (btcBalance < fromAmount) { + notify('You do not have enough BTC to convert', 'error'); + buttonLoader('convert_asset_button', false) + return; + } + }) + } else { + floTokenAPI.getBalance(myFloID).then((balance = 0) => { + if(balance < fromAmount) { + notify('You do not have enough rupee tokens to convert', 'error'); + buttonLoader('convert_asset_button', false) + return; + } + }) + } + // use api to convert asset } \ No newline at end of file