Skip to content

Commit 5afdf2a

Browse files
committed
Merge branch 'main' into feat/pagination
2 parents c20768e + 5193365 commit 5afdf2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3586
-443
lines changed

.github/workflows/npm-publish.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- '@requestnetwork/create-invoice-form'
1919
- '@requestnetwork/invoice-dashboard'
2020
- '@requestnetwork/payment-widget'
21+
- '@requestnetwork/single-invoice'
2122
steps:
2223
- name: Checkout repository 🛎️
2324
uses: actions/checkout@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules
55
.turbo
66
dist
77
.svelte-kit
8+
vite.congig.ts.timestamp*

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Usage depends on the component. See packages/\<package>/README.md
1717
| [@requestnetwork/create-invoice-form](packages/create-invoice-form/README.md) | [![npm version](https://badge.fury.io/js/%40requestnetwork%2Fcreate-invoice-form.svg)](https://badge.fury.io/js/%40requestnetwork%2Fcreate-invoice-form) |
1818
| [@requestnetwork/invoice-dashboard](packages/invoice-dashboard/README.md) | [![npm version](https://badge.fury.io/js/%40requestnetwork%2Finvoice-dashboard.svg)](https://badge.fury.io/js/%40requestnetwork%2Finvoice-dashboard) |
1919
| [@requestnetwork/payment-widget](packages/payment-widget/README.md) | [![npm version](https://badge.fury.io/js/%40requestnetwork%2Fpayment-widget.svg)](https://badge.fury.io/js/%40requestnetwork%2Fpayment-widget) |
20+
| [@requestnetwork/single-invoice](packages/single-invoice/README.md) | [![npm version](https://badge.fury.io/js/%40requestnetwork%2Fsingle-invoice.svg)](https://badge.fury.io/js/%40requestnetwork%2Fsingle-invoice) |
2021
| [@requestnetwork/shared](packages/shared/README.md) | [![npm version](https://badge.fury.io/js/%40requestnetwork%2Fshared.svg)](https://badge.fury.io/js/%40requestnetwork%2Fshared) |
2122

2223

@@ -45,7 +46,7 @@ npm run link:all --app-path=../rn-checkout
4546
cd <project>
4647

4748
# Use local packages instead of the deployed ones
48-
npm link @requestnetwork/create-invoice-form @requestnetwork/invoice-dashboard
49+
npm link @requestnetwork/create-invoice-form @requestnetwork/invoice-dashboard @requestnetwork/single-invoice
4950
npm link @requestnetwork/payment-widget
5051
```
5152

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"build:dashboard": "turbo run build --filter=@requestnetwork/invoice-dashboard",
1818
"build:stakeholder": "turbo run build --filter=@requestnetwork/add-stakeholder",
1919
"build:payment-widget": "turbo run build --filter=@requestnetwork/payment-widget",
20+
"build:single-invoice": "turbo run build --filter=@requestnetwork/single-invoice",
2021
"link:react": "npm link $npm_config_app_path/node_modules/react $npm_config_app_path/node_modules/react-dom",
2122
"link:all": "npm run link:react --app-path=$npm_config_app_path && for d in packages/*; do (cd $d && npm link); done",
2223
"unlink:all": "for d in packages/*; do (cd $d && npm unlink); done"

packages/create-invoice-form/package.json

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

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

Lines changed: 102 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@
1616
import { CurrencyTypes } from "@requestnetwork/types";
1717
// Utils
1818
import { getInitialFormData, prepareRequestParams } from "./utils";
19-
import { config as defaultConfig } from "@requestnetwork/shared-utils/config";
20-
import { calculateInvoiceTotals } from "@requestnetwork/shared-utils/invoiceTotals";
2119
import {
20+
config as defaultConfig,
21+
calculateInvoiceTotals,
2222
getCurrencySupportedNetworksForConversion,
23-
initializeCurrencyManager,
24-
} from "@requestnetwork/shared-utils/initCurrencyManager";
23+
initializeCreateInvoiceCurrencyManager,
24+
} from "@requestnetwork/shared-utils/index";
2525
// Components
2626
import { InvoiceForm, InvoiceView } from "./invoice";
2727
import Button from "@requestnetwork/shared-components/button.svelte";
2828
import Status from "@requestnetwork/shared-components/status.svelte";
2929
import Modal from "@requestnetwork/shared-components/modal.svelte";
3030
import { EncryptionTypes, CipherProviderTypes } from "@requestnetwork/types";
3131
import { onDestroy, onMount, tick } from "svelte";
32+
import { CurrencyManager } from "@requestnetwork/currency";
3233
3334
interface CipherProvider extends CipherProviderTypes.ICipherProvider {
3435
disconnectWallet: () => void;
@@ -37,7 +38,7 @@
3738
export let config: IConfig;
3839
export let wagmiConfig: WagmiConfig;
3940
export let requestNetwork: RequestNetwork | null | undefined;
40-
export let currencies: CurrencyTypes.CurrencyInput[] = [];
41+
export let currencies: string[] = [];
4142
let cipherProvider: CipherProvider | undefined;
4243
4344
let account: GetAccountReturnType | undefined =
@@ -46,7 +47,7 @@
4647
let activeConfig = config ? config : defaultConfig;
4748
let mainColor = activeConfig.colors.main;
4849
let secondaryColor = activeConfig.colors.secondary;
49-
let currencyManager = initializeCurrencyManager(currencies);
50+
let currencyManager: CurrencyManager;
5051
5152
let invoiceCurrencyDropdown: { clear: () => void };
5253
let networkDropdown: { clear: () => void };
@@ -58,10 +59,54 @@
5859
let currency: CurrencyTypes.CurrencyDefinition | undefined = undefined;
5960
let invoiceCurrency: CurrencyTypes.CurrencyDefinition | undefined = undefined;
6061
62+
let defaultCurrencies: any[] = [];
63+
64+
onMount(async () => {
65+
currencyManager = await initializeCreateInvoiceCurrencyManager(currencies);
66+
67+
defaultCurrencies = Object.values(
68+
currencyManager.knownCurrencies.reduce(
69+
(
70+
unique: { [x: string]: any },
71+
currency: { symbol: string | number }
72+
) => {
73+
const baseSymbol = String(currency.symbol).split("-")[0];
74+
if (!unique[baseSymbol]) {
75+
unique[baseSymbol] = {
76+
...currency,
77+
symbol: baseSymbol,
78+
};
79+
}
80+
return unique;
81+
},
82+
{}
83+
)
84+
);
85+
86+
unwatchAccount = watchAccount(wagmiConfig, {
87+
onChange(
88+
account: GetAccountReturnType,
89+
previousAccount: GetAccountReturnType
90+
) {
91+
tick().then(() => {
92+
handleWalletChange(account, previousAccount);
93+
});
94+
},
95+
});
96+
});
97+
6198
const handleNetworkChange = (newNetwork: string) => {
6299
if (newNetwork) {
63100
currencyDropdown.clear();
64-
invoiceCurrency = invoiceCurrency?.type !== Types.RequestLogic.CURRENCY.ISO4217 ? currencyManager.knownCurrencies.find(currency => invoiceCurrency?.symbol === currency.symbol && currency.network === newNetwork) : invoiceCurrency;
101+
invoiceCurrency =
102+
invoiceCurrency?.type !== Types.RequestLogic.CURRENCY.ISO4217
103+
? currencyManager.knownCurrencies.find(
104+
(currency) =>
105+
currency.symbol.split("-")[0] ===
106+
invoiceCurrency?.symbol.split("-")[0] &&
107+
currency.network === newNetwork
108+
)
109+
: invoiceCurrency;
65110
network = newNetwork;
66111
currency = undefined;
67112
@@ -77,7 +122,7 @@
77122
currencyManager?.getConversionPath(
78123
invoiceCurrency,
79124
currency,
80-
currency?.network,
125+
currency?.network
81126
)?.length > 0;
82127
83128
return (
@@ -88,8 +133,14 @@
88133
}
89134
90135
// For other currency types (like ERC20)
91-
return invoiceCurrency.hash === currency?.hash;
92-
},
136+
// Compare base symbols (without network suffix)
137+
const invoiceBaseSymbol = invoiceCurrency.symbol.split("-")[0];
138+
const currencyBaseSymbol = currency.symbol.split("-")[0];
139+
return (
140+
invoiceBaseSymbol === currencyBaseSymbol &&
141+
currency.network === newNetwork
142+
);
143+
}
93144
);
94145
}
95146
};
@@ -98,18 +149,9 @@
98149
let canSubmit = false;
99150
let appStatus: APP_STATUS[] = [];
100151
let formData = getInitialFormData();
101-
// Remove duplicate currencies and filter out currencies with '-' in the symbol
102-
let defaultCurrencies = Object.values(currencyManager.knownCurrencies.reduce(
103-
(unique: { [x: string]: any; }, currency: { symbol: string | number; }) => {
104-
if (!unique[currency.symbol] && !currency.symbol.includes('-')) unique[currency.symbol] = currency;
105-
106-
return unique;
107-
},
108-
{},
109-
));
110152
111153
const handleInvoiceCurrencyChange = (
112-
value: CurrencyTypes.CurrencyDefinition,
154+
value: CurrencyTypes.CurrencyDefinition
113155
) => {
114156
if (value !== invoiceCurrency) {
115157
networkDropdown.clear();
@@ -119,16 +161,45 @@
119161
currency = undefined;
120162
filteredSettlementCurrencies = [];
121163
network = undefined;
122-
networks = [];
164+
165+
const availableNetworks = new Set(
166+
currencyManager.knownCurrencies.map((currency) => currency.network)
167+
);
123168
124169
if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) {
125-
networks = (getCurrencySupportedNetworksForConversion(
126-
invoiceCurrency.hash,
127-
currencyManager,
128-
) ?? []) as string[];
170+
const conversionNetworks = new Set(
171+
getCurrencySupportedNetworksForConversion(
172+
invoiceCurrency.hash,
173+
currencyManager
174+
)
175+
);
176+
177+
networks = [...availableNetworks].filter(
178+
(network) =>
179+
conversionNetworks.has(network) &&
180+
(config.supportedNetworks
181+
? config.supportedNetworks.includes(network)
182+
: true)
183+
);
129184
} else {
130-
networks = currencyManager.knownCurrencies.filter(currency => currency.symbol === invoiceCurrency?.symbol).map(currency => currency.network);
185+
const baseSymbol = invoiceCurrency.symbol.split("-")[0];
186+
networks = [...availableNetworks].filter((network) => {
187+
const hasToken = currencyManager.knownCurrencies.some(
188+
(currency) =>
189+
currency.network === network &&
190+
currency.symbol.split("-")[0] === baseSymbol
191+
);
192+
193+
return (
194+
hasToken &&
195+
(config.supportedNetworks
196+
? config.supportedNetworks.includes(network)
197+
: true)
198+
);
199+
});
131200
}
201+
202+
networks = [...new Set(networks)];
132203
}
133204
};
134205
@@ -152,7 +223,10 @@
152223
cipherProvider?.disconnectWallet();
153224
};
154225
155-
const handleWalletChange = (account: GetAccountReturnType, previousAccount: GetAccountReturnType) => {
226+
const handleWalletChange = (
227+
account: GetAccountReturnType,
228+
previousAccount: GetAccountReturnType
229+
) => {
156230
if (account?.address !== previousAccount?.address) {
157231
handleWalletDisconnection();
158232
handleWalletConnection();
@@ -163,16 +237,6 @@
163237
}
164238
};
165239
166-
onMount(() => {
167-
unwatchAccount = watchAccount(wagmiConfig, {
168-
onChange(account: GetAccountReturnType, previousAccount: GetAccountReturnType) {
169-
tick().then(() => {
170-
handleWalletChange(account, previousAccount);
171-
});
172-
},
173-
});
174-
});
175-
176240
let unwatchAccount: WatchAccountReturnType | undefined;
177241
178242
onDestroy(() => {
@@ -261,7 +325,7 @@
261325
paymentNetwork: requestCreateParameters.paymentNetwork,
262326
contentData: requestCreateParameters.contentData,
263327
},
264-
[payeeEncryptionParams, payerEncryptionParams],
328+
[payeeEncryptionParams, payerEncryptionParams]
265329
);
266330
} else {
267331
request = await requestNetwork.createRequest({

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import { CurrencyTypes } from "@requestnetwork/types";
1212
1313
// Utils
14-
import { config as defaultConfig } from "@requestnetwork/shared-utils/config";
15-
import { calculateItemTotal } from "@requestnetwork/shared-utils/invoiceTotals";
16-
import { formatDate } from "@requestnetwork/shared-utils/formatDate";
14+
import {
15+
formatDate,
16+
calculateItemTotal,
17+
config as defaultConfig,
18+
} from "@requestnetwork/shared-utils/index";
1719
1820
export let defaultCurrencies;
1921
export let config: IConfig;

0 commit comments

Comments
 (0)