@daimo/pay 1.0.9 → 1.1.0
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/index.d.ts +260 -3
- package/build/package.json.js +1 -1
- package/build/src/index.js +1 -1
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import React$1, { ReactNode } from 'react';
|
|
2
2
|
export { version } from '../package.json';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import * as _daimo_common from '@daimo/common';
|
|
5
|
+
import { DepositAddressPaymentOptionMetadata, PlatformType, ExternalPaymentOptionMetadata, DaimoPayOrder, DaimoPayTokenAmount, ExternalPaymentOptions, DepositAddressPaymentOptions, DepositAddressPaymentOptionData, SolanaPublicKey, PaymentStartedEvent, PaymentCompletedEvent, PaymentBouncedEvent } from '@daimo/common';
|
|
6
|
+
import { Address, Hex } from 'viem';
|
|
7
|
+
import { AppRouter } from '@daimo/pay-api';
|
|
8
|
+
import { CreateTRPCClient } from '@trpc/client';
|
|
9
|
+
import * as abitype from 'abitype';
|
|
10
|
+
import { WalletName } from '@solana/wallet-adapter-base';
|
|
4
11
|
import { CreateConfigParameters } from '@wagmi/core';
|
|
5
12
|
import { CoinbaseWalletParameters } from 'wagmi/connectors';
|
|
6
|
-
import { PaymentStartedEvent, PaymentCompletedEvent, PaymentBouncedEvent } from '@daimo/common';
|
|
7
|
-
import { Address, Hex } from 'viem';
|
|
8
13
|
import { CreateConnectorFn } from 'wagmi';
|
|
9
14
|
|
|
10
15
|
type Hash = `0x${string}`;
|
|
@@ -93,6 +98,256 @@ type useConnectCallbackProps = {
|
|
|
93
98
|
onDisconnect?: () => void;
|
|
94
99
|
};
|
|
95
100
|
|
|
101
|
+
type TrpcClient = CreateTRPCClient<AppRouter>;
|
|
102
|
+
|
|
103
|
+
declare function useDepositAddressOptions({ trpc, usdRequired, }: {
|
|
104
|
+
trpc: TrpcClient;
|
|
105
|
+
usdRequired: number;
|
|
106
|
+
}): {
|
|
107
|
+
options: DepositAddressPaymentOptionMetadata[];
|
|
108
|
+
loading: boolean;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
declare function useExternalPaymentOptions({ trpc, filterIds, usdRequired, platform, }: {
|
|
112
|
+
trpc: TrpcClient;
|
|
113
|
+
filterIds: string[] | undefined;
|
|
114
|
+
usdRequired: number | undefined;
|
|
115
|
+
platform: PlatformType | undefined;
|
|
116
|
+
}): {
|
|
117
|
+
options: ExternalPaymentOptionMetadata[];
|
|
118
|
+
loading: boolean;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
type SolanaPaymentOption = Awaited<ReturnType<TrpcClient["getSolanaPaymentOptions"]["query"]>>[0];
|
|
122
|
+
declare function useSolanaPaymentOptions({ trpc, address, usdRequired, }: {
|
|
123
|
+
trpc: TrpcClient;
|
|
124
|
+
address: string | undefined;
|
|
125
|
+
usdRequired: number | undefined;
|
|
126
|
+
}): {
|
|
127
|
+
options: {
|
|
128
|
+
required: {
|
|
129
|
+
token: {
|
|
130
|
+
symbol: string;
|
|
131
|
+
chainId: number;
|
|
132
|
+
token: abitype.Address | _daimo_common.SolanaPublicKey;
|
|
133
|
+
usd: number;
|
|
134
|
+
displayDecimals: number;
|
|
135
|
+
decimals: number;
|
|
136
|
+
name?: string;
|
|
137
|
+
fiatSymbol?: string;
|
|
138
|
+
logoURI?: string;
|
|
139
|
+
};
|
|
140
|
+
amount: _daimo_common.BigIntStr;
|
|
141
|
+
usd: number;
|
|
142
|
+
};
|
|
143
|
+
balance: {
|
|
144
|
+
token: {
|
|
145
|
+
symbol: string;
|
|
146
|
+
chainId: number;
|
|
147
|
+
token: abitype.Address | _daimo_common.SolanaPublicKey;
|
|
148
|
+
usd: number;
|
|
149
|
+
displayDecimals: number;
|
|
150
|
+
decimals: number;
|
|
151
|
+
name?: string;
|
|
152
|
+
fiatSymbol?: string;
|
|
153
|
+
logoURI?: string;
|
|
154
|
+
};
|
|
155
|
+
amount: _daimo_common.BigIntStr;
|
|
156
|
+
usd: number;
|
|
157
|
+
};
|
|
158
|
+
}[] | null;
|
|
159
|
+
isLoading: boolean;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/** Wallet payment options. User picks one. */
|
|
163
|
+
type WalletPaymentOption = Awaited<ReturnType<TrpcClient["getWalletPaymentOptions"]["query"]>>[0];
|
|
164
|
+
declare function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, preferredChains, preferredTokens, log, }: {
|
|
165
|
+
trpc: TrpcClient;
|
|
166
|
+
address: string | undefined;
|
|
167
|
+
usdRequired: number | undefined;
|
|
168
|
+
destChainId: number | undefined;
|
|
169
|
+
preferredChains: number[] | undefined;
|
|
170
|
+
preferredTokens: {
|
|
171
|
+
chain: number;
|
|
172
|
+
address: string;
|
|
173
|
+
}[] | undefined;
|
|
174
|
+
log: (msg: string) => void;
|
|
175
|
+
}): {
|
|
176
|
+
options: {
|
|
177
|
+
fees: {
|
|
178
|
+
token: {
|
|
179
|
+
symbol: string;
|
|
180
|
+
chainId: number;
|
|
181
|
+
token: abitype.Address | _daimo_common.SolanaPublicKey;
|
|
182
|
+
usd: number;
|
|
183
|
+
displayDecimals: number;
|
|
184
|
+
decimals: number;
|
|
185
|
+
name?: string;
|
|
186
|
+
fiatSymbol?: string;
|
|
187
|
+
logoURI?: string;
|
|
188
|
+
};
|
|
189
|
+
amount: _daimo_common.BigIntStr;
|
|
190
|
+
usd: number;
|
|
191
|
+
};
|
|
192
|
+
required: {
|
|
193
|
+
token: {
|
|
194
|
+
symbol: string;
|
|
195
|
+
chainId: number;
|
|
196
|
+
token: abitype.Address | _daimo_common.SolanaPublicKey;
|
|
197
|
+
usd: number;
|
|
198
|
+
displayDecimals: number;
|
|
199
|
+
decimals: number;
|
|
200
|
+
name?: string;
|
|
201
|
+
fiatSymbol?: string;
|
|
202
|
+
logoURI?: string;
|
|
203
|
+
};
|
|
204
|
+
amount: _daimo_common.BigIntStr;
|
|
205
|
+
usd: number;
|
|
206
|
+
};
|
|
207
|
+
balance: {
|
|
208
|
+
token: {
|
|
209
|
+
symbol: string;
|
|
210
|
+
chainId: number;
|
|
211
|
+
token: abitype.Address | _daimo_common.SolanaPublicKey;
|
|
212
|
+
usd: number;
|
|
213
|
+
displayDecimals: number;
|
|
214
|
+
decimals: number;
|
|
215
|
+
name?: string;
|
|
216
|
+
fiatSymbol?: string;
|
|
217
|
+
logoURI?: string;
|
|
218
|
+
};
|
|
219
|
+
amount: _daimo_common.BigIntStr;
|
|
220
|
+
usd: number;
|
|
221
|
+
};
|
|
222
|
+
}[] | null;
|
|
223
|
+
isLoading: boolean;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/** Payment parameters. The payment is created only after user taps pay. */
|
|
227
|
+
interface PayParams {
|
|
228
|
+
/** App ID, for authentication. */
|
|
229
|
+
appId: string;
|
|
230
|
+
/** Destination chain ID. */
|
|
231
|
+
toChain: number;
|
|
232
|
+
/** The destination token to send. */
|
|
233
|
+
toToken: Address;
|
|
234
|
+
/** The amount of the token to send. */
|
|
235
|
+
toUnits: string;
|
|
236
|
+
/** The final address to transfer to or contract to call. */
|
|
237
|
+
toAddress: Address;
|
|
238
|
+
/** Calldata for final call, or empty data for transfer. */
|
|
239
|
+
toCallData?: Hex;
|
|
240
|
+
/** Let the user edit the amount to send. */
|
|
241
|
+
isAmountEditable: boolean;
|
|
242
|
+
/** The intent verb, such as Pay, Deposit, or Purchase. Default: Pay */
|
|
243
|
+
intent?: string;
|
|
244
|
+
/** Payment options. By default, all are enabled. */
|
|
245
|
+
paymentOptions?: PaymentOption[];
|
|
246
|
+
/** Preferred chain IDs. */
|
|
247
|
+
preferredChains?: number[];
|
|
248
|
+
/** Preferred tokens. These appear first in the token list. */
|
|
249
|
+
preferredTokens?: {
|
|
250
|
+
chain: number;
|
|
251
|
+
address: Address;
|
|
252
|
+
}[];
|
|
253
|
+
}
|
|
254
|
+
/** Creates (or loads) a payment and manages the corresponding modal. */
|
|
255
|
+
interface PaymentState {
|
|
256
|
+
setPayId: (id: string | undefined) => void;
|
|
257
|
+
setPayParams: (payParams: PayParams | undefined) => void;
|
|
258
|
+
payParams: PayParams | undefined;
|
|
259
|
+
daimoPayOrder: DaimoPayOrder | undefined;
|
|
260
|
+
modalOptions: DaimoPayModalOptions;
|
|
261
|
+
setModalOptions: (modalOptions: DaimoPayModalOptions) => void;
|
|
262
|
+
paymentWaitingMessage: string | undefined;
|
|
263
|
+
externalPaymentOptions: ReturnType<typeof useExternalPaymentOptions>;
|
|
264
|
+
walletPaymentOptions: ReturnType<typeof useWalletPaymentOptions>;
|
|
265
|
+
solanaPaymentOptions: ReturnType<typeof useSolanaPaymentOptions>;
|
|
266
|
+
depositAddressOptions: ReturnType<typeof useDepositAddressOptions>;
|
|
267
|
+
selectedExternalOption: ExternalPaymentOptionMetadata | undefined;
|
|
268
|
+
selectedTokenOption: WalletPaymentOption | undefined;
|
|
269
|
+
selectedSolanaTokenOption: SolanaPaymentOption | undefined;
|
|
270
|
+
selectedDepositAddressOption: DepositAddressPaymentOptionMetadata | undefined;
|
|
271
|
+
setSelectedDepositAddressOption: (option: DepositAddressPaymentOptionMetadata | undefined) => void;
|
|
272
|
+
setSelectedExternalOption: (option: ExternalPaymentOptionMetadata | undefined) => void;
|
|
273
|
+
setSelectedTokenOption: (option: WalletPaymentOption | undefined) => void;
|
|
274
|
+
setSelectedSolanaTokenOption: (option: SolanaPaymentOption | undefined) => void;
|
|
275
|
+
setChosenUsd: (amount: number) => void;
|
|
276
|
+
payWithToken: (tokenAmount: DaimoPayTokenAmount) => Promise<void>;
|
|
277
|
+
payWithExternal: (option: ExternalPaymentOptions) => Promise<string>;
|
|
278
|
+
payWithDepositAddress: (option: DepositAddressPaymentOptions) => Promise<DepositAddressPaymentOptionData | null>;
|
|
279
|
+
payWithSolanaToken: (inputToken: SolanaPublicKey) => Promise<string | undefined>;
|
|
280
|
+
refreshOrder: () => Promise<void>;
|
|
281
|
+
onSuccess: (args: {
|
|
282
|
+
txHash: string;
|
|
283
|
+
txURL?: string;
|
|
284
|
+
}) => void;
|
|
285
|
+
senderEnsName: string | undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
type SolanaWalletName = WalletName<string>;
|
|
289
|
+
|
|
290
|
+
declare enum ROUTES {
|
|
291
|
+
SELECT_METHOD = "daimoPaySelectMethod",
|
|
292
|
+
SELECT_TOKEN = "daimoPaySelectToken",
|
|
293
|
+
WAITING_OTHER = "daimoPayWaitingOther",
|
|
294
|
+
SELECT_DEPOSIT_ADDRESS_CHAIN = "daimoPaySelectDepositAddressChain",
|
|
295
|
+
WAITING_DEPOSIT_ADDRESS = "daimoPayWaitingDepositAddress",
|
|
296
|
+
PAY_WITH_TOKEN = "daimoPayPayWithToken",
|
|
297
|
+
CONFIRMATION = "daimoPayConfirmation",
|
|
298
|
+
SOLANA_CONNECT = "daimoPaySolanaConnect",
|
|
299
|
+
SOLANA_CONNECTOR = "daimoPaySolanaConnector",
|
|
300
|
+
SOLANA_SELECT_TOKEN = "daimoPaySolanaSelectToken",
|
|
301
|
+
SOLANA_PAY_WITH_TOKEN = "daimoPaySolanaPayWithToken",
|
|
302
|
+
ONBOARDING = "onboarding",
|
|
303
|
+
ABOUT = "about",
|
|
304
|
+
CONNECTORS = "connectors",
|
|
305
|
+
MOBILECONNECTORS = "mobileConnectors",
|
|
306
|
+
CONNECT = "connect",
|
|
307
|
+
DOWNLOAD = "download",
|
|
308
|
+
SWITCHNETWORKS = "switchNetworks"
|
|
309
|
+
}
|
|
310
|
+
/** Chosen Ethereum wallet, eg MM or Rainbow. Specifies wallet ID. */
|
|
311
|
+
type Connector = {
|
|
312
|
+
id: string;
|
|
313
|
+
};
|
|
314
|
+
type Error = string | React$1.ReactNode | null;
|
|
315
|
+
/** Daimo Pay internal context. */
|
|
316
|
+
type ContextValue = {
|
|
317
|
+
theme: Theme;
|
|
318
|
+
setTheme: React$1.Dispatch<React$1.SetStateAction<Theme>>;
|
|
319
|
+
mode: Mode;
|
|
320
|
+
setMode: React$1.Dispatch<React$1.SetStateAction<Mode>>;
|
|
321
|
+
customTheme: CustomTheme | undefined;
|
|
322
|
+
setCustomTheme: React$1.Dispatch<React$1.SetStateAction<CustomTheme | undefined>>;
|
|
323
|
+
lang: Languages;
|
|
324
|
+
setLang: React$1.Dispatch<React$1.SetStateAction<Languages>>;
|
|
325
|
+
open: boolean;
|
|
326
|
+
setOpen: React$1.Dispatch<React$1.SetStateAction<boolean>>;
|
|
327
|
+
route: string;
|
|
328
|
+
setRoute: React$1.Dispatch<React$1.SetStateAction<ROUTES>>;
|
|
329
|
+
connector: Connector;
|
|
330
|
+
setConnector: React$1.Dispatch<React$1.SetStateAction<Connector>>;
|
|
331
|
+
errorMessage: Error;
|
|
332
|
+
debugMode?: boolean;
|
|
333
|
+
log: (...props: any) => void;
|
|
334
|
+
displayError: (message: string | React$1.ReactNode | null, code?: any) => void;
|
|
335
|
+
resize: number;
|
|
336
|
+
triggerResize: () => void;
|
|
337
|
+
/** Chosen Solana wallet, eg Phantom.*/
|
|
338
|
+
solanaConnector: SolanaWalletName | undefined;
|
|
339
|
+
setSolanaConnector: React$1.Dispatch<React$1.SetStateAction<SolanaWalletName | undefined>>;
|
|
340
|
+
/** Global options, across all pay buttons and payments. */
|
|
341
|
+
options?: DaimoPayContextOptions;
|
|
342
|
+
/** Loads a payment, then shows the modal to complete payment. */
|
|
343
|
+
showPayment: (modalOptions: DaimoPayModalOptions) => Promise<void>;
|
|
344
|
+
/** Payment status & callbacks. */
|
|
345
|
+
paymentState: PaymentState;
|
|
346
|
+
/** TRPC API client. Internal use only. */
|
|
347
|
+
trpc: any;
|
|
348
|
+
} & useConnectCallbackProps;
|
|
349
|
+
/** Meant for internal use. This will be non-exported in a future SDK version. */
|
|
350
|
+
declare const Context: React$1.Context<ContextValue | null>;
|
|
96
351
|
type DaimoPayProviderProps = {
|
|
97
352
|
children?: React$1.ReactNode;
|
|
98
353
|
theme?: Theme;
|
|
@@ -113,6 +368,8 @@ type DaimoPayProviderProps = {
|
|
|
113
368
|
* Provides context for DaimoPayButton and hooks. Place in app root or layout.
|
|
114
369
|
*/
|
|
115
370
|
declare const DaimoPayProvider: (props: DaimoPayProviderProps) => react_jsx_runtime.JSX.Element;
|
|
371
|
+
/** Daimo Pay internal context. */
|
|
372
|
+
declare const usePayContext: () => ContextValue;
|
|
116
373
|
|
|
117
374
|
type DefaultConfigProps = {
|
|
118
375
|
appName: string;
|
|
@@ -262,4 +519,4 @@ declare const daimoPayVersion: string;
|
|
|
262
519
|
/** Generates a globally-unique payId. */
|
|
263
520
|
declare function generatePayId(): string;
|
|
264
521
|
|
|
265
|
-
export { Avatar, Chain as ChainIcon, DaimoPayButton, DaimoPayProvider, types_d as Types, daimoPayVersion, generatePayId, defaultConfig as getDefaultConfig, useModal as useDaimoPayModal, useDaimoPayStatus, wallets };
|
|
522
|
+
export { Avatar, Chain as ChainIcon, DaimoPayButton, Context as DaimoPayContext, DaimoPayProvider, types_d as Types, daimoPayVersion, generatePayId, defaultConfig as getDefaultConfig, useModal as useDaimoPayModal, useDaimoPayStatus, usePayContext, wallets };
|
package/build/package.json.js
CHANGED
package/build/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { version } from '../package.json.js';
|
|
2
|
-
export { DaimoPayProvider } from './components/DaimoPay.js';
|
|
2
|
+
export { Context as DaimoPayContext, DaimoPayProvider, usePayContext } from './components/DaimoPay.js';
|
|
3
3
|
export { default as getDefaultConfig } from './defaultConfig.js';
|
|
4
4
|
export { DaimoPayButton } from './components/DaimoPayButton/index.js';
|
|
5
5
|
export { useDaimoPayStatus } from './hooks/useDaimoPayStatus.js';
|