Skip to content

Commit 085650e

Browse files
fix: balance format issue (#281)
1 parent 3ee2e6f commit 085650e

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/invoice-dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestnetwork/invoice-dashboard",
3-
"version": "0.11.13",
3+
"version": "0.11.14",
44
"main": "./dist/web-component.umd.cjs",
55
"scripts": {
66
"dev": "vite dev",

packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,6 @@
479479
: value;
480480
}
481481
482-
function formatBalance(value: number, maxDecimals: number = 4): string {
483-
try {
484-
return Number.isInteger(value)
485-
? value.toString()
486-
: value.toFixed(maxDecimals);
487-
} catch (error) {
488-
console.error("Error formatting balance:", error);
489-
return "-";
490-
}
491-
}
492-
493482
async function checkBalance() {
494483
try {
495484
if (!address || !paymentCurrencies[0] || !network) {
@@ -515,16 +504,15 @@
515504
token: paymentCurrencies[0].address as `0x${string}`,
516505
chainId: invoiceNetworkId,
517506
});
518-
const balanceNum = BigInt(balance.formatted);
519-
userBalance = formatBalance(balanceNum);
507+
;
508+
userBalance = balance.formatted;
520509
hasEnoughBalance = balance.value >= BigInt(request.expectedAmount);
521510
} else {
522511
const balance = await getBalance(wagmiConfig, {
523512
address,
524513
chainId: invoiceNetworkId,
525514
});
526-
const balanceNum = BigInt(balance.formatted);
527-
userBalance = formatBalance(balanceNum);
515+
userBalance = balance.formatted;
528516
hasEnoughBalance = balance.value >= BigInt(request.expectedAmount);
529517
}
530518
} catch (err) {
@@ -847,7 +835,7 @@
847835
{#if !isPayee && !unsupportedNetwork && !isPaid && !isRequestPayed && !isSigningTransaction}
848836
{#if !hasEnoughBalance}
849837
<div class="balance-warning">
850-
Insufficient funds: {userBalance}
838+
Insufficient funds: {Number(userBalance).toFixed(4)}
851839
{paymentCurrencies[0]?.symbol || "-"}
852840
</div>
853841
{/if}

0 commit comments

Comments
 (0)