Skip to content

Commit b35db2b

Browse files
committed
Merge branch 'main' of github.com:RequestNetwork/web-components into 285-switch-network-button-disabled-when-it-should-be-enabled-and-vice-versa
2 parents 5ba4d66 + ec6ca36 commit b35db2b

File tree

3 files changed

+85
-56
lines changed

3 files changed

+85
-56
lines changed

packages/create-invoice-form/src/lib/invoice/form.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
export let handleNetworkChange: (chainId: string) => void;
3030
export let networks;
3131
export let defaultCurrencies: any = [];
32-
export let filteredSettlementCurrencies: CurrencyTypes.CurrencyDefinition[] = [];
32+
export let filteredSettlementCurrencies: CurrencyTypes.CurrencyDefinition[] =
33+
[];
3334
export let cipherProvider: CipherProviderTypes.ICipherProvider | undefined;
3435
3536
export let invoiceCurrencyDropdown;
@@ -161,7 +162,7 @@
161162
162163
$: if (!formData.dueDate) {
163164
formData.dueDate = inputDateFormat(
164-
new Date(new Date(formData.issuedOn).getTime() + 24 * 60 * 60 * 1000)
165+
new Date(new Date(formData.issuedOn).getTime() + 30 * 24 * 60 * 60 * 1000)
165166
);
166167
}
167168
</script>
@@ -406,8 +407,7 @@
406407
<SearchableDropdown
407408
bind:this={invoiceCurrencyDropdown}
408409
getValue={(currency) => currency.value.symbol}
409-
getDisplayValue={(currency) =>
410-
`${currency.value.symbol}`}
410+
getDisplayValue={(currency) => `${currency.value.symbol}`}
411411
placeholder="Invoice currency"
412412
items={defaultCurrencies
413413
?.filter((curr) => curr)
@@ -419,7 +419,7 @@
419419
onSelect={handleInvoiceCurrencyChange}
420420
/>
421421
</div>
422-
<div class="searchable-dropdown-container">
422+
<div class="searchable-dropdown-container">
423423
<SearchableDropdown
424424
bind:this={networkDropdown}
425425
items={networks

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

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
let otherItems: any;
6565
let sellerInfo: SellerInfo[] = [];
6666
let buyerInfo: BuyerInfo[] = [];
67+
let unknownCurrency = currency?.decimals === undefined;
6768
let isPayee = request?.payee?.value.toLowerCase() === address?.toLowerCase();
6869
let unsupportedNetwork = false;
6970
let hexStringChain = "0x" + account?.chainId?.toString(16);
@@ -155,7 +156,7 @@
155156
}
156157
157158
$: {
158-
if (account && network) {
159+
if (account && network && !unknownCurrency) {
159160
checkBalance();
160161
}
161162
}
@@ -638,18 +639,18 @@
638639
<h3 class="invoice-info-payment">
639640
<span style="font-weight: 500;">Payment Chain:</span>
640641
{paymentCurrencies && paymentCurrencies.length > 0
641-
? paymentCurrencies[0]?.network || "-"
642+
? paymentCurrencies[0]?.network || "Unknown"
642643
: ""}
643644
</h3>
644645
<h3 class="invoice-info-payment">
645646
<span style="font-weight: 500;">Invoice Currency:</span>
646-
{currency?.symbol || "-"}
647+
{currency?.symbol || "Unknown"}
647648
</h3>
648649

649650
<h3 class="invoice-info-payment">
650651
<span style="font-weight: 500;">Settlement Currency:</span>
651652
{paymentCurrencies && paymentCurrencies.length > 0
652-
? paymentCurrencies[0]?.symbol || "-"
653+
? paymentCurrencies[0]?.symbol || "Unknown"
653654
: ""}
654655
</h3>
655656

@@ -675,27 +676,34 @@
675676
<p class="truncate description-text">{item.name || "-"}</p>
676677
</th>
677678
<td>{item.quantity || "-"}</td>
678-
<td
679-
>{item.unitPrice
680-
? formatUnits(item.unitPrice, currency?.decimals ?? 18)
681-
: "-"}</td
682-
>
683-
<td
684-
>{item.discount
679+
<td>
680+
{#if unknownCurrency}
681+
Unknown
682+
{:else}
683+
{item.unitPrice
684+
? formatUnits(item.unitPrice, currency?.decimals ?? 18)
685+
: "-"}
686+
{/if}
687+
</td>
688+
<td>
689+
{item.discount
685690
? formatUnits(item.discount, currency?.decimals ?? 18)
686-
: "-"}</td
687-
>
691+
: "-"}
692+
</td>
688693
<td>{Number(item.tax.amount || "-")}</td>
689-
<td
690-
>{truncateNumberString(
691-
formatUnits(
692-
// @ts-expect-error
693-
calculateItemTotal(item),
694-
currency?.decimals ?? 18
695-
),
696-
2
697-
)}</td
698-
>
694+
<td>
695+
{#if unknownCurrency}
696+
Unknown
697+
{:else}
698+
{truncateNumberString(
699+
formatUnits(
700+
calculateItemTotal(item),
701+
currency?.decimals ?? 18
702+
),
703+
2
704+
)}
705+
{/if}
706+
</td>
699707
</tr>
700708
{/each}
701709
</tbody>
@@ -724,27 +732,34 @@
724732
</p>
725733
</th>
726734
<td>{item.quantity || "-"}</td>
727-
<td
728-
>{item.unitPrice
729-
? formatUnits(item.unitPrice, currency?.decimals ?? 18)
730-
: "-"}</td
731-
>
732-
<td
733-
>{item.discount
735+
<td>
736+
{#if unknownCurrency}
737+
Unknown
738+
{:else}
739+
{item.unitPrice
740+
? formatUnits(item.unitPrice, currency?.decimals ?? 18)
741+
: "-"}
742+
{/if}
743+
</td>
744+
<td>
745+
{item.discount
734746
? formatUnits(item.discount, currency?.decimals ?? 18)
735-
: "-"}</td
736-
>
747+
: "-"}
748+
</td>
737749
<td>{Number(item.tax.amount || "-")}</td>
738-
<td
739-
>{truncateNumberString(
740-
formatUnits(
741-
// @ts-expect-error
742-
calculateItemTotal(item),
743-
currency?.decimals ?? 18
744-
),
745-
2
746-
)}</td
747-
>
750+
<td>
751+
{#if unknownCurrency}
752+
Unknown
753+
{:else}
754+
{truncateNumberString(
755+
formatUnits(
756+
calculateItemTotal(item),
757+
currency?.decimals ?? 18
758+
),
759+
2
760+
)}
761+
{/if}
762+
</td>
748763
</tr>
749764
{/each}</tbody
750765
>
@@ -833,7 +848,7 @@
833848
</div>
834849
{/if}
835850
<div class="invoice-view-actions">
836-
{#if !isPayee && !unsupportedNetwork && !isPaid && !isRequestPayed && !isSigningTransaction}
851+
{#if !isPayee && !unsupportedNetwork && !isPaid && !isRequestPayed && !isSigningTransaction && !unknownCurrency}
837852
{#if !hasEnoughBalance && correctChain}
838853
<div class="balance-warning">
839854
Insufficient funds: {Number(userBalance).toFixed(4)}

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@
119119
cipherProvider = undefined;
120120
};
121121
122-
const handleWalletChange = (account: GetAccountReturnType, previousAccount: GetAccountReturnType) => {
122+
const handleWalletChange = (
123+
account: GetAccountReturnType,
124+
previousAccount: GetAccountReturnType
125+
) => {
123126
if (account?.address !== previousAccount?.address) {
124127
handleWalletDisconnection();
125128
handleWalletConnection();
@@ -132,7 +135,10 @@
132135
133136
onMount(() => {
134137
unwatchAccount = watchAccount(wagmiConfig, {
135-
onChange(account: GetAccountReturnType, previousAccount: GetAccountReturnType) {
138+
onChange(
139+
account: GetAccountReturnType,
140+
previousAccount: GetAccountReturnType
141+
) {
136142
tick().then(() => {
137143
handleWalletChange(account, previousAccount);
138144
});
@@ -279,6 +285,11 @@
279285
currencyManager
280286
);
281287
288+
const formattedAmount =
289+
currencyInfo?.decimals !== undefined
290+
? formatUnits(BigInt(request.expectedAmount), currencyInfo.decimals)
291+
: "Unknown";
292+
282293
let paymentNetworkExtension = getPaymentNetworkExtension(request);
283294
let paymentCurrencies: (
284295
| CurrencyTypes.ERC20Currency
@@ -328,11 +339,8 @@
328339
329340
return {
330341
...request,
331-
formattedAmount: formatUnits(
332-
BigInt(request.expectedAmount),
333-
currencyInfo?.decimals ?? 18
334-
),
335-
currencySymbol: currencyInfo?.symbol ?? "-",
342+
formattedAmount,
343+
currencySymbol: currencyInfo?.symbol ?? "",
336344
paymentCurrencies,
337345
};
338346
}
@@ -710,7 +718,13 @@
710718
</td>
711719
{/if}
712720
<td>
713-
{#if request.formattedAmount.includes(".") && request.formattedAmount.split(".")[1].length > 5}
721+
{#if request.formattedAmount === "Unknown"}
722+
<Tooltip
723+
text="Cannot calculate the expected amount due to unknown decimals"
724+
>
725+
Unknown
726+
</Tooltip>
727+
{:else if request.formattedAmount.includes(".") && request.formattedAmount.split(".")[1].length > 5}
714728
<Tooltip text={request.formattedAmount}>
715729
{Number(request.formattedAmount).toFixed(5)}
716730
</Tooltip>

0 commit comments

Comments
 (0)