Skip to content

Commit 141410c

Browse files
committed
chore: add missing functions, updated text on payment chain
1 parent 1ced42c commit 141410c

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
// Utils
3535
import { config as defaultConfig } from "@requestnetwork/shared-utils/config";
3636
import { initializeCurrencyManager } from "@requestnetwork/shared-utils/initCurrencyManager";
37+
import { checkStatus } from "@requestnetwork/shared-utils/checkStatus";
3738
import { exportToPDF } from "@requestnetwork/shared-utils/generateInvoice";
3839
import { getCurrencyFromManager } from "@requestnetwork/shared-utils/getCurrency";
3940
import { CurrencyManager } from "@requestnetwork/currency";
4041
import { onDestroy, onMount, tick } from "svelte";
4142
import { formatUnits } from "viem";
42-
import { capitalize, debounce, formatAddress } from "../utils";
43+
import { debounce, formatAddress } from "../utils";
4344
import { Drawer, InvoiceView } from "./dashboard";
4445
import { getPaymentNetworkExtension } from "@requestnetwork/payment-detection";
4546
import { CurrencyTypes } from "@requestnetwork/types";
@@ -382,17 +383,6 @@
382383
const handleRemoveSelectedRequest = () => {
383384
activeRequest = undefined;
384385
};
385-
386-
const checkStatus = (request: any) => {
387-
switch (request?.balance?.balance > 0) {
388-
case true:
389-
return request?.balance?.balance >= request?.expectedAmount
390-
? "Paid"
391-
: "Partially Paid";
392-
default:
393-
return capitalize(request?.state);
394-
}
395-
};
396386
</script>
397387

398388
<div

shared/icons/network/network-icon.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script>
2+
import { capitalize } from "../../utils/capitalize";
23
import { getNetworkIcon } from "../../utils/getNetworkIcon";
34
45
export let network = "mainnet";
@@ -9,7 +10,7 @@
910
{#if icon}
1011
<div class="network-icon">
1112
<svelte:component this={icon} />
12-
<span>{network}</span>
13+
<span>{capitalize(network)}</span>
1314
</div>
1415
{/if}
1516

shared/utils/capitalize.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const capitalize = (str: string) =>
2+
(str && str[0].toUpperCase() + str.slice(1)) || "";

shared/utils/checkStatus.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { capitalize } from "./capitalize";
2+
import { Types } from "@requestnetwork/request-client.js";
3+
4+
export const checkStatus = (request: Types.IRequestDataWithEvents | null) => {
5+
const balance = BigInt(request?.balance?.balance ?? 0);
6+
const expectedAmount = BigInt(request?.expectedAmount ?? 0);
7+
const today = new Date();
8+
const dueDate = new Date(request?.contentData?.paymentTerms?.dueDate);
9+
const isPaid = balance >= expectedAmount ? "Paid" : "Partially Paid";
10+
11+
const eventStatus = {
12+
reject: "Rejected",
13+
cancel: "Canceled",
14+
};
15+
16+
for (const [event, status] of Object.entries(eventStatus)) {
17+
if (
18+
request?.events?.some(
19+
(e: { name?: string }) => e?.name?.toLowerCase() === event.toLowerCase()
20+
)
21+
) {
22+
return capitalize(status);
23+
}
24+
}
25+
26+
if (dueDate < today) {
27+
if (balance === BigInt(0)) {
28+
return "Overdue";
29+
}
30+
return isPaid;
31+
} else {
32+
if (balance === BigInt(0)) {
33+
return "Awaiting Payment";
34+
}
35+
return isPaid;
36+
}
37+
};

0 commit comments

Comments
 (0)