@stableflow/pay-widgets 0.1.0 → 0.2.0-beta-e820becee0-20261012
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/README.md +6 -2
- package/dist/token-select/index.d.ts +37 -35
- package/dist/token-select/index.js +933 -787
- package/dist/token-select/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -24,17 +24,21 @@ The host must use Tailwind v4 and scan both packages. Without the scan, the widg
|
|
|
24
24
|
|
|
25
25
|
Import `@stableflow/pay-widgets/token-select`. Render `TokenSelectDialog` inside `PayWidgetsProvider`.
|
|
26
26
|
|
|
27
|
-
`PayWidgetsProvider` requires `
|
|
27
|
+
`PayWidgetsProvider` requires `tokens` and `wallet`, plus either `readBalances` or `getBalance`. The host normalizes pay config and passes the flat token list in. The widget does not fetch.
|
|
28
28
|
|
|
29
29
|
```tsx
|
|
30
30
|
import {
|
|
31
31
|
PayWidgetsProvider,
|
|
32
32
|
TokenSelectDialog,
|
|
33
|
+
mapPayConfigSource,
|
|
34
|
+
normalizePayConfig,
|
|
33
35
|
} from "@stableflow/pay-widgets/token-select";
|
|
34
36
|
|
|
37
|
+
const tokens = normalizePayConfig(mapPayConfigSource(payload));
|
|
38
|
+
|
|
35
39
|
export function Picker() {
|
|
36
40
|
return (
|
|
37
|
-
<PayWidgetsProvider wallet={wallet} readBalances={readBalances}>
|
|
41
|
+
<PayWidgetsProvider tokens={tokens} wallet={wallet} readBalances={readBalances}>
|
|
38
42
|
<TokenSelectDialog open={open} onClose={onClose} onSelect={onSelect} />
|
|
39
43
|
</PayWidgetsProvider>
|
|
40
44
|
);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
type ChainKind =
|
|
4
|
+
type ChainKind = string;
|
|
5
|
+
declare const KNOWN_CHAIN_KINDS: readonly ["evm", "near", "solana", "tron", "zec"];
|
|
5
6
|
type PayChain = {
|
|
6
7
|
blockchain: string;
|
|
7
8
|
chainName: string;
|
|
@@ -78,17 +79,22 @@ type ReadBalances = (batch: {
|
|
|
78
79
|
tokens: PayToken[];
|
|
79
80
|
}) => Promise<BalanceReadResult[]>;
|
|
80
81
|
type TokenSelectRole = "payer" | "receiver";
|
|
81
|
-
type ChainOwners = Partial<Record<
|
|
82
|
+
type ChainOwners = Partial<Record<string, string>>;
|
|
83
|
+
/** Stable identity for the connected owners. Keys are sorted so order does not matter. */
|
|
84
|
+
declare function ownerKey(owners: ChainOwners): string;
|
|
82
85
|
type TokenBalanceStatus = "idle" | "loading" | "success" | "error";
|
|
83
86
|
|
|
84
87
|
type PayWidgetsProviderProps = {
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
tokens: PayToken[];
|
|
89
|
+
loading?: boolean;
|
|
87
90
|
wallet: PayWallet;
|
|
88
|
-
readBalances
|
|
89
|
-
|
|
91
|
+
readBalances?: ReadBalances;
|
|
92
|
+
getBalance?: (token: PayToken, owner: string) => string | null | undefined;
|
|
93
|
+
isBalanceLoading?: (token: PayToken, owner: string) => boolean;
|
|
94
|
+
popularTokens?: PopularTokenRef[];
|
|
95
|
+
stableSymbols?: string[];
|
|
96
|
+
chainKindLabels?: Record<string, string>;
|
|
90
97
|
onCopyAddress?: (address: string) => void;
|
|
91
|
-
chainKinds?: Partial<Record<string, ChainKind>>;
|
|
92
98
|
children: ReactNode;
|
|
93
99
|
};
|
|
94
100
|
declare function PayWidgetsProvider(props: PayWidgetsProviderProps): react.JSX.Element;
|
|
@@ -96,6 +102,19 @@ declare function PayWidgetsProvider(props: PayWidgetsProviderProps): react.JSX.E
|
|
|
96
102
|
type TokenSelectSelection = {
|
|
97
103
|
token: PayToken;
|
|
98
104
|
};
|
|
105
|
+
type PaneView = {
|
|
106
|
+
kind: "wallet";
|
|
107
|
+
} | {
|
|
108
|
+
kind: "all";
|
|
109
|
+
} | {
|
|
110
|
+
kind: "rail-chain";
|
|
111
|
+
blockchain: string;
|
|
112
|
+
} | {
|
|
113
|
+
kind: "networks";
|
|
114
|
+
} | {
|
|
115
|
+
kind: "network-chain";
|
|
116
|
+
blockchain: string;
|
|
117
|
+
};
|
|
99
118
|
type TokenSelectDialogProps = {
|
|
100
119
|
open: boolean;
|
|
101
120
|
onClose: () => void;
|
|
@@ -111,6 +130,7 @@ type TokenSelectDialogProps = {
|
|
|
111
130
|
disabledReason?: string;
|
|
112
131
|
className?: string;
|
|
113
132
|
titleClassName?: string;
|
|
133
|
+
headerClassName?: string;
|
|
114
134
|
closeClassName?: string;
|
|
115
135
|
contentClassName?: string;
|
|
116
136
|
searchClassName?: string;
|
|
@@ -119,33 +139,13 @@ type TokenSelectDialogProps = {
|
|
|
119
139
|
};
|
|
120
140
|
declare function TokenSelectDialog(props: TokenSelectDialogProps): react.JSX.Element;
|
|
121
141
|
|
|
122
|
-
type PayConfigStatus = "idle" | "loading" | "success" | "error";
|
|
123
|
-
type PayConfigSnapshot = {
|
|
124
|
-
apiHost: string;
|
|
125
|
-
chains: PayChain[];
|
|
126
|
-
tokens: PayToken[];
|
|
127
|
-
source: PayConfigSource | null;
|
|
128
|
-
status: PayConfigStatus;
|
|
129
|
-
error: string | null;
|
|
130
|
-
fetchedAt: number | null;
|
|
131
|
-
};
|
|
132
142
|
type ChainKindMap = Partial<Record<string, ChainKind>>;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
chains: PayChain[];
|
|
136
|
-
tokens: PayToken[];
|
|
137
|
-
};
|
|
138
|
-
declare function usePayConfigSnapshot(): PayConfigSnapshot;
|
|
139
|
-
declare function usePayConfig(options?: {
|
|
140
|
-
apiHost?: string;
|
|
141
|
-
}): {
|
|
142
|
-
chains: PayChain[];
|
|
143
|
-
tokens: PayToken[];
|
|
144
|
-
source: PayConfigSource | null;
|
|
145
|
-
status: PayConfigStatus;
|
|
146
|
-
error: string | null;
|
|
147
|
-
refetch: () => void;
|
|
143
|
+
type NormalizePayConfigOptions = {
|
|
144
|
+
chainKinds?: ChainKindMap;
|
|
148
145
|
};
|
|
146
|
+
declare function mapPayConfigSource(raw: unknown): PayConfigSource;
|
|
147
|
+
declare function tokenAssetId(network: string, symbol: string, contractAddress: string | null | undefined): string;
|
|
148
|
+
declare function normalizePayConfig(source: PayConfigSource, options?: NormalizePayConfigOptions): PayToken[];
|
|
149
149
|
|
|
150
150
|
type TokenBalance = {
|
|
151
151
|
raw: string | null;
|
|
@@ -158,8 +158,10 @@ declare function clearPayTokenBalances(): void;
|
|
|
158
158
|
declare function usePayTokenBalance(owner: string | null | undefined, assetId: string | null | undefined): TokenBalance | undefined;
|
|
159
159
|
declare function refreshPayTokenBalance(owner: string, token: PayToken): Promise<TokenBalance | null>;
|
|
160
160
|
|
|
161
|
+
declare function chainsFromTokens(tokens: readonly {
|
|
162
|
+
blockchain: string;
|
|
163
|
+
chain: PayChain;
|
|
164
|
+
}[]): PayChain[];
|
|
161
165
|
declare function parsePopularTokens(raw: string | null | undefined): PopularTokenRef[];
|
|
162
166
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
export { type BalanceReadResult, type ChainKind, type ChainOwners, DEFAULT_API_HOST, type PayChain, type PayConfigSnapshot, type PayConfigSource, type PayConfigStatus, type PayToken, type PayWallet, PayWidgetsProvider, type PayWidgetsProviderProps, type PopularTokenRef, type ReadBalances, type TokenBalance, TokenSelectDialog, type TokenSelectDialogProps, type TokenSelectRole, type TokenSelectSelection, clearPayTokenBalances, mapPayConfigSource, normalizePayConfig, parsePopularTokens, refreshPayTokenBalance, usePayConfig, usePayConfigSnapshot, usePayTokenBalance };
|
|
167
|
+
export { type BalanceReadResult, type ChainKind, type ChainOwners, KNOWN_CHAIN_KINDS, type NormalizePayConfigOptions, type PaneView, type PayChain, type PayConfigSource, type PayToken, type PayWallet, PayWidgetsProvider, type PayWidgetsProviderProps, type PopularTokenRef, type ReadBalances, type TokenBalance, TokenSelectDialog, type TokenSelectDialogProps, type TokenSelectRole, type TokenSelectSelection, chainsFromTokens, clearPayTokenBalances, mapPayConfigSource, normalizePayConfig, ownerKey, parsePopularTokens, refreshPayTokenBalance, tokenAssetId, usePayTokenBalance };
|