File tree Expand file tree Collapse file tree 4 files changed +43
-13
lines changed
packages/invoice-dashboard/src/lib Expand file tree Collapse file tree 4 files changed +43
-13
lines changed Original file line number Diff line number Diff line change 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" ;
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
Original file line number Diff line number Diff line change 11<script >
2+ import { capitalize } from " ../../utils/capitalize" ;
23 import { getNetworkIcon } from " ../../utils/getNetworkIcon" ;
34
45 export let network = " mainnet" ;
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
Original file line number Diff line number Diff line change 1+ export const capitalize = ( str : string ) =>
2+ ( str && str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ) || "" ;
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments