added balance check for converting assets

This commit is contained in:
sairaj mote 2022-08-16 01:11:49 +05:30
parent abd6cd78c7
commit cca538ddf5
2 changed files with 35 additions and 8 deletions

View File

@ -513,14 +513,17 @@
<span id="conversion_fees">0.00</span>
</div>
</div>
<button class="button button--primary cta" type="submit">
<svg class="icon margin-right-0-5" xmlns="http://www.w3.org/2000/svg" height="24px"
viewBox="0 0 24 24" width="24px" fill="#000000">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z" />
</svg>
Convert
</button>
<div class="multi-state-button">
<button id="convert_asset_button" class="button button--primary cta" type="submit"
onclick="convertAsset()">
<svg class="icon margin-right-0-5" xmlns="http://www.w3.org/2000/svg" height="24px"
viewBox="0 0 24 24" width="24px" fill="#000000">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z" />
</svg>
Convert
</button>
</div>
</sm-form>
</div>
</div>

View File

@ -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
}