Skip to content

Commit f761532

Browse files
feat: adjust preferredSymbol to follow supportedTokens
1 parent 88fca8f commit f761532

File tree

11 files changed

+195
-20
lines changed

11 files changed

+195
-20
lines changed

examples/nextjs-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"@farcaster/frame-sdk": "^0.0.26",
1414
"@headlessui/react": "^2.2.0",
1515
"@rainbow-me/rainbowkit": "^2.2.8",
16-
"@rozoai/intent-common": "workspace:*",
17-
"@rozoai/intent-pay": "workspace:*",
16+
"@rozoai/intent-common": "0.1.7-beta.2",
17+
"@rozoai/intent-pay": "0.1.7-beta.3",
1818
"@tanstack/react-query": "^5.51.11",
1919
"@types/react-syntax-highlighter": "^15.5.13",
2020
"@wagmi/core": "^2.22.0",

examples/nextjs-app/src/app/basic/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
knownTokens,
99
rozoSolana,
1010
rozoStellar,
11+
TokenSymbol,
1112
} from "@rozoai/intent-common";
1213
import {
1314
isEvmChain,
@@ -312,7 +313,7 @@ export default function DemoBasic() {
312313
}}
313314
feeType={FeeType.ExactOut}
314315
metadata={metadata}
315-
// preferredTokens={[baseEURC, baseUSDC, rozoStellarEURC]}
316+
preferredSymbol={[TokenSymbol.EURC]}
316317
resetOnSuccess
317318
showProcessingPayout
318319
>

packages/connectkit/bundle-analysis.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/connectkit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@rozoai/intent-pay",
33
"private": false,
4-
"version": "0.1.7-beta.1",
4+
"version": "0.1.7-beta.3",
55
"author": "RozoAI",
66
"homepage": "https://github.com/RozoAI/intent-pay",
77
"license": "BSD-2-Clause",
@@ -47,7 +47,7 @@
4747
"@albedo-link/intent": "^0.13.0",
4848
"@reown/appkit": "^1.7.0",
4949
"@rollup/plugin-typescript": "^12.1.2",
50-
"@rozoai/intent-common": "workspace:*",
50+
"@rozoai/intent-common": "0.1.7-beta.2",
5151
"@solana/spl-token": "^0.4.14",
5252
"@solana/wallet-adapter-base": "^0.9.27",
5353
"@solana/wallet-adapter-react": "^0.15.39",

packages/connectkit/src/components/DaimoPayButton/index.tsx

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414
RozoPayHydratedOrderWithOrg,
1515
rozoSolana,
1616
rozoStellar,
17+
supportedTokens,
18+
Token,
19+
TokenSymbol,
1720
writeRozoPayOrderID,
1821
} from "@rozoai/intent-common";
1922
import { AnimatePresence, Variants } from "framer-motion";
@@ -34,6 +37,59 @@ import { validatePayoutToken } from "../../utils/validatePayoutToken";
3437
import ThemedButton, { ThemeContainer } from "../Common/ThemedButton";
3538
import { RozoPayButtonCustomProps, RozoPayButtonProps } from "./types";
3639

40+
/**
41+
* Converts preferredSymbol array to preferredTokens array.
42+
* Only USDC, USDT, and EURC symbols are allowed.
43+
* Finds tokens matching the symbols across supported chains (Base, Polygon, Ethereum, Solana, Stellar).
44+
*/
45+
function convertPreferredSymbolsToTokens(
46+
symbols: TokenSymbol[] | undefined,
47+
existingPreferredTokens: Token[] | undefined
48+
): Token[] | undefined {
49+
// If preferredTokens is explicitly provided, it takes precedence
50+
// Even if it's an empty array, we respect it (means "no preferred tokens")
51+
if (existingPreferredTokens !== undefined) {
52+
return existingPreferredTokens;
53+
}
54+
55+
// If no preferredSymbol provided, return undefined (will use defaults later)
56+
if (!symbols || symbols.length === 0) {
57+
return undefined;
58+
}
59+
60+
// Validate that only allowed symbols are used
61+
const allowedSymbols = [TokenSymbol.USDC, TokenSymbol.USDT, TokenSymbol.EURC];
62+
const invalidSymbols = symbols.filter((s) => !allowedSymbols.includes(s));
63+
if (invalidSymbols.length > 0) {
64+
console.warn(
65+
`[RozoPayButton] Invalid preferredSymbol values: ${invalidSymbols.join(
66+
", "
67+
)}. Only USDC, USDT, and EURC are allowed.`
68+
);
69+
// Filter out invalid symbols
70+
symbols = symbols.filter((s) => allowedSymbols.includes(s));
71+
if (symbols.length === 0) {
72+
return undefined;
73+
}
74+
}
75+
76+
// Filter supportedTokens by the provided symbols
77+
// supportedTokens is a Map<chainId, Token[]> - this is what's used for wallet payment options
78+
const tokens: Token[] = [];
79+
const symbolSet = new Set(symbols);
80+
81+
// Iterate through all supported tokens (organized by chain)
82+
for (const chainTokens of supportedTokens.values()) {
83+
for (const token of chainTokens) {
84+
if (symbolSet.has(token.symbol as TokenSymbol)) {
85+
tokens.push(token);
86+
}
87+
}
88+
}
89+
90+
return tokens.length > 0 ? tokens : undefined;
91+
}
92+
3793
/**
3894
* A button that shows the Rozo Pay checkout. Replaces the traditional
3995
* Connect Wallet » approve » execute sequence with a single action.
@@ -90,13 +146,29 @@ function RozoPayButtonCustom(props: RozoPayButtonCustomProps): JSX.Element {
90146
paymentOptions,
91147
preferredChains,
92148
preferredTokens,
149+
preferredSymbol,
93150
feeType,
94151
externalId,
95152
metadata,
96153
showProcessingPayout,
97154
receiverMemo,
98155
} = props;
99156

157+
// Convert preferredSymbol to preferredTokens if needed
158+
// Default to [USDC, USDT] if neither preferredSymbol nor preferredTokens is provided
159+
// If preferredTokens is explicitly provided (even if empty array), it takes precedence
160+
const symbolsToUse: TokenSymbol[] | undefined =
161+
preferredTokens !== undefined
162+
? undefined // preferredTokens takes precedence, don't use preferredSymbol
163+
: preferredSymbol !== undefined
164+
? preferredSymbol
165+
: [TokenSymbol.USDC, TokenSymbol.USDT]; // Default to USDC and USDT
166+
167+
const finalPreferredTokens = convertPreferredSymbolsToTokens(
168+
symbolsToUse,
169+
preferredTokens
170+
);
171+
100172
const commonParams = {
101173
appId,
102174
toChain,
@@ -105,7 +177,7 @@ function RozoPayButtonCustom(props: RozoPayButtonCustomProps): JSX.Element {
105177
intent,
106178
paymentOptions,
107179
preferredChains,
108-
preferredTokens,
180+
preferredTokens: finalPreferredTokens,
109181
evmChains: undefined,
110182
externalId,
111183
metadata,

packages/connectkit/src/components/DaimoPayButton/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
PaymentPayoutCompletedEvent,
77
PaymentStartedEvent,
88
Token,
9+
TokenSymbol,
910
} from "@rozoai/intent-common";
1011
import { ReactElement } from "react";
1112
import { Address } from "viem";
@@ -93,6 +94,11 @@ type CommonPaymentProps = {
9394
* Preferred tokens. These appear first in the token list.
9495
*/
9596
preferredTokens?: Token[];
97+
/**
98+
* Preferred token symbols. These will be converted to preferredTokens internally.
99+
* Only USDC, USDT, and EURC are allowed. Defaults to [USDC, USDT].
100+
*/
101+
preferredSymbol?: TokenSymbol[];
96102
/**
97103
* Only allow payments on these EVM chains.
98104
*/

packages/connectkit/src/components/Pages/SelectMethod/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ export default function SelectMethod() {
316316
options.push(depositAddressOption);
317317
}
318318

319-
console.log("showStellarPaymentMethod", showStellarPaymentMethod);
320-
321319
if (showStellarPaymentMethod) {
322320
options.push({
323321
id: "stellar",

packages/connectkit/src/components/Pages/SelectToken/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function NoTokensAvailable({
181181
// Get supported token symbols from preferredTokens if available
182182
const supportedSymbols = useMemo(() => {
183183
if (preferredTokens && preferredTokens.length > 0) {
184-
return preferredTokens.map((pt) => pt.symbol);
184+
return Array.from(new Set(preferredTokens.map((pt) => pt.symbol)));
185185
}
186186
return [];
187187
}, [preferredTokens]);

packages/connectkit/src/hooks/useWalletPaymentOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ export function useWalletPaymentOptions({
156156
usdRequired: isDepositFlow ? undefined : usdRequired,
157157
destChainId,
158158
preferredChains: memoizedPreferredChains,
159-
preferredTokenAddress: (memoizedPreferredTokens ?? [])?.map(
160-
(t) => t.token
161-
),
159+
// preferredTokenAddress: (memoizedPreferredTokens ?? [])?.map(
160+
// (t) => t.token
161+
// ),
162162
appId: stableAppId,
163163
});
164164

packages/pay-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rozoai/intent-common",
3-
"version": "0.1.7-beta.1",
3+
"version": "0.1.7-beta.2",
44
"description": "Intent Pay shared types and utilities",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)