@daimo/pay 1.9.5 → 1.10.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/index.d.ts +90 -17
- package/build/index.js +152 -7
- package/build/index.js.map +1 -1
- package/package.json +9 -3
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React$1
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import React__default, { ReactNode, ReactElement } from 'react';
|
|
2
3
|
export { version } from '../package.json';
|
|
3
4
|
import { CreateConfigParameters } from '@wagmi/core';
|
|
4
5
|
import { CreateConnectorFn } from 'wagmi';
|
|
@@ -19,7 +20,7 @@ type CustomAvatarProps = {
|
|
|
19
20
|
radius: number;
|
|
20
21
|
};
|
|
21
22
|
/** Icon for an Ethereum address. Supports ENS names and avatars. */
|
|
22
|
-
declare const Avatar:
|
|
23
|
+
declare const Avatar: React__default.FC<{
|
|
23
24
|
address?: Hash | undefined;
|
|
24
25
|
name?: string | undefined;
|
|
25
26
|
size?: number;
|
|
@@ -109,7 +110,7 @@ type useConnectCallbackProps = {
|
|
|
109
110
|
};
|
|
110
111
|
|
|
111
112
|
type DaimoPayProviderProps = {
|
|
112
|
-
children?:
|
|
113
|
+
children?: React__default.ReactNode;
|
|
113
114
|
theme?: Theme;
|
|
114
115
|
mode?: Mode;
|
|
115
116
|
customTheme?: CustomTheme;
|
|
@@ -191,7 +192,7 @@ type PayButtonPaymentProps = {
|
|
|
191
192
|
* */
|
|
192
193
|
metadata?: DaimoPayUserMetadata;
|
|
193
194
|
/**
|
|
194
|
-
* The address to refund to if the payment bounces
|
|
195
|
+
* The address to refund to if the payment bounces.
|
|
195
196
|
*/
|
|
196
197
|
refundAddress?: Address;
|
|
197
198
|
} | {
|
|
@@ -349,6 +350,8 @@ type DaimoPayFunctions = {
|
|
|
349
350
|
hydrateOrder: (refundAddress?: Address) => Promise<Extract<PaymentState$1, {
|
|
350
351
|
type: "payment_unpaid";
|
|
351
352
|
}>>;
|
|
353
|
+
/** Trigger search for payment on the current order. */
|
|
354
|
+
paySource: () => void;
|
|
352
355
|
/**
|
|
353
356
|
* Register an Ethereum payment source for the current order.
|
|
354
357
|
* Call this after the user has submitted an Ethereum payment transaction.
|
|
@@ -426,7 +429,7 @@ type UseDaimoPayUI = {
|
|
|
426
429
|
declare function useDaimoPayUI(): UseDaimoPayUI;
|
|
427
430
|
|
|
428
431
|
/** Icon for an EVM chain, given chain ID. No ID shows a loading spinner. */
|
|
429
|
-
declare const Chain:
|
|
432
|
+
declare const Chain: React__default.FC<{
|
|
430
433
|
id?: number;
|
|
431
434
|
unsupported?: boolean;
|
|
432
435
|
radius?: number | string;
|
|
@@ -590,28 +593,28 @@ interface PaymentState {
|
|
|
590
593
|
type SolanaWalletName = WalletName<string>;
|
|
591
594
|
|
|
592
595
|
/** Meant for internal use. This will be non-exported in a future SDK version. */
|
|
593
|
-
declare const PayContext:
|
|
596
|
+
declare const PayContext: React__default.Context<PayContextValue | null>;
|
|
594
597
|
type PayLogFn = (message: string, ...props: any[]) => void;
|
|
595
598
|
/** Daimo Pay internal context. */
|
|
596
599
|
type PayContextValue = {
|
|
597
600
|
theme: Theme;
|
|
598
|
-
setTheme:
|
|
601
|
+
setTheme: React__default.Dispatch<React__default.SetStateAction<Theme>>;
|
|
599
602
|
mode: Mode;
|
|
600
|
-
setMode:
|
|
603
|
+
setMode: React__default.Dispatch<React__default.SetStateAction<Mode>>;
|
|
601
604
|
customTheme: CustomTheme | undefined;
|
|
602
|
-
setCustomTheme:
|
|
605
|
+
setCustomTheme: React__default.Dispatch<React__default.SetStateAction<CustomTheme | undefined>>;
|
|
603
606
|
lang: Languages;
|
|
604
|
-
setLang:
|
|
607
|
+
setLang: React__default.Dispatch<React__default.SetStateAction<Languages>>;
|
|
605
608
|
setOnOpen: (fn?: () => void) => void;
|
|
606
609
|
setOnClose: (fn?: () => void) => void;
|
|
607
610
|
open: boolean;
|
|
608
611
|
setOpen: (open: boolean, meta?: Record<string, any>) => void;
|
|
609
612
|
route: string;
|
|
610
613
|
setRoute: (route: ROUTES, data?: Record<string, any>) => void;
|
|
611
|
-
errorMessage: string |
|
|
614
|
+
errorMessage: string | React__default.ReactNode | null;
|
|
612
615
|
debugMode?: boolean;
|
|
613
616
|
log: PayLogFn;
|
|
614
|
-
displayError: (message: string |
|
|
617
|
+
displayError: (message: string | React__default.ReactNode | null, code?: any) => void;
|
|
615
618
|
resize: number;
|
|
616
619
|
triggerResize: () => void;
|
|
617
620
|
/** Session ID. */
|
|
@@ -623,7 +626,7 @@ type PayContextValue = {
|
|
|
623
626
|
setPendingConnectorId: (id: string) => void;
|
|
624
627
|
/** Chosen Solana wallet, eg Phantom.*/
|
|
625
628
|
solanaConnector: SolanaWalletName | undefined;
|
|
626
|
-
setSolanaConnector:
|
|
629
|
+
setSolanaConnector: React__default.Dispatch<React__default.SetStateAction<SolanaWalletName | undefined>>;
|
|
627
630
|
/** Global options, across all pay buttons and payments. */
|
|
628
631
|
options?: DaimoPayContextOptions;
|
|
629
632
|
/** Loads a payment, then shows the modal to complete payment. */
|
|
@@ -636,14 +639,84 @@ type PayContextValue = {
|
|
|
636
639
|
onSuccess: () => void;
|
|
637
640
|
/** Custom message to display on confirmation page. */
|
|
638
641
|
confirmationMessage?: string;
|
|
639
|
-
setConfirmationMessage:
|
|
642
|
+
setConfirmationMessage: React__default.Dispatch<React__default.SetStateAction<string | undefined>>;
|
|
640
643
|
/** Redirect URL to return to the app. E.g. after Coinbase, Binance, RampNetwork. */
|
|
641
644
|
redirectReturnUrl?: string;
|
|
642
|
-
setRedirectReturnUrl:
|
|
645
|
+
setRedirectReturnUrl: React__default.Dispatch<React__default.SetStateAction<string | undefined>>;
|
|
643
646
|
} & useConnectCallbackProps;
|
|
644
647
|
|
|
645
648
|
/** Daimo Pay internal context. */
|
|
646
649
|
declare const usePayContext: () => PayContextValue;
|
|
647
650
|
|
|
648
|
-
|
|
649
|
-
|
|
651
|
+
type WorldPayButtonPaymentProps = {
|
|
652
|
+
/**
|
|
653
|
+
* Your public app ID. Specify either (payId) or (appId + parameters).
|
|
654
|
+
*/
|
|
655
|
+
appId: string;
|
|
656
|
+
/**
|
|
657
|
+
* Your World Mini App app ID.
|
|
658
|
+
*/
|
|
659
|
+
worldAppId: string;
|
|
660
|
+
/**
|
|
661
|
+
* Destination chain ID.
|
|
662
|
+
*/
|
|
663
|
+
toChain: number;
|
|
664
|
+
/**
|
|
665
|
+
* The destination token to send, completing payment. Must be an ERC-20
|
|
666
|
+
* token or the zero address, indicating the native token / ETH.
|
|
667
|
+
*/
|
|
668
|
+
toToken: Address;
|
|
669
|
+
/**
|
|
670
|
+
* The amount of destination token to send (transfer or approve).
|
|
671
|
+
*/
|
|
672
|
+
toUnits: string;
|
|
673
|
+
/**
|
|
674
|
+
* The destination address to transfer to, or contract to call.
|
|
675
|
+
*/
|
|
676
|
+
toAddress: Address;
|
|
677
|
+
/**
|
|
678
|
+
* Optional calldata to call an arbitrary function on `toAddress`.
|
|
679
|
+
*/
|
|
680
|
+
toCallData?: Hex;
|
|
681
|
+
/**
|
|
682
|
+
* The intent verb, such as "Pay", "Deposit", or "Purchase".
|
|
683
|
+
*/
|
|
684
|
+
intent?: string;
|
|
685
|
+
/**
|
|
686
|
+
* External ID. E.g. a correlation ID.
|
|
687
|
+
*/
|
|
688
|
+
externalId?: string;
|
|
689
|
+
/**
|
|
690
|
+
* Developer metadata. E.g. correlation ID.
|
|
691
|
+
* */
|
|
692
|
+
metadata?: DaimoPayUserMetadata;
|
|
693
|
+
/**
|
|
694
|
+
* The address to refund to if the payment bounces.
|
|
695
|
+
*/
|
|
696
|
+
refundAddress?: Address;
|
|
697
|
+
};
|
|
698
|
+
type WorldPayButtonProps = WorldPayButtonPaymentProps & {
|
|
699
|
+
/** Light mode, dark mode, or auto. */
|
|
700
|
+
mode?: Mode;
|
|
701
|
+
/** Named theme. See docs for options. */
|
|
702
|
+
theme?: Theme;
|
|
703
|
+
/** Custom theme. See docs for options. */
|
|
704
|
+
customTheme?: CustomTheme;
|
|
705
|
+
/** Disable interaction. */
|
|
706
|
+
disabled?: boolean;
|
|
707
|
+
};
|
|
708
|
+
type WorldPayButtonCustomProps = WorldPayButtonProps & {
|
|
709
|
+
children: (renderProps: {
|
|
710
|
+
show: () => void;
|
|
711
|
+
isMiniKitReady: boolean;
|
|
712
|
+
}) => ReactElement;
|
|
713
|
+
};
|
|
714
|
+
declare function WorldPayButton(props: WorldPayButtonProps): react_jsx_runtime.JSX.Element;
|
|
715
|
+
declare namespace WorldPayButton {
|
|
716
|
+
var displayName: string;
|
|
717
|
+
var Custom: typeof WorldPayButtonCustom;
|
|
718
|
+
}
|
|
719
|
+
declare function WorldPayButtonCustom(props: WorldPayButtonCustomProps): ReactElement<any, string | React$1.JSXElementConstructor<any>>;
|
|
720
|
+
|
|
721
|
+
export { Avatar, Chain as ChainIcon, DaimoPayButton, PayContext as DaimoPayContext, DaimoPayProvider, types as Types, WorldPayButton, daimoPayVersion, defaultConfig as getDefaultConfig, useDaimoPay, useDaimoPayStatus, useDaimoPayUI, usePayContext, wallets };
|
|
722
|
+
export type { All, CustomAvatarProps, CustomTheme, DaimoPayButtonCustomProps, DaimoPayButtonProps, DaimoPayContextOptions, DaimoPayModalOptions, DaimoPayment, Languages, Mode, Theme, WorldPayButtonCustomProps, WorldPayButtonProps };
|
package/build/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { http, useConnectors as useConnectors$1, useAccount, useSwitchChain, use
|
|
|
2
2
|
import { mainnet, base as base$1, polygon, optimism, arbitrum, linea, bsc, sepolia, baseSepolia, worldchain, mantle } from 'wagmi/chains';
|
|
3
3
|
import { safe, injected, coinbaseWallet, walletConnect } from '@wagmi/connectors';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
|
-
import { DaimoPayIntentStatus, assert, DaimoPayOrderMode, isHydrated, readDaimoPayOrderID, getOrderDestChainId, assertNotNull, getChainName, arbitrum as arbitrum$1, base as base$2, bsc as bsc$1, ethereum, linea as linea$1, mantle as mantle$1, optimism as optimism$1, polygon as polygon$1, worldchain as worldchain$1, solana, getAddressContraction, supportedChains, getChainExplorerTxUrl, ExternalPaymentOptions, DepositAddressPaymentOptions, ethereumUSDC, polygonUSDC, baseUSDC, arbitrumUSDC, optimismUSDC, isCCTPV1Chain, debugJson, writeDaimoPayOrderID, DaimoPayOrderStatusSource, getOrderSourceChainId, DaimoPayEventType, getDaimoPayOrderView } from '@daimo/pay-common';
|
|
5
|
+
import { DaimoPayIntentStatus, assert, DaimoPayOrderMode, isHydrated, readDaimoPayOrderID, getOrderDestChainId, assertNotNull, getChainName, arbitrum as arbitrum$1, base as base$2, bsc as bsc$1, ethereum, linea as linea$1, mantle as mantle$1, optimism as optimism$1, polygon as polygon$1, worldchain as worldchain$1, solana, getAddressContraction, supportedChains, getChainExplorerTxUrl, ExternalPaymentOptions, DepositAddressPaymentOptions, ethereumUSDC, polygonUSDC, baseUSDC, arbitrumUSDC, optimismUSDC, isCCTPV1Chain, debugJson, writeDaimoPayOrderID, DaimoPayOrderStatusSource, getOrderSourceChainId, DaimoPayEventType, getDaimoPayOrderView, worldchainWLD, worldchainUSDCe } from '@daimo/pay-common';
|
|
6
6
|
import { Buffer } from 'buffer';
|
|
7
7
|
import React, { createContext, useRef, useState, useEffect, useLayoutEffect, useMemo, useContext, useSyncExternalStore, useCallback, createElement } from 'react';
|
|
8
8
|
import styled$1, { css, keyframes, ThemeProvider } from 'styled-components';
|
|
@@ -22,7 +22,7 @@ import { VersionedTransaction } from '@solana/web3.js';
|
|
|
22
22
|
import { normalize } from 'viem/ens';
|
|
23
23
|
|
|
24
24
|
var name = "@daimo/pay";
|
|
25
|
-
var version = "1.
|
|
25
|
+
var version = "1.10.1";
|
|
26
26
|
var author = "Daimo";
|
|
27
27
|
var homepage = "https://pay.daimo.com";
|
|
28
28
|
var license = "BSD-2-Clause license";
|
|
@@ -61,7 +61,7 @@ var keywords = [
|
|
|
61
61
|
"crypto"
|
|
62
62
|
];
|
|
63
63
|
var dependencies = {
|
|
64
|
-
"@daimo/pay-common": "1.
|
|
64
|
+
"@daimo/pay-common": "1.10.1",
|
|
65
65
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
66
66
|
"@solana/wallet-adapter-base": "^0.9.23",
|
|
67
67
|
"@solana/wallet-adapter-react": "^0.15.35",
|
|
@@ -84,7 +84,13 @@ var peerDependencies = {
|
|
|
84
84
|
react: "18.x || 19.x",
|
|
85
85
|
"react-dom": "18.x || 19.x",
|
|
86
86
|
viem: ">=2.22.0",
|
|
87
|
-
wagmi: "2.x"
|
|
87
|
+
wagmi: "2.x",
|
|
88
|
+
"@worldcoin/minikit-js": ">=1.9.5"
|
|
89
|
+
};
|
|
90
|
+
var peerDependenciesMeta = {
|
|
91
|
+
"@worldcoin/minikit-js": {
|
|
92
|
+
optional: true
|
|
93
|
+
}
|
|
88
94
|
};
|
|
89
95
|
var devDependencies = {
|
|
90
96
|
"@rollup/plugin-json": "^6.1.0",
|
|
@@ -119,6 +125,7 @@ var packageJson = {
|
|
|
119
125
|
keywords: keywords,
|
|
120
126
|
dependencies: dependencies,
|
|
121
127
|
peerDependencies: peerDependencies,
|
|
128
|
+
peerDependenciesMeta: peerDependenciesMeta,
|
|
122
129
|
devDependencies: devDependencies
|
|
123
130
|
};
|
|
124
131
|
|
|
@@ -2565,6 +2572,15 @@ function attachPaymentEffectHandlers(store, trpc, log) {
|
|
|
2565
2572
|
}
|
|
2566
2573
|
break;
|
|
2567
2574
|
}
|
|
2575
|
+
case "pay_source": {
|
|
2576
|
+
if (prev.type === "payment_unpaid") {
|
|
2577
|
+
runPaySourceEffects(store, trpc, prev);
|
|
2578
|
+
}
|
|
2579
|
+
else {
|
|
2580
|
+
log(`[EFFECT] Invalid event ${event.type} on state ${prev.type}`);
|
|
2581
|
+
}
|
|
2582
|
+
break;
|
|
2583
|
+
}
|
|
2568
2584
|
case "pay_ethereum_source": {
|
|
2569
2585
|
if (prev.type === "payment_unpaid") {
|
|
2570
2586
|
runPayEthereumSourceEffects(store, trpc, prev, event);
|
|
@@ -2731,6 +2747,18 @@ async function runHydratePayIdEffects(store, trpc, prev, event) {
|
|
|
2731
2747
|
store.dispatch({ type: "error", order: prev.order, message: e.message });
|
|
2732
2748
|
}
|
|
2733
2749
|
}
|
|
2750
|
+
async function runPaySourceEffects(store, trpc, prev) {
|
|
2751
|
+
const orderId = prev.order.id;
|
|
2752
|
+
try {
|
|
2753
|
+
const order = await trpc.findOrderPayments.query({
|
|
2754
|
+
orderId: orderId.toString(),
|
|
2755
|
+
});
|
|
2756
|
+
store.dispatch({ type: "order_refreshed", order });
|
|
2757
|
+
}
|
|
2758
|
+
catch (e) {
|
|
2759
|
+
store.dispatch({ type: "error", order: prev.order, message: e.message });
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2734
2762
|
async function runPayEthereumSourceEffects(store, trpc, prev, event) {
|
|
2735
2763
|
const orderId = prev.order.id;
|
|
2736
2764
|
try {
|
|
@@ -2858,6 +2886,7 @@ function useDaimoPay() {
|
|
|
2858
2886
|
const hydratedOrderState = await waitForPaymentState(store, (s) => s.type === "payment_unpaid");
|
|
2859
2887
|
return hydratedOrderState;
|
|
2860
2888
|
}, [dispatch, store]);
|
|
2889
|
+
const paySource = useCallback(() => dispatch({ type: "pay_source" }), [dispatch]);
|
|
2861
2890
|
const payEthSource = useCallback((args) => dispatch({ type: "pay_ethereum_source", ...args }), [dispatch]);
|
|
2862
2891
|
const paySolanaSource = useCallback((args) => dispatch({ type: "pay_solana_source", ...args }), [dispatch]);
|
|
2863
2892
|
const reset = useCallback(() => dispatch({ type: "reset" }), [dispatch]);
|
|
@@ -2868,6 +2897,7 @@ function useDaimoPay() {
|
|
|
2868
2897
|
createPreviewOrder,
|
|
2869
2898
|
hydrateOrder,
|
|
2870
2899
|
setPayId,
|
|
2900
|
+
paySource,
|
|
2871
2901
|
payEthSource,
|
|
2872
2902
|
paySolanaSource,
|
|
2873
2903
|
reset,
|
|
@@ -13096,7 +13126,7 @@ const ThemedButton = ({ children, variant = "primary", autoSize = true, duration
|
|
|
13096
13126
|
function DaimoPayButton(props) {
|
|
13097
13127
|
const { theme, mode, customTheme } = props;
|
|
13098
13128
|
const context = usePayContext();
|
|
13099
|
-
return (jsx(DaimoPayButtonCustom, { ...props, children: ({ show }) => (jsx(ResetContainer, { "$useTheme": theme ?? context.theme, "$useMode": mode ?? context.mode, "$customTheme": customTheme ?? context.customTheme, children: jsx(ThemeContainer, { onClick: !props.disabled && show, children: jsx(ThemedButton, { theme: theme ?? context.theme, mode: mode ?? context.mode, customTheme: customTheme ?? context.customTheme, children: jsx(DaimoPayButtonInner, {
|
|
13129
|
+
return (jsx(DaimoPayButtonCustom, { ...props, children: ({ show }) => (jsx(ResetContainer, { "$useTheme": theme ?? context.theme, "$useMode": mode ?? context.mode, "$customTheme": customTheme ?? context.customTheme, children: jsx(ThemeContainer, { onClick: !props.disabled && show, children: jsx(ThemedButton, { theme: theme ?? context.theme, mode: mode ?? context.mode, customTheme: customTheme ?? context.customTheme, children: jsx(DaimoPayButtonInner, {}) }) }) })) }));
|
|
13100
13130
|
}
|
|
13101
13131
|
/** Like DaimoPayButton, but with custom styling. */
|
|
13102
13132
|
function DaimoPayButtonCustom(props) {
|
|
@@ -13269,7 +13299,7 @@ const contentVariants = {
|
|
|
13269
13299
|
},
|
|
13270
13300
|
},
|
|
13271
13301
|
};
|
|
13272
|
-
function DaimoPayButtonInner(
|
|
13302
|
+
function DaimoPayButtonInner() {
|
|
13273
13303
|
const { order } = useDaimoPay();
|
|
13274
13304
|
const label = order?.metadata?.intent ?? "Pay";
|
|
13275
13305
|
return (jsx(AnimatePresence, { initial: false, children: jsx(TextContainer, { initial: "initial", animate: "animate", exit: "exit", variants: contentVariants, style: {
|
|
@@ -13560,5 +13590,120 @@ const wallets = Object.keys(walletConfigs).reduce((acc, key) => {
|
|
|
13560
13590
|
return acc;
|
|
13561
13591
|
}, {});
|
|
13562
13592
|
|
|
13563
|
-
|
|
13593
|
+
/**
|
|
13594
|
+
* Open Worldcoin's payment drawer and prompt the user to pay a Daimo Pay order.
|
|
13595
|
+
*/
|
|
13596
|
+
async function promptWorldcoinPayment(order, trpc) {
|
|
13597
|
+
try {
|
|
13598
|
+
// Dynamically import @worldcoin/minikit-js to avoid bundling it for
|
|
13599
|
+
// developers who don't use World Mini App features, as it's an optional
|
|
13600
|
+
// peer dependency.
|
|
13601
|
+
const { MiniKit, Tokens } = await import(
|
|
13602
|
+
/* webpackIgnore: true */ '@worldcoin/minikit-js');
|
|
13603
|
+
if (!MiniKit.isInstalled()) {
|
|
13604
|
+
console.error("[WORLD] MiniKit is not installed. Please install @worldcoin/minikit-js to use this feature.");
|
|
13605
|
+
return null;
|
|
13606
|
+
}
|
|
13607
|
+
const paymentOptions = (await trpc.getTokenPaymentOptions.query({
|
|
13608
|
+
orderId: order.id,
|
|
13609
|
+
tokens: [
|
|
13610
|
+
{
|
|
13611
|
+
chainId: worldchainWLD.chainId,
|
|
13612
|
+
token: worldchainWLD.token,
|
|
13613
|
+
},
|
|
13614
|
+
{
|
|
13615
|
+
chainId: worldchainUSDCe.chainId,
|
|
13616
|
+
token: worldchainUSDCe.token,
|
|
13617
|
+
},
|
|
13618
|
+
],
|
|
13619
|
+
}));
|
|
13620
|
+
const wld = paymentOptions.find((opt) => getAddress(opt.token.token) === getAddress(worldchainWLD.token));
|
|
13621
|
+
const usdc = paymentOptions.find((opt) => getAddress(opt.token.token) === getAddress(worldchainUSDCe.token));
|
|
13622
|
+
assert(wld != null, "WLD DP token not found");
|
|
13623
|
+
assert(usdc != null, "USDCe DP token not found");
|
|
13624
|
+
const paymentId = crypto.randomUUID().replace(/-/g, "");
|
|
13625
|
+
const payload = {
|
|
13626
|
+
reference: paymentId,
|
|
13627
|
+
to: order.intentAddr,
|
|
13628
|
+
tokens: [
|
|
13629
|
+
{
|
|
13630
|
+
symbol: Tokens.WLD,
|
|
13631
|
+
token_amount: wld.amount,
|
|
13632
|
+
},
|
|
13633
|
+
{
|
|
13634
|
+
symbol: Tokens.USDCE,
|
|
13635
|
+
token_amount: usdc.amount,
|
|
13636
|
+
},
|
|
13637
|
+
],
|
|
13638
|
+
description: order.metadata.intent,
|
|
13639
|
+
};
|
|
13640
|
+
const { finalPayload } = await MiniKit.commandsAsync.pay(payload);
|
|
13641
|
+
return { paymentId, finalPayload };
|
|
13642
|
+
}
|
|
13643
|
+
catch (error) {
|
|
13644
|
+
console.error("[WORLD] Error sending payment", error);
|
|
13645
|
+
return null;
|
|
13646
|
+
}
|
|
13647
|
+
}
|
|
13648
|
+
|
|
13649
|
+
function WorldPayButton(props) {
|
|
13650
|
+
const { theme, mode, customTheme } = props;
|
|
13651
|
+
const context = usePayContext();
|
|
13652
|
+
return (jsx(WorldPayButtonCustom, { ...props, children: ({ show, isMiniKitReady }) => (jsx(ResetContainer, { "$useTheme": theme ?? context.theme, "$useMode": mode ?? context.mode, "$customTheme": customTheme ?? context.customTheme, children: jsx(ThemeContainer, { onClick: !props.disabled && isMiniKitReady && show, children: jsx(ThemedButton, { children: jsx(DaimoPayButtonInner, {}) }) }) })) }));
|
|
13653
|
+
}
|
|
13654
|
+
function WorldPayButtonCustom(props) {
|
|
13655
|
+
const pay = useDaimoPay();
|
|
13656
|
+
const context = usePayContext();
|
|
13657
|
+
const [isMiniKitReady, setIsMiniKitReady] = useState(false);
|
|
13658
|
+
useEffect(() => {
|
|
13659
|
+
// Dynamically import @worldcoin/minikit-js to avoid bundling it for
|
|
13660
|
+
// developers who don't use World Mini App features, as it's an optional
|
|
13661
|
+
// peer dependency.
|
|
13662
|
+
import(/* webpackIgnore: true */ '@worldcoin/minikit-js')
|
|
13663
|
+
.then(({ MiniKit }) => {
|
|
13664
|
+
if (MiniKit.isInstalled()) {
|
|
13665
|
+
setIsMiniKitReady(true);
|
|
13666
|
+
}
|
|
13667
|
+
else {
|
|
13668
|
+
setIsMiniKitReady(false);
|
|
13669
|
+
}
|
|
13670
|
+
})
|
|
13671
|
+
.catch(() => {
|
|
13672
|
+
setIsMiniKitReady(false);
|
|
13673
|
+
});
|
|
13674
|
+
}, []);
|
|
13675
|
+
useEffect(() => {
|
|
13676
|
+
pay.createPreviewOrder(props);
|
|
13677
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
13678
|
+
}, [pay, JSON.stringify(props)]);
|
|
13679
|
+
const showSpinner = useCallback(() => {
|
|
13680
|
+
context.showPayment({});
|
|
13681
|
+
context.setRoute(ROUTES.CONFIRMATION);
|
|
13682
|
+
}, [context]);
|
|
13683
|
+
const show = useCallback(async () => {
|
|
13684
|
+
if (!isMiniKitReady) {
|
|
13685
|
+
console.error("[WORLD] MiniKit is not installed. Please install @worldcoin/minikit-js to use this feature.");
|
|
13686
|
+
return;
|
|
13687
|
+
}
|
|
13688
|
+
if (["payment_started", "payment_completed", "payment_bounced"].includes(pay.paymentState)) {
|
|
13689
|
+
showSpinner();
|
|
13690
|
+
return;
|
|
13691
|
+
}
|
|
13692
|
+
const { order } = await pay.hydrateOrder();
|
|
13693
|
+
const payRes = await promptWorldcoinPayment(order, context.trpc);
|
|
13694
|
+
if (payRes == null || payRes.finalPayload.status == "error") {
|
|
13695
|
+
console.error("[WORLD] Failed to prompt Worldcoin payment: ", payRes);
|
|
13696
|
+
return;
|
|
13697
|
+
}
|
|
13698
|
+
pay.paySource();
|
|
13699
|
+
// Optimistically assume the source payment is correct and show the
|
|
13700
|
+
// confirmation spinner
|
|
13701
|
+
showSpinner();
|
|
13702
|
+
}, [pay, showSpinner, context.trpc, isMiniKitReady]);
|
|
13703
|
+
return props.children({ show, isMiniKitReady });
|
|
13704
|
+
}
|
|
13705
|
+
WorldPayButton.displayName = "WorldPayButton";
|
|
13706
|
+
WorldPayButton.Custom = WorldPayButtonCustom;
|
|
13707
|
+
|
|
13708
|
+
export { Avatar, Chain as ChainIcon, DaimoPayButton, PayContext as DaimoPayContext, DaimoPayProvider, WorldPayButton, daimoPayVersion, defaultConfig as getDefaultConfig, useDaimoPay, useDaimoPayStatus, useDaimoPayUI, usePayContext, version, wallets };
|
|
13564
13709
|
//# sourceMappingURL=index.js.map
|