Skip to content

Commit 772141c

Browse files
committed
feat: changed the arch to reflect props changes
1 parent 3b2cf5e commit 772141c

File tree

12 files changed

+15974
-7028
lines changed

12 files changed

+15974
-7028
lines changed

package-lock.json

Lines changed: 15889 additions & 6973 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/create-invoice-form/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"devDependencies": {
3939
"@sveltejs/vite-plugin-svelte": "^2.5.2",
40+
"@wagmi/core": "^2.13.8",
4041
"svelte": "^4.0.5",
4142
"svelte-check": "^3.6.0",
4243
"typescript": "^5.0.0",

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
import { InvoiceForm, InvoiceView } from "./invoice";
1919
import { getInitialFormData, prepareRequestParams } from "./utils";
2020
import type { RequestNetwork } from "@requestnetwork/request-client.js";
21+
import { getAccount } from "@wagmi/core";
2122
2223
export let config: IConfig;
23-
export let signer: string = "";
24+
export let wagmiConfig: any;
2425
export let requestNetwork: RequestNetwork | null | undefined;
2526
export let currencies: any;
2627
28+
let account: any;
2729
let isTimeout = false;
2830
let activeConfig = config ? config : defaultConfig;
2931
let mainColor = activeConfig.colors.main;
@@ -77,7 +79,13 @@
7779
};
7880
7981
$: {
80-
formData.creatorId = signer;
82+
if (wagmiConfig) {
83+
account = getAccount(wagmiConfig);
84+
}
85+
}
86+
87+
$: {
88+
formData.creatorId = account?.address as string;
8189
invoiceTotals = calculateInvoiceTotals(formData.items);
8290
}
8391
@@ -130,7 +138,7 @@
130138
formData.miscellaneous.createdWith = window.location.hostname;
131139
132140
const requestCreateParameters = prepareRequestParams({
133-
signer,
141+
address: account?.address,
134142
formData,
135143
currency,
136144
invoiceTotals,

packages/create-invoice-form/src/lib/react/CreateInvoiceForm.ts renamed to packages/create-invoice-form/src/lib/react/CreateInvoiceForm.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from "react";
22
import type { IConfig } from "@requestnetwork/shared-types";
33
import type { RequestNetwork, Types } from "@requestnetwork/request-client.js";
4+
import { Config as WagmiConfig } from "@wagmi/core";
45
export interface CreateInvoiceFormProps {
56
config: IConfig;
6-
signer: string;
7+
wagmiConfig: WagmiConfig;
78
requestNetwork: RequestNetwork | null | undefined;
89
currencies: {
910
symbol: string;
@@ -26,7 +27,7 @@ export interface CreateInvoiceFormProps {
2627
* @example
2728
* <CreateInvoiceForm
2829
* config={config}
29-
* signer={signer}
30+
* wagmiConfig={wagmiConfig}
3031
* requestNetwork={requestNetwork}
3132
* currencies={[
3233
* {

packages/create-invoice-form/src/lib/utils/prepareRequest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ interface IRequestParams {
1010
totalTaxAmount: number;
1111
totalAmount: number;
1212
};
13-
signer: string;
13+
address: `0x${string}` | undefined;
1414
}
1515

1616
export const prepareRequestParams = ({
17-
signer,
17+
address,
1818
currency,
1919
formData,
2020
invoiceTotals,
@@ -123,7 +123,7 @@ export const prepareRequestParams = ({
123123
},
124124
signer: {
125125
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
126-
value: signer,
126+
value: address as string,
127127
},
128128
};
129129
};

packages/invoice-dashboard/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@
3939
"@requestnetwork/payment-detection": "0.43.1-next.2043",
4040
"@requestnetwork/payment-processor": "0.45.1-next.2043",
4141
"@requestnetwork/request-client.js": "0.47.1-next.2043",
42+
"@wagmi/connectors": "^5.2.0",
43+
"@wagmi/core": "^2.13.8",
4244
"ethers": "^5.7.2",
4345
"svelte-sonner": "^0.3.27",
44-
"viem": "^2.9.15",
45-
"vite-plugin-node-polyfills": "^0.22.0"
46+
"viem": "^2.21.27",
47+
"vite-plugin-node-polyfills": "^0.22.0",
48+
"wagmi": "^2.12.17"
4649
},
4750
"devDependencies": {
4851
"@sveltejs/package": "^2.0.0",

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@
2222
import { calculateItemTotal } from "@requestnetwork/shared-utils/invoiceTotals";
2323
import { exportToPDF } from "@requestnetwork/shared-utils/generateInvoice";
2424
import { getCurrencyFromManager } from "@requestnetwork/shared-utils/getCurrency";
25-
// Types
26-
import type { WalletState } from "@requestnetwork/shared-types/web3Onboard";
27-
2825
import { onMount } from "svelte";
2926
import { formatUnits } from "viem";
30-
import { walletClientToSigner } from "../../utils";
27+
import { getEthersSigner } from "../../utils";
3128
3229
export let config;
33-
export let wallet: WalletState | undefined;
30+
export let account: any;
3431
export let requestNetwork: RequestNetwork | null | undefined;
3532
export let request: Types.IRequestDataWithEvents;
3633
export let currencyManager: any;
3734
export let isRequestPayed: boolean;
35+
export let wagmiConfig: any;
3836
3937
let network = request?.currencyInfo?.network || "mainnet";
4038
// FIXME: Use a non deprecated function
@@ -45,15 +43,16 @@
4543
let requestData: any = null;
4644
let signer: any = null;
4745
let approved = false;
48-
let address = wallet?.accounts?.[0]?.address;
46+
let address = account.address;
4947
let firstItems: any;
5048
let otherItems: any;
5149
let sellerInfo: { label: string; value: string }[] = [];
5250
let buyerInfo: { label: string; value: string }[] = [];
5351
let isPayee = request?.payee?.value.toLowerCase() === address?.toLowerCase();
5452
let unsupportedNetwork = false;
53+
let hexStringChain = "0x" + account.chainId.toString(16);
5554
let correctChain =
56-
wallet?.chains[0].id === String(getNetworkIdFromNetworkName(network));
55+
hexStringChain === String(getNetworkIdFromNetworkName(network));
5756
5857
const generateDetailParagraphs = (info: any) => {
5958
return [
@@ -96,7 +95,7 @@
9695
$: request, checkInvoice();
9796
9897
$: {
99-
wallet = wallet;
98+
account = account;
10099
network = request?.currencyInfo?.network || "mainnet";
101100
// FIXME: Use a non deprecated function
102101
currency = getCurrencyFromManager(request.currencyInfo, currencyManager);
@@ -109,7 +108,9 @@
109108
const singleRequest = await requestNetwork?.fromRequestId(
110109
request!.requestId
111110
);
112-
signer = walletClientToSigner(wallet);
111+
112+
signer = await getEthersSigner(wagmiConfig);
113+
113114
requestData = singleRequest?.getData();
114115
115116
if (requestData.currencyInfo.type === Types.RequestLogic.CURRENCY.ERC20) {
@@ -183,11 +184,9 @@
183184
async function switchNetworkIfNeeded(network: string) {
184185
try {
185186
const targetNetworkId = String(getNetworkIdFromNetworkName(network));
186-
await wallet?.provider.request({
187-
method: "wallet_switchEthereumChain",
188-
params: [{ chainId: targetNetworkId }],
189-
});
190-
signer = walletClientToSigner(wallet);
187+
await account.connector.switchChain({ chainId: Number(targetNetworkId) });
188+
signer = await getEthersSigner(wagmiConfig);
189+
191190
correctChain = true;
192191
} catch (err) {
193192
console.error("Something went wrong while switching networks: ", err);

packages/invoice-dashboard/src/lib/react/InvoiceDashboard.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import type { IConfig } from "@requestnetwork/shared-types";
33
import type { WalletState } from "@requestnetwork/shared-types/web3Onboard";
44
import type { RequestNetwork } from "@requestnetwork/request-client.js";
55
import { Currency } from "../types";
6+
import { Config as WagmiConfig } from "wagmi";
67

78
export interface InvoiceDashboardProps {
89
config: IConfig;
9-
wallet: WalletState | null;
10+
wagmiConfig: WagmiConfig;
1011
requestNetwork: RequestNetwork | null | undefined;
1112
currencies: Currency[];
1213
}
@@ -23,7 +24,7 @@ export interface InvoiceDashboardProps {
2324
* @example
2425
* <InvoiceDashboard
2526
* config={config}
26-
* wallet={wallet}
27+
* wagmiConfig={wagmiConfig}
2728
* requestNetwork={requestNetwork}
2829
* currencies={currencies}
2930
* />

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import Search from "@requestnetwork/shared-icons/search.svelte";
2222
// Types
2323
import type { IConfig } from "@requestnetwork/shared-types";
24-
import type { WalletState } from "@requestnetwork/shared-types/web3Onboard";
2524
// Utils
2625
import { config as defaultConfig } from "@requestnetwork/shared-utils/config";
2726
import { initializeCurrencyManager } from "@requestnetwork/shared-utils/initCurrencyManager";
@@ -34,18 +33,20 @@
3433
import { onMount } from "svelte";
3534
import { formatUnits } from "viem";
3635
import { capitalize, debounce, formatAddress } from "../utils";
37-
3836
import { Drawer, InvoiceView } from "./dashboard";
37+
import { getAccount, getClient } from "@wagmi/core";
38+
import type { Config as WagmiConfig } from "wagmi";
3939
4040
export let config: IConfig;
41-
export let wallet: WalletState;
41+
export let wagmiConfig: WagmiConfig;
4242
export let requestNetwork: RequestNetwork | null | undefined;
4343
export let currencies: any = [];
4444
45-
let signer = "";
45+
let signer: `0x${string}` | undefined;
4646
let activeConfig = config ? config : defaultConfig;
4747
let mainColor = activeConfig.colors.main;
4848
let secondaryColor = activeConfig.colors.secondary;
49+
let account: any;
4950
5051
let loading = false;
5152
let searchQuery = "";
@@ -76,7 +77,13 @@
7677
let sortColumn = "timestamp";
7778
7879
$: {
79-
signer = wallet?.accounts[0]?.address;
80+
if (wagmiConfig) {
81+
account = getAccount(wagmiConfig);
82+
}
83+
}
84+
85+
$: {
86+
signer = account?.address;
8087
}
8188
8289
$: isRequestPayed, getOneRequest(activeRequest);
@@ -86,13 +93,13 @@
8693
});
8794
8895
const getRequests = async () => {
89-
if (!wallet || !requestNetwork) return;
96+
if (!account?.address || !requestNetwork) return;
9097
loading = true;
9198
9299
try {
93100
const requestsData = await requestNetwork?.fromIdentity({
94101
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
95-
value: wallet?.accounts[0]?.address,
102+
value: account?.address,
96103
});
97104
requests = requestsData
98105
?.map((request) => request.getData())
@@ -115,7 +122,7 @@
115122
requests = requests?.filter(
116123
(request) => request.requestId !== activeRequest.requestId
117124
);
118-
requests = [...requests, _request.getData()].sort(
125+
requests = [...requests, _request?.getData()].sort(
119126
(a, b) => b.timestamp - a.timestamp
120127
);
121128
} catch (error) {
@@ -136,8 +143,8 @@
136143
let totalPages = 1;
137144
138145
$: {
139-
const currentWalletAddress = wallet?.accounts[0]?.address;
140-
const currentNetwork = wallet?.chains[0]?.id;
146+
const currentWalletAddress = account?.address;
147+
const currentNetwork = account?.chainId?.toString();
141148
142149
if (
143150
currentWalletAddress &&
@@ -184,9 +191,9 @@
184191
if (
185192
currentTab === "All" ||
186193
(currentTab === "Get Paid" &&
187-
request.payee?.value?.toLowerCase() === signer.toLowerCase()) ||
194+
request.payee?.value?.toLowerCase() === signer?.toLowerCase()) ||
188195
(currentTab === "Pay" &&
189-
request.payer?.value?.toLowerCase() === signer.toLowerCase())
196+
request.payer?.value?.toLowerCase() === signer?.toLowerCase())
190197
) {
191198
const invoiceMatches = request.contentData?.invoiceNumber
192199
?.toString()
@@ -517,8 +524,8 @@
517524
<span
518525
>{formatAddress(
519526
currentTab === "Pay"
520-
? request.payee?.value ?? ""
521-
: request.payer?.value ?? ""
527+
? (request.payee?.value ?? "")
528+
: (request.payer?.value ?? "")
522529
)}</span
523530
>
524531
<Copy
@@ -572,7 +579,8 @@
572579
>
573580
{#if activeRequest !== undefined}
574581
<InvoiceView
575-
{wallet}
582+
{account}
583+
{wagmiConfig}
576584
bind:isRequestPayed
577585
{requestNetwork}
578586
{currencyManager}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { debounce } from "./debounce";
22
export { formatAddress } from "./formatAddress";
3-
export { publicClientToProvider, walletClientToSigner } from "./wallet-utils";
3+
export { publicClientToProvider, getEthersSigner } from "./wallet-utils";
44
export { capitalize } from "./capitalize";

0 commit comments

Comments
 (0)