@blocklet/payment-react-headless 1.27.0 → 1.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react-headless",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.2",
|
|
4
4
|
"description": "Headless React hooks for payment-kit checkout",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@arcblock/ws": "^1.28.5",
|
|
37
37
|
"@blocklet/js-sdk": "workspace:*",
|
|
38
|
-
"@blocklet/payment-types": "1.27.
|
|
38
|
+
"@blocklet/payment-types": "1.27.2",
|
|
39
39
|
"@ocap/util": "^1.28.5",
|
|
40
40
|
"ahooks": "^3.8.5",
|
|
41
41
|
"google-libphonenumber": "^3.2.42",
|
|
42
|
-
"lodash": "^4.
|
|
42
|
+
"lodash": "^4.18.1",
|
|
43
43
|
"p-wait-for": "^3.2.0",
|
|
44
|
-
"validator": "^13.15.
|
|
44
|
+
"validator": "^13.15.35"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": ">=17.0.0"
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "ba98e644bcbf88924039ba8990bba673198e6a61"
|
|
64
64
|
}
|
|
@@ -2,12 +2,16 @@ import type { TLineItemExpanded } from '@blocklet/payment-types';
|
|
|
2
2
|
|
|
3
3
|
import api, { API } from '../../shared/api';
|
|
4
4
|
|
|
5
|
+
type DynamicPriceFields = {
|
|
6
|
+
pricing_type?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
5
9
|
// Rate polling intervals
|
|
6
10
|
export const BASE_INTERVAL = 30_000;
|
|
7
11
|
export const MAX_INTERVAL = 120_000;
|
|
8
12
|
|
|
9
13
|
export function checkHasDynamicPricing(items: TLineItemExpanded[]): boolean {
|
|
10
|
-
return items.some((item) => (item.upsell_price || item.price)?.pricing_type === 'dynamic');
|
|
14
|
+
return items.some((item) => ((item.upsell_price || item.price) as DynamicPriceFields | undefined)?.pricing_type === 'dynamic');
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
export async function fetchExchangeRate(
|
|
@@ -234,6 +234,10 @@ export interface QuoteMeta {
|
|
|
234
234
|
slippagePercent: number | null;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
type DynamicPriceFields = {
|
|
238
|
+
base_currency?: string;
|
|
239
|
+
};
|
|
240
|
+
|
|
237
241
|
export function calculateQuoteMeta(
|
|
238
242
|
items: TLineItemExpanded[],
|
|
239
243
|
hasDynamicPricing: boolean,
|
|
@@ -256,7 +260,7 @@ export function calculateQuoteMeta(
|
|
|
256
260
|
let slippagePercent: number | null = null;
|
|
257
261
|
|
|
258
262
|
items.forEach((item) => {
|
|
259
|
-
const price = item.upsell_price || item.price;
|
|
263
|
+
const price = (item.upsell_price || item.price) as DynamicPriceFields | undefined;
|
|
260
264
|
if (!baseCurrency && price?.base_currency) baseCurrency = price.base_currency;
|
|
261
265
|
|
|
262
266
|
const expires = item.expires_at as number | undefined;
|
package/src/shared/format.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { BN, fromUnitToToken, fromTokenToUnit } from '@ocap/util';
|
|
2
2
|
import type { TPaymentCurrency, TPrice, TLineItemExpanded } from '@blocklet/payment-types';
|
|
3
3
|
|
|
4
|
+
type DynamicPriceFields = {
|
|
5
|
+
pricing_type?: string;
|
|
6
|
+
base_amount?: string | number | null;
|
|
7
|
+
};
|
|
8
|
+
|
|
4
9
|
// ── Number Formatting ──
|
|
5
10
|
|
|
6
11
|
export function formatNumber(
|
|
@@ -213,7 +218,7 @@ export function getLineItemAmounts(
|
|
|
213
218
|
return { unitAmount: new BN(0), totalAmount: new BN(0), isDynamicQuote: false };
|
|
214
219
|
}
|
|
215
220
|
|
|
216
|
-
const price = useUpsell ? item.upsell_price || item.price : item.price;
|
|
221
|
+
const price = (useUpsell ? item.upsell_price || item.price : item.price) as TPrice & DynamicPriceFields;
|
|
217
222
|
const quantity = new BN(item.quantity || 0);
|
|
218
223
|
const quoteAmount = item.quoted_amount as string | undefined;
|
|
219
224
|
const quoteCurrencyId = item.quote_currency_id as string | undefined;
|