@rozoai/intent-pay 0.1.34 → 0.1.35-beta.1
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/build/components/Common/TokenChainLogo/index.d.ts +7 -1
- package/build/components/Spinners/TokenLogoSpinner/index.d.ts +6 -1
- package/build/hooks/useWalletPaymentOptions.d.ts +11 -6
- package/build/package.json.js +2 -2
- package/build/src/components/Common/TokenChainLogo/index.js +26 -3
- package/build/src/components/Common/TokenChainLogo/index.js.map +1 -1
- package/build/src/components/Pages/PayWithToken/index.js +18 -3
- package/build/src/components/Pages/PayWithToken/index.js.map +1 -1
- package/build/src/components/Pages/Solana/PayWithSolanaToken/index.js +43 -20
- package/build/src/components/Pages/Solana/PayWithSolanaToken/index.js.map +1 -1
- package/build/src/components/Pages/Stellar/PayWithStellarToken/index.js +21 -5
- package/build/src/components/Pages/Stellar/PayWithStellarToken/index.js.map +1 -1
- package/build/src/components/Pages/WaitingDepositAddress/index.js +12 -4
- package/build/src/components/Pages/WaitingDepositAddress/index.js.map +1 -1
- package/build/src/components/Spinners/TokenLogoSpinner/index.js +5 -2
- package/build/src/components/Spinners/TokenLogoSpinner/index.js.map +1 -1
- package/build/src/hooks/usePaymentState.js +145 -60
- package/build/src/hooks/usePaymentState.js.map +1 -1
- package/build/src/hooks/useTokenOptions.js +3 -3
- package/build/src/hooks/useTokenOptions.js.map +1 -1
- package/build/src/hooks/useWalletPaymentOptions.js +11 -6
- package/build/src/hooks/useWalletPaymentOptions.js.map +1 -1
- package/build/src/payment/createPaymentPayload.js +28 -7
- package/build/src/payment/createPaymentPayload.js.map +1 -1
- package/build/src/payment/paymentEffects.js +3 -4
- package/build/src/payment/paymentEffects.js.map +1 -1
- package/build/src/utils/format.js +36 -2
- package/build/src/utils/format.js.map +1 -1
- package/build/src/utils/token.js +38 -6
- package/build/src/utils/token.js.map +1 -1
- package/build/utils/format.d.ts +24 -0
- package/build/utils/token.d.ts +8 -1
- package/package.json +2 -2
package/build/src/utils/token.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { TokenSymbol, supportedTokens } from '@rozoai/intent-common';
|
|
2
|
+
import { ethAddress } from 'viem';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Native-token address markers across supported ecosystems:
|
|
6
|
+
* - EVM natives (ETH/BNB/POL/MNT) all use the conventional `ethAddress`
|
|
7
|
+
* placeholder (0xEeee…eEeE).
|
|
8
|
+
* - Solana native SOL uses the system program address.
|
|
9
|
+
* - Stellar native XLM uses the "XLM" sentinel.
|
|
10
|
+
*
|
|
11
|
+
* A token is "native" when its address matches one of these (case-insensitive).
|
|
12
|
+
*/
|
|
13
|
+
const NATIVE_TOKEN_ADDRESSES = new Set([ethAddress, "11111111111111111111111111111112", "XLM"].map((a) => a.toLowerCase()));
|
|
14
|
+
/** Returns true if the given token is a chain-native token (ETH/BNB/POL/SOL/XLM, etc.). */
|
|
15
|
+
function isNativeToken(token) {
|
|
16
|
+
if (!token?.token)
|
|
17
|
+
return false;
|
|
18
|
+
return NATIVE_TOKEN_ADDRESSES.has(token.token.toLowerCase());
|
|
19
|
+
}
|
|
3
20
|
/**
|
|
4
21
|
* Converts preferredSymbol array to preferredTokens array.
|
|
5
|
-
*
|
|
22
|
+
* Explicit preferredSymbol values are respected as given (USDC, USDT, EURC,
|
|
23
|
+
* or native ETH/BNB/POL/SOL/XLM). When neither preferredSymbol nor
|
|
24
|
+
* preferredTokens is provided, defaults to stablecoins plus native tokens
|
|
25
|
+
* so native options aren't silently filtered out of the default request.
|
|
6
26
|
* Finds tokens matching the symbols across supported chains (Base, Polygon, Ethereum, Solana, Stellar).
|
|
7
27
|
*/
|
|
8
28
|
function convertPreferredSymbolsToTokens(symbols, existingPreferredTokens) {
|
|
@@ -11,16 +31,28 @@ function convertPreferredSymbolsToTokens(symbols, existingPreferredTokens) {
|
|
|
11
31
|
if (existingPreferredTokens !== undefined) {
|
|
12
32
|
return existingPreferredTokens.filter((v) => !!v);
|
|
13
33
|
}
|
|
14
|
-
|
|
34
|
+
const nativeSymbols = [
|
|
35
|
+
TokenSymbol.ETH,
|
|
36
|
+
TokenSymbol.BNB,
|
|
37
|
+
TokenSymbol.POL,
|
|
38
|
+
TokenSymbol.SOL,
|
|
39
|
+
TokenSymbol.XLM,
|
|
40
|
+
];
|
|
41
|
+
// If no preferredSymbol provided, default to stablecoins plus native tokens
|
|
15
42
|
const symbolsToUse = symbols && symbols.length > 0
|
|
16
43
|
? symbols
|
|
17
|
-
: [TokenSymbol.USDC, TokenSymbol.USDT];
|
|
44
|
+
: [TokenSymbol.USDC, TokenSymbol.USDT, ...nativeSymbols];
|
|
18
45
|
// Validate that only allowed symbols are used
|
|
19
|
-
const allowedSymbols = [
|
|
46
|
+
const allowedSymbols = [
|
|
47
|
+
TokenSymbol.USDC,
|
|
48
|
+
TokenSymbol.USDT,
|
|
49
|
+
TokenSymbol.EURC,
|
|
50
|
+
...nativeSymbols,
|
|
51
|
+
];
|
|
20
52
|
const validSymbols = symbolsToUse.filter((s) => allowedSymbols.includes(s));
|
|
21
53
|
const invalidSymbols = symbolsToUse.filter((s) => !allowedSymbols.includes(s));
|
|
22
54
|
if (invalidSymbols.length > 0) {
|
|
23
|
-
console.warn(`[RozoPay] Invalid preferredSymbol values: ${invalidSymbols.join(", ")}.
|
|
55
|
+
console.warn(`[RozoPay] Invalid preferredSymbol values: ${invalidSymbols.join(", ")}. Allowed: ${allowedSymbols.join(", ")}.`);
|
|
24
56
|
}
|
|
25
57
|
if (validSymbols.length === 0) {
|
|
26
58
|
return undefined;
|
|
@@ -39,5 +71,5 @@ function convertPreferredSymbolsToTokens(symbols, existingPreferredTokens) {
|
|
|
39
71
|
return tokens.length > 0 ? tokens : undefined;
|
|
40
72
|
}
|
|
41
73
|
|
|
42
|
-
export { convertPreferredSymbolsToTokens };
|
|
74
|
+
export { convertPreferredSymbolsToTokens, isNativeToken };
|
|
43
75
|
//# sourceMappingURL=token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sources":["../../../src/utils/token.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token.js","sources":["../../../src/utils/token.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAGA;;;;;;;;AAQG;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CACpC,CAAC,UAAU,EAAE,kCAAkC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAC5D,CAAC,CAAC,WAAW,EAAE,CAChB,CACF,CAAC;AAEF;AACM,SAAU,aAAa,CAAC,KAA2C,EAAA;IACvE,IAAI,CAAC,KAAK,EAAE,KAAK;AAAE,QAAA,OAAO,KAAK,CAAC;IAChC,OAAO,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;AAOG;AACa,SAAA,+BAA+B,CAC7C,OAAkC,EAClC,uBAA4C,EAAA;;;AAI5C,IAAA,IAAI,uBAAuB,KAAK,SAAS,EAAE;AACzC,QAAA,OAAO,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KACnD;AAED,IAAA,MAAM,aAAa,GAAG;AACpB,QAAA,WAAW,CAAC,GAAG;AACf,QAAA,WAAW,CAAC,GAAG;AACf,QAAA,WAAW,CAAC,GAAG;AACf,QAAA,WAAW,CAAC,GAAG;AACf,QAAA,WAAW,CAAC,GAAG;KAChB,CAAC;;IAGF,MAAM,YAAY,GAChB,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;AAC3B,UAAE,OAAO;AACT,UAAE,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,GAAG,aAAa,CAAC,CAAC;;AAG7D,IAAA,MAAM,cAAc,GAAG;AACrB,QAAA,WAAW,CAAC,IAAI;AAChB,QAAA,WAAW,CAAC,IAAI;AAChB,QAAA,WAAW,CAAC,IAAI;AAChB,QAAA,GAAG,aAAa;KACjB,CAAC;AACF,IAAA,MAAM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5E,IAAA,MAAM,cAAc,GAAG,YAAY,CAAC,MAAM,CACxC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CACnC,CAAC;AAEF,IAAA,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;AAC7B,QAAA,OAAO,CAAC,IAAI,CACV,6CAA6C,cAAc,CAAC,IAAI,CAC9D,IAAI,CACL,CAAc,WAAA,EAAA,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAA,CAAG,CAC5C,CAAC;KACH;AAED,IAAA,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AAC7B,QAAA,OAAO,SAAS,CAAC;KAClB;;IAGD,MAAM,MAAM,GAAY,EAAE,CAAC;AAC3B,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;;IAGxC,KAAK,MAAM,WAAW,IAAI,eAAe,CAAC,MAAM,EAAE,EAAE;AAClD,QAAA,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE;YAC/B,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,MAAqB,CAAC,EAAE;AAC9C,gBAAA,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;SACF;KACF;AAED,IAAA,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,SAAS,CAAC;AAChD;;;;"}
|
package/build/utils/format.d.ts
CHANGED
|
@@ -47,3 +47,27 @@ export declare function usdToRoundedTokenAmount(usd: number, token: RozoPayToken
|
|
|
47
47
|
* @returns The formatted USD amount
|
|
48
48
|
*/
|
|
49
49
|
export declare function tokenAmountToRoundedUsd(amount: bigint | BigIntStr, token: RozoPayToken, round?: "up" | "down" | "nearest"): string;
|
|
50
|
+
/**
|
|
51
|
+
* Convert a `RozoPayTokenAmount.amount` value to a full-precision, human-readable
|
|
52
|
+
* decimal string suitable for sending to the backend (checkout/create-payment
|
|
53
|
+
* payloads, on-chain transfer amounts, etc).
|
|
54
|
+
*
|
|
55
|
+
* `amount` is documented as `BigIntStr` (integer base units, e.g. lamports/wei)
|
|
56
|
+
* but some endpoints (e.g. Solana tRPC payment options) have been observed to
|
|
57
|
+
* return an already-human-readable decimal string instead (e.g. "0.012985327").
|
|
58
|
+
* `BigInt()` throws on decimal strings, so this detects the shape first:
|
|
59
|
+
* - Contains a "." → already a decimal token amount, pass through as-is.
|
|
60
|
+
* - Otherwise → integer base units, convert via `formatUnits`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function tokenBaseAmountToDecimalString(amount: bigint | BigIntStr, decimals: number): string;
|
|
63
|
+
/**
|
|
64
|
+
* Inverse of `tokenBaseAmountToDecimalString`: convert a
|
|
65
|
+
* `RozoPayTokenAmount.amount` value to an integer base-units bigint, suitable
|
|
66
|
+
* for on-chain transfer instructions (e.g. lamports for SOL, raw SPL/ERC20
|
|
67
|
+
* transfer amounts).
|
|
68
|
+
*
|
|
69
|
+
* Same shape ambiguity as above — detects a decimal string (already
|
|
70
|
+
* human-readable) and converts it up to base units via `parseUnits`;
|
|
71
|
+
* otherwise assumes the string is already an integer base-units amount.
|
|
72
|
+
*/
|
|
73
|
+
export declare function tokenAmountToBaseUnits(amount: bigint | BigIntStr, decimals: number): bigint;
|
package/build/utils/token.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { Token, TokenSymbol } from "@rozoai/intent-common";
|
|
2
|
+
/** Returns true if the given token is a chain-native token (ETH/BNB/POL/SOL/XLM, etc.). */
|
|
3
|
+
export declare function isNativeToken(token: {
|
|
4
|
+
token: string;
|
|
5
|
+
} | null | undefined): boolean;
|
|
2
6
|
/**
|
|
3
7
|
* Converts preferredSymbol array to preferredTokens array.
|
|
4
|
-
*
|
|
8
|
+
* Explicit preferredSymbol values are respected as given (USDC, USDT, EURC,
|
|
9
|
+
* or native ETH/BNB/POL/SOL/XLM). When neither preferredSymbol nor
|
|
10
|
+
* preferredTokens is provided, defaults to stablecoins plus native tokens
|
|
11
|
+
* so native options aren't silently filtered out of the default request.
|
|
5
12
|
* Finds tokens matching the symbols across supported chains (Base, Polygon, Ethereum, Solana, Stellar).
|
|
6
13
|
*/
|
|
7
14
|
export declare function convertPreferredSymbolsToTokens(symbols: TokenSymbol[] | undefined, existingPreferredTokens: Token[] | undefined): Token[] | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rozoai/intent-pay",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.",
|
|
6
6
|
"keywords": [
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@reown/appkit": "^1.7.0",
|
|
49
49
|
"@rollup/plugin-image": "^3.0.3",
|
|
50
50
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
51
|
-
"@rozoai/intent-common": "0.1.
|
|
51
|
+
"@rozoai/intent-common": "0.1.22-beta.1",
|
|
52
52
|
"@solana/spl-memo": "^0.2.5",
|
|
53
53
|
"@solana/spl-token": "^0.4.14",
|
|
54
54
|
"@solana/wallet-adapter-base": "^0.9.27",
|