@b3dotfun/sdk 0.0.4-alpha.2 → 0.0.5-alpha.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/dist/cjs/anyspend/index.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +2 -2
- package/dist/cjs/anyspend/react/components/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/index.js +3 -1
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampOrderStatus.js +37 -0
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +3 -2
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +141 -61
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +4 -3
- package/dist/cjs/anyspend/services/anyspend.d.ts +2 -1
- package/dist/cjs/anyspend/services/anyspend.js +3 -2
- package/dist/cjs/global-account/react/hooks/useTokenFromUrl.d.ts +4 -0
- package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +23 -0
- package/dist/cjs/shared/constants/chains/supported.d.ts +2 -6
- package/dist/cjs/shared/constants/chains/supported.js +6 -3
- package/dist/esm/anyspend/index.js +13 -14
- package/dist/esm/anyspend/index.native.js +13 -13
- package/dist/esm/anyspend/react/components/AnySpend.js +15 -15
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +8 -8
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +14 -14
- package/dist/esm/anyspend/react/components/AnySpendNFT.js +7 -7
- package/dist/esm/anyspend/react/components/AnySpendNFTButton.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +7 -7
- package/dist/esm/anyspend/react/components/AnySpendTournament.js +4 -4
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -6
- package/dist/esm/anyspend/react/components/common/OrderHistory.js +3 -3
- package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +4 -4
- package/dist/esm/anyspend/react/components/common/OrderStatus.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderToken.js +6 -6
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +4 -4
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +3 -3
- package/dist/esm/anyspend/react/components/common/PanelOnrampPayment.js +3 -3
- package/dist/esm/anyspend/react/components/common/PaymentMethodIcons.js +1 -1
- package/dist/esm/anyspend/react/components/common/PaymentOneClick.js +3 -3
- package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +6 -6
- package/dist/esm/anyspend/react/components/common/PaymentVendorUI.js +3 -3
- package/dist/esm/anyspend/react/components/common/TokenBalance.js +1 -1
- package/dist/esm/anyspend/react/components/index.d.ts +1 -0
- package/dist/esm/anyspend/react/components/index.js +16 -15
- package/dist/esm/anyspend/react/components/modals/EnterRecipientModal.js +1 -1
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +6 -0
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampOrderStatus.js +31 -0
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +3 -2
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +140 -60
- package/dist/esm/anyspend/react/hooks/index.js +13 -13
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +6 -5
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +2 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.js +1 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.js +1 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendQuote.js +2 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendSendPermitData.js +1 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendTokens.js +1 -1
- package/dist/esm/anyspend/react/hooks/useCoinbaseOnrampOptions.js +1 -1
- package/dist/esm/anyspend/react/hooks/useGeoOnrampOptions.js +3 -3
- package/dist/esm/anyspend/react/hooks/usePermitData.js +2 -2
- package/dist/esm/anyspend/react/hooks/useStripeClientSecret.js +1 -1
- package/dist/esm/anyspend/react/hooks/useStripeSupport.js +1 -1
- package/dist/esm/anyspend/react/index.js +3 -3
- package/dist/esm/anyspend/services/anyspend.d.ts +2 -1
- package/dist/esm/anyspend/services/anyspend.js +6 -5
- package/dist/esm/anyspend/types/custom.js +1 -1
- package/dist/esm/anyspend/types/index.js +13 -13
- package/dist/esm/anyspend/types/nft.js +1 -1
- package/dist/esm/anyspend/types/order.js +6 -6
- package/dist/esm/anyspend/types/req-res/createOrder.js +6 -6
- package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.js +2 -2
- package/dist/esm/anyspend/types/req-res/getOrderHistory.js +1 -1
- package/dist/esm/anyspend/types/req-res/getQuote.js +3 -3
- package/dist/esm/anyspend/types/req-res/index.js +8 -8
- package/dist/esm/anyspend/types/req-res/sendPermitData.js +1 -1
- package/dist/esm/anyspend/types/swap.js +1 -1
- package/dist/esm/anyspend/types/tournament.js +1 -1
- package/dist/esm/anyspend/types/transaction.js +1 -1
- package/dist/esm/anyspend/utils/chain.js +3 -3
- package/dist/esm/anyspend/utils/format.js +1 -1
- package/dist/esm/anyspend/utils/index.js +8 -8
- package/dist/esm/anyspend/utils/orderPayload.js +2 -2
- package/dist/esm/anyspend/utils/token.js +1 -1
- package/dist/esm/global-account/app.js +1 -1
- package/dist/esm/global-account/index.js +1 -1
- package/dist/esm/global-account/index.native.js +1 -1
- package/dist/esm/global-account/react/components/B3DynamicModal.js +10 -10
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +4 -4
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +1 -1
- package/dist/esm/global-account/react/components/B3Provider/useB3.js +1 -1
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +4 -4
- package/dist/esm/global-account/react/components/MintButton/MintButton.js +2 -2
- package/dist/esm/global-account/react/components/ProfileAvatar.js +1 -1
- package/dist/esm/global-account/react/components/RequestPermissions/RequestPermissions.js +4 -4
- package/dist/esm/global-account/react/components/RequestPermissions/RequestPermissionsButton.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +5 -5
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/components/AuthButton.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/components/PermissionItem.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/components/WalletRow.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +3 -3
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -2
- package/dist/esm/global-account/react/components/StyleRoot.js +1 -1
- package/dist/esm/global-account/react/components/Transak/TransakModal.js +2 -2
- package/dist/esm/global-account/react/components/custom/Button.js +1 -1
- package/dist/esm/global-account/react/components/custom/ClientOnly.js +1 -1
- package/dist/esm/global-account/react/components/index.js +45 -45
- package/dist/esm/global-account/react/components/ui/Loading.js +1 -1
- package/dist/esm/global-account/react/components/ui/ShinyButton.js +3 -3
- package/dist/esm/global-account/react/components/ui/TabSystem.js +2 -2
- package/dist/esm/global-account/react/components/ui/Tabs.js +1 -1
- package/dist/esm/global-account/react/components/ui/badge.js +1 -1
- package/dist/esm/global-account/react/components/ui/button.js +1 -1
- package/dist/esm/global-account/react/components/ui/command.js +2 -2
- package/dist/esm/global-account/react/components/ui/dialog.js +1 -1
- package/dist/esm/global-account/react/components/ui/drawer.js +1 -1
- package/dist/esm/global-account/react/components/ui/glare-card-rounded.js +1 -1
- package/dist/esm/global-account/react/components/ui/glare-card.js +1 -1
- package/dist/esm/global-account/react/components/ui/input.js +1 -1
- package/dist/esm/global-account/react/components/ui/popover.js +2 -2
- package/dist/esm/global-account/react/components/ui/scroll-area.js +1 -1
- package/dist/esm/global-account/react/components/ui/skeleton.js +1 -1
- package/dist/esm/global-account/react/components/ui/text-loop.js +1 -1
- package/dist/esm/global-account/react/components/ui/text-shimmer.js +1 -1
- package/dist/esm/global-account/react/components/ui/tooltip.js +1 -1
- package/dist/esm/global-account/react/components/ui/transition-panel.js +1 -1
- package/dist/esm/global-account/react/hooks/index.js +35 -35
- package/dist/esm/global-account/react/hooks/useAccountAssets.js +1 -1
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +3 -3
- package/dist/esm/global-account/react/hooks/useAddTWSessionKey.js +1 -1
- package/dist/esm/global-account/react/hooks/useAuthentication.js +8 -8
- package/dist/esm/global-account/react/hooks/useB3BalanceFromAddresses.js +2 -2
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +2 -2
- package/dist/esm/global-account/react/hooks/useBsmntProfile.js +1 -1
- package/dist/esm/global-account/react/hooks/useChainSwitchWithAction.js +2 -2
- package/dist/esm/global-account/react/hooks/useClaim.js +1 -1
- package/dist/esm/global-account/react/hooks/useConnect.js +3 -3
- package/dist/esm/global-account/react/hooks/useGetAllTWSigners.js +1 -1
- package/dist/esm/global-account/react/hooks/useGetGeo.js +1 -1
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -2
- package/dist/esm/global-account/react/hooks/useIsMobile.js +1 -1
- package/dist/esm/global-account/react/hooks/useMediaQuery.js +1 -1
- package/dist/esm/global-account/react/hooks/useNativeBalance.js +2 -2
- package/dist/esm/global-account/react/hooks/useOnchainName.js +2 -2
- package/dist/esm/global-account/react/hooks/useOneBalance.js +2 -2
- package/dist/esm/global-account/react/hooks/useQueryB3.js +1 -1
- package/dist/esm/global-account/react/hooks/useQueryBSMNT.js +1 -1
- package/dist/esm/global-account/react/hooks/useRemoveSessionKey.js +1 -1
- package/dist/esm/global-account/react/hooks/useSiwe.js +2 -2
- package/dist/esm/global-account/react/hooks/useTokenBalance.js +4 -4
- package/dist/esm/global-account/react/hooks/useTokenBalancesByChain.js +4 -4
- package/dist/esm/global-account/react/hooks/useTokenFromUrl.d.ts +4 -0
- package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +23 -1
- package/dist/esm/global-account/react/hooks/useTokenPrice.js +1 -1
- package/dist/esm/global-account/react/hooks/useTokenPriceWithFallback.js +2 -2
- package/dist/esm/global-account/react/hooks/useTokensFromAddress.js +1 -1
- package/dist/esm/global-account/react/hooks/useURLParams.js +1 -1
- package/dist/esm/global-account/react/index.js +3 -3
- package/dist/esm/global-account/react/index.native.js +10 -10
- package/dist/esm/global-account/react/stores/index.js +2 -2
- package/dist/esm/shared/constants/chains/supported.d.ts +2 -6
- package/dist/esm/shared/constants/chains/supported.js +6 -3
- package/dist/esm/shared/thirdweb/generated/@tanstack/react-query.gen.js +2 -2
- package/dist/esm/shared/thirdweb/generated/index.js +2 -2
- package/dist/esm/shared/thirdweb/generated/sdk.gen.js +1 -1
- package/dist/esm/shared/thirdweb/initiateClient.js +2 -2
- package/dist/esm/shared/utils/chains.js +1 -1
- package/dist/esm/shared/utils/fetchBalances.js +2 -2
- package/dist/esm/shared/utils/index.js +1 -1
- package/dist/esm/shared/utils/insights.js +1 -1
- package/dist/esm/shared/utils/payment.utils.js +2 -2
- package/dist/esm/shared/utils/simplehash.js +4 -4
- package/dist/esm/shared/utils/thirdweb-insights.js +2 -2
- package/dist/esm/shared/utils/thirdweb.js +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/index.d.ts +1 -0
- package/dist/types/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +6 -0
- package/dist/types/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +3 -2
- package/dist/types/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +1 -0
- package/dist/types/anyspend/services/anyspend.d.ts +2 -1
- package/dist/types/global-account/react/hooks/useTokenFromUrl.d.ts +4 -0
- package/dist/types/shared/constants/chains/supported.d.ts +2 -6
- package/package.json +2 -2
- package/src/anyspend/index.ts +0 -2
- package/src/anyspend/react/components/AnySpend.tsx +2 -2
- package/src/anyspend/react/components/index.ts +1 -0
- package/src/anyspend/react/components/webview/WebviewOnrampOrderStatus.tsx +120 -0
- package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +294 -132
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +7 -4
- package/src/anyspend/services/anyspend.ts +5 -2
- package/src/global-account/react/hooks/useTokenFromUrl.tsx +25 -1
- package/src/shared/constants/chains/supported.ts +8 -4
|
@@ -103,7 +103,7 @@ function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet
|
|
|
103
103
|
name: srcTokenMetadata.name || selectedSrcToken.name,
|
|
104
104
|
metadata: {
|
|
105
105
|
...selectedSrcToken.metadata,
|
|
106
|
-
logoURI: srcTokenMetadata
|
|
106
|
+
logoURI: srcTokenMetadata?.logoURI || selectedSrcToken.metadata.logoURI
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
setSelectedSrcToken(enhancedToken);
|
|
@@ -125,7 +125,7 @@ function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet
|
|
|
125
125
|
name: dstTokenMetadata.name || selectedDstToken.name,
|
|
126
126
|
metadata: {
|
|
127
127
|
...selectedDstToken.metadata,
|
|
128
|
-
logoURI: dstTokenMetadata
|
|
128
|
+
logoURI: dstTokenMetadata?.logoURI || selectedDstToken.metadata.logoURI
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
setSelectedDstToken(enhancedToken);
|
|
@@ -12,4 +12,5 @@ export { OrderStatus } from "./common/OrderStatus";
|
|
|
12
12
|
export { OrderToken } from "./common/OrderToken";
|
|
13
13
|
export { OrderTokenAmount } from "./common/OrderTokenAmount";
|
|
14
14
|
export { TokenBalance } from "./common/TokenBalance";
|
|
15
|
+
export { WebviewOnrampOrderStatus } from "./webview/WebviewOnrampOrderStatus";
|
|
15
16
|
export { WebviewOnrampPayment } from "./webview/WebviewOnrampPayment";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebviewOnrampPayment = exports.TokenBalance = exports.OrderTokenAmount = exports.OrderToken = exports.OrderStatus = exports.OrderHistoryItem = exports.OrderHistory = exports.OrderDetails = exports.AnySpendTournament = exports.AnySpendStakeB3 = exports.AnySpendNFTButton = exports.AnySpendNFT = exports.AnySpendCustom = exports.AnySpendBuySpin = exports.AnySpend = void 0;
|
|
3
|
+
exports.WebviewOnrampPayment = exports.WebviewOnrampOrderStatus = exports.TokenBalance = exports.OrderTokenAmount = exports.OrderToken = exports.OrderStatus = exports.OrderHistoryItem = exports.OrderHistory = exports.OrderDetails = exports.AnySpendTournament = exports.AnySpendStakeB3 = exports.AnySpendNFTButton = exports.AnySpendNFT = exports.AnySpendCustom = exports.AnySpendBuySpin = exports.AnySpend = void 0;
|
|
4
4
|
// Components
|
|
5
5
|
var AnySpend_1 = require("./AnySpend");
|
|
6
6
|
Object.defineProperty(exports, "AnySpend", { enumerable: true, get: function () { return AnySpend_1.AnySpend; } });
|
|
@@ -31,5 +31,7 @@ var OrderTokenAmount_1 = require("./common/OrderTokenAmount");
|
|
|
31
31
|
Object.defineProperty(exports, "OrderTokenAmount", { enumerable: true, get: function () { return OrderTokenAmount_1.OrderTokenAmount; } });
|
|
32
32
|
var TokenBalance_1 = require("./common/TokenBalance");
|
|
33
33
|
Object.defineProperty(exports, "TokenBalance", { enumerable: true, get: function () { return TokenBalance_1.TokenBalance; } });
|
|
34
|
+
var WebviewOnrampOrderStatus_1 = require("./webview/WebviewOnrampOrderStatus");
|
|
35
|
+
Object.defineProperty(exports, "WebviewOnrampOrderStatus", { enumerable: true, get: function () { return WebviewOnrampOrderStatus_1.WebviewOnrampOrderStatus; } });
|
|
34
36
|
var WebviewOnrampPayment_1 = require("./webview/WebviewOnrampPayment");
|
|
35
37
|
Object.defineProperty(exports, "WebviewOnrampPayment", { enumerable: true, get: function () { return WebviewOnrampPayment_1.WebviewOnrampPayment; } });
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebviewOnrampOrderStatus = WebviewOnrampOrderStatus;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const anyspend_1 = require("../../../../anyspend");
|
|
9
|
+
const react_1 = require("../../../../global-account/react");
|
|
10
|
+
const centerTruncate_1 = __importDefault(require("../../../../shared/utils/centerTruncate"));
|
|
11
|
+
const lucide_react_1 = require("lucide-react");
|
|
12
|
+
const sonner_1 = require("sonner");
|
|
13
|
+
const viem_1 = require("viem");
|
|
14
|
+
function WebviewOnrampOrderStatus({ order }) {
|
|
15
|
+
console.log(order.status);
|
|
16
|
+
const isPending = order.status === anyspend_1.OrderStatus.WaitingStripePayment ||
|
|
17
|
+
order.status === anyspend_1.OrderStatus.ScanningDepositTransaction ||
|
|
18
|
+
order.status === anyspend_1.OrderStatus.SendingTokenFromVault ||
|
|
19
|
+
order.status === anyspend_1.OrderStatus.ObtainToken ||
|
|
20
|
+
order.status === anyspend_1.OrderStatus.Relay;
|
|
21
|
+
const isExecuted = order.status === anyspend_1.OrderStatus.Executed;
|
|
22
|
+
const isFailed = order.status === anyspend_1.OrderStatus.Failure;
|
|
23
|
+
const isRefunded = order.status === anyspend_1.OrderStatus.Refunded;
|
|
24
|
+
// Get token metadata
|
|
25
|
+
const { data: tokenMetadata } = (0, react_1.useTokenData)(order.metadata.dstToken.chainId, order.metadata.dstToken.address);
|
|
26
|
+
// Only show expected amount for swap orders
|
|
27
|
+
const expectedAmount = order.type === anyspend_1.OrderType.Swap
|
|
28
|
+
? Number((0, viem_1.formatUnits)(BigInt(order.payload.expectedDstAmount), order.metadata.dstToken.decimals)).toFixed(2)
|
|
29
|
+
: null;
|
|
30
|
+
// Use token metadata logo if available
|
|
31
|
+
const tokenLogoUrl = tokenMetadata?.logoURI || order.metadata.dstToken.metadata?.logoURI;
|
|
32
|
+
const handleCopy = (text, label) => {
|
|
33
|
+
navigator.clipboard.writeText(text);
|
|
34
|
+
sonner_1.toast.success(`${label} copied to clipboard`);
|
|
35
|
+
};
|
|
36
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-full max-w-[460px] flex-col gap-6", children: [(0, jsx_runtime_1.jsx)("div", { className: "flex justify-center", children: (0, jsx_runtime_1.jsxs)(react_1.Badge, { variant: "default", className: "flex items-center gap-3 px-4 py-2 text-base", children: [isPending && (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-4 w-4 animate-spin" }), isExecuted && (0, jsx_runtime_1.jsx)(lucide_react_1.CheckIcon, { className: "h-4 w-4 text-green-500" }), isFailed && (0, jsx_runtime_1.jsx)(lucide_react_1.ExternalLink, { className: "h-4 w-4 text-red-500" }), (0, jsx_runtime_1.jsxs)("span", { children: [isPending && "Processing Payment...", isExecuted && "Payment Complete", isFailed && "Payment Failed", isRefunded && "Payment Refunded"] })] }) }), (0, jsx_runtime_1.jsx)("div", { className: "overflow-hidden rounded-xl bg-white", children: (0, jsx_runtime_1.jsxs)("div", { className: "px-6 py-4", children: [(0, jsx_runtime_1.jsx)("h2", { className: "mb-4 text-lg font-semibold", children: "Order Summary" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col divide-y", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Amount Paid" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-lg font-semibold", children: ["$", Number((0, viem_1.formatUnits)(BigInt(order.srcAmount), order.metadata.srcToken.decimals)).toFixed(2)] })] }), order.type === anyspend_1.OrderType.Swap && expectedAmount && ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Est Token Amount" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [tokenLogoUrl && ((0, jsx_runtime_1.jsx)("img", { src: tokenLogoUrl, alt: order.metadata.dstToken.symbol, className: "h-5 w-5 rounded-full" })), (0, jsx_runtime_1.jsxs)("span", { className: "font-medium", children: [expectedAmount, " ", order.metadata.dstToken.symbol] })] })] })), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Network" }), (0, jsx_runtime_1.jsx)("span", { className: "font-medium", children: (0, anyspend_1.getChainName)(order.dstChain) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Recipient" }), (0, jsx_runtime_1.jsxs)("button", { onClick: () => handleCopy(order.recipientAddress, "Recipient address"), className: "flex items-center gap-2 font-medium transition-colors hover:text-blue-600", children: [(0, centerTruncate_1.default)(order.recipientAddress, 8), (0, jsx_runtime_1.jsx)(lucide_react_1.Copy, { className: "h-4 w-4" })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Order ID" }), (0, jsx_runtime_1.jsxs)("button", { onClick: () => handleCopy(order.id, "Order ID"), className: "flex items-center gap-2 font-medium transition-colors hover:text-blue-600", children: [(0, centerTruncate_1.default)(order.id, 8), (0, jsx_runtime_1.jsx)(lucide_react_1.Copy, { className: "h-4 w-4" })] })] })] })] }) })] }));
|
|
37
|
+
}
|
|
@@ -3,9 +3,10 @@ interface WebviewOnrampPaymentProps {
|
|
|
3
3
|
srcAmountOnRamp: string;
|
|
4
4
|
recipientAddress?: string;
|
|
5
5
|
destinationToken: Token;
|
|
6
|
+
partnerId?: string;
|
|
6
7
|
anyspendQuote: GetQuoteResponse | undefined;
|
|
7
|
-
|
|
8
|
+
onPaymentSuccess: (orderId: string) => void;
|
|
8
9
|
userId?: string;
|
|
9
10
|
}
|
|
10
|
-
export declare function WebviewOnrampPayment({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote,
|
|
11
|
+
export declare function WebviewOnrampPayment({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote, onPaymentSuccess, userId, partnerId }: WebviewOnrampPaymentProps): import("react/jsx-runtime").JSX.Element;
|
|
11
12
|
export {};
|
|
@@ -6,88 +6,168 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.WebviewOnrampPayment = WebviewOnrampPayment;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
const anyspend_1 = require("../../../../anyspend");
|
|
9
|
-
const react_1 = require("../../../../global-account/react");
|
|
10
9
|
const centerTruncate_1 = __importDefault(require("../../../../shared/utils/centerTruncate"));
|
|
10
|
+
const react_stripe_js_1 = require("@stripe/react-stripe-js");
|
|
11
|
+
const stripe_js_1 = require("@stripe/stripe-js");
|
|
11
12
|
const framer_motion_1 = require("framer-motion");
|
|
12
13
|
const lucide_react_1 = require("lucide-react");
|
|
13
|
-
const
|
|
14
|
+
const react_1 = require("react");
|
|
14
15
|
const sonner_1 = require("sonner");
|
|
15
16
|
const viem_1 = require("viem");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
17
|
+
const stripePromise = (0, stripe_js_1.loadStripe)(anyspend_1.STRIPE_CONFIG.publishableKey);
|
|
18
|
+
// Stripe Payment Form Component
|
|
19
|
+
function StripePaymentForm({ order, onPaymentSuccess }) {
|
|
20
|
+
const stripe = (0, react_stripe_js_1.useStripe)();
|
|
21
|
+
const elements = (0, react_stripe_js_1.useElements)();
|
|
22
|
+
const [isProcessing, setIsProcessing] = (0, react_1.useState)(false);
|
|
23
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
24
|
+
const handleSubmit = async (e) => {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
if (!stripe || !elements) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
setIsProcessing(true);
|
|
30
|
+
setError(null);
|
|
31
|
+
try {
|
|
32
|
+
const { error: submitError } = await stripe.confirmPayment({
|
|
33
|
+
elements,
|
|
34
|
+
redirect: "if_required"
|
|
35
|
+
});
|
|
36
|
+
if (submitError) {
|
|
37
|
+
setError(submitError.message || "An error occurred");
|
|
38
|
+
console.error("Payment error:", submitError);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.log("Payment successful");
|
|
42
|
+
onPaymentSuccess(order.id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
setError(err.message || "An error occurred");
|
|
47
|
+
console.error("Payment error:", err);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
setIsProcessing(false);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const stripeElementOptions = {
|
|
54
|
+
layout: "tabs",
|
|
55
|
+
defaultValues: {
|
|
56
|
+
billingDetails: {
|
|
57
|
+
name: "",
|
|
58
|
+
email: ""
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return ((0, jsx_runtime_1.jsx)("form", { onSubmit: handleSubmit, className: "w-full", children: (0, jsx_runtime_1.jsx)("div", { className: "overflow-hidden rounded-xl bg-white", children: (0, jsx_runtime_1.jsxs)("div", { className: "px-6 py-4", children: [(0, jsx_runtime_1.jsx)("h2", { className: "mb-4 text-lg font-semibold", children: "Payment Details" }), (0, jsx_runtime_1.jsx)(react_stripe_js_1.PaymentElement, { options: stripeElementOptions }), error && ((0, jsx_runtime_1.jsx)("div", { className: "mt-4 rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-600", children: error })), (0, jsx_runtime_1.jsx)("button", { type: "submit", disabled: !stripe || isProcessing, className: "mt-6 w-full rounded-xl bg-blue-600 px-4 py-3 font-medium text-white hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50", children: isProcessing ? ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-5 w-5 animate-spin" }), (0, jsx_runtime_1.jsx)("span", { children: "Processing..." })] })) : ((0, jsx_runtime_1.jsx)("span", { children: "Complete Payment" })) })] }) }) }));
|
|
63
|
+
}
|
|
64
|
+
function WebviewOnrampPayment({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote, onPaymentSuccess, userId, partnerId }) {
|
|
65
|
+
const [stableAmountForGeo, setStableAmountForGeo] = (0, react_1.useState)(srcAmountOnRamp);
|
|
66
|
+
const hasInitialized = (0, react_1.useRef)(false);
|
|
67
|
+
const [createdOrder, setCreatedOrder] = (0, react_1.useState)(null);
|
|
68
|
+
const orderCreationAttempted = (0, react_1.useRef)(false);
|
|
20
69
|
// Only update the stable amount on first render or when explicitly needed
|
|
21
|
-
(0,
|
|
70
|
+
(0, react_1.useEffect)(() => {
|
|
22
71
|
if (!hasInitialized.current && srcAmountOnRamp) {
|
|
23
72
|
setStableAmountForGeo(srcAmountOnRamp);
|
|
24
73
|
hasInitialized.current = true;
|
|
25
74
|
}
|
|
26
75
|
}, [srcAmountOnRamp]);
|
|
27
76
|
const { geoData, isStripeWeb2Supported, isLoading: isLoadingGeoOnramp } = (0, anyspend_1.useGeoOnrampOptions)(true, stableAmountForGeo);
|
|
28
|
-
console.log("isStripeWeb2Supported", isStripeWeb2Supported);
|
|
29
77
|
const { createOrder, isCreatingOrder } = (0, anyspend_1.useAnyspendCreateOnrampOrder)({
|
|
30
78
|
onSuccess: data => {
|
|
31
79
|
const orderId = data.data.id;
|
|
32
|
-
|
|
80
|
+
setCreatedOrder(data.data);
|
|
33
81
|
},
|
|
34
82
|
onError: error => {
|
|
35
83
|
console.error(error);
|
|
36
84
|
sonner_1.toast.error("Failed to create order: " + error.message);
|
|
37
85
|
}
|
|
38
86
|
});
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
87
|
+
const { clientSecret, isLoadingStripeClientSecret } = (0, anyspend_1.useStripeClientSecret)(true, createdOrder?.stripePaymentIntentId || "");
|
|
88
|
+
// Create order when component mounts and all required data is available
|
|
89
|
+
(0, react_1.useEffect)(() => {
|
|
90
|
+
const createOrderIfPossible = async () => {
|
|
91
|
+
if (!orderCreationAttempted.current &&
|
|
92
|
+
recipientAddress &&
|
|
93
|
+
srcAmountOnRamp &&
|
|
94
|
+
parseFloat(srcAmountOnRamp) > 0 &&
|
|
95
|
+
isStripeWeb2Supported &&
|
|
96
|
+
anyspendQuote &&
|
|
97
|
+
geoData) {
|
|
98
|
+
orderCreationAttempted.current = true;
|
|
99
|
+
try {
|
|
100
|
+
const getDstToken = () => {
|
|
101
|
+
return {
|
|
102
|
+
...destinationToken,
|
|
103
|
+
chainId: destinationToken.chainId,
|
|
104
|
+
address: destinationToken.address
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
createOrder({
|
|
108
|
+
isMainnet: true,
|
|
109
|
+
recipientAddress,
|
|
110
|
+
orderType: anyspend_1.OrderType.Swap,
|
|
111
|
+
dstChain: getDstToken().chainId,
|
|
112
|
+
dstToken: getDstToken(),
|
|
113
|
+
srcFiatAmount: srcAmountOnRamp,
|
|
114
|
+
onramp: {
|
|
115
|
+
vendor: anyspend_1.OnrampVendor.StripeWeb2,
|
|
116
|
+
paymentMethod: "",
|
|
117
|
+
country: geoData.country || "US",
|
|
118
|
+
ipAddress: geoData.ip,
|
|
119
|
+
redirectUrl: `${window.location.origin}${userId ? `?userId=${userId}` : ""}`
|
|
120
|
+
},
|
|
121
|
+
expectedDstAmount: anyspendQuote.data?.currencyOut?.amount?.toString() || "0",
|
|
122
|
+
partnerId
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
console.error(err);
|
|
127
|
+
sonner_1.toast.error("Failed to create order: " + err.message);
|
|
128
|
+
}
|
|
56
129
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
130
|
+
};
|
|
131
|
+
createOrderIfPossible();
|
|
132
|
+
}, [
|
|
133
|
+
recipientAddress,
|
|
134
|
+
srcAmountOnRamp,
|
|
135
|
+
isStripeWeb2Supported,
|
|
136
|
+
anyspendQuote,
|
|
137
|
+
geoData,
|
|
138
|
+
createOrder,
|
|
139
|
+
destinationToken,
|
|
140
|
+
userId,
|
|
141
|
+
partnerId
|
|
142
|
+
]);
|
|
143
|
+
// Check if all required data is loaded
|
|
144
|
+
const isLoading = isLoadingGeoOnramp || !anyspendQuote || !destinationToken.metadata?.logoURI;
|
|
145
|
+
// Show loading state while data is being fetched or order is being created
|
|
146
|
+
if (isLoading || isCreatingOrder || isLoadingStripeClientSecret) {
|
|
147
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-full max-w-[460px] flex-col items-center justify-center gap-3 py-12", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "text-as-brand h-8 w-8 animate-spin" }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70", children: isCreatingOrder
|
|
148
|
+
? "Creating payment session..."
|
|
149
|
+
: isLoadingStripeClientSecret
|
|
150
|
+
? "Loading payment form..."
|
|
151
|
+
: "Loading payment details..." })] }));
|
|
152
|
+
}
|
|
153
|
+
// If we have a created order and client secret, show the payment form
|
|
154
|
+
if (createdOrder && clientSecret) {
|
|
155
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-full max-w-[460px] flex-col gap-6", children: [(0, jsx_runtime_1.jsx)("div", { className: "overflow-hidden rounded-xl bg-white", children: (0, jsx_runtime_1.jsxs)("div", { className: "px-6 py-4", children: [(0, jsx_runtime_1.jsx)("h2", { className: "mb-4 text-lg font-semibold", children: "Order summary" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col divide-y", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Receiving" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [destinationToken.metadata?.logoURI && ((0, jsx_runtime_1.jsx)("img", { src: destinationToken.metadata.logoURI, alt: destinationToken.symbol, className: "h-5 w-5 rounded-full" })), (0, jsx_runtime_1.jsxs)("span", { className: "font-medium", children: [anyspendQuote?.data?.currencyOut?.amount
|
|
156
|
+
? Number((0, viem_1.formatUnits)(BigInt(anyspendQuote.data.currencyOut.amount), destinationToken.decimals)).toFixed(4)
|
|
157
|
+
: "0", " ", destinationToken.symbol] })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Network" }), (0, jsx_runtime_1.jsx)("span", { className: "font-medium", children: (0, anyspend_1.getChainName)(destinationToken.chainId) })] }), recipientAddress && ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Recipient" }), (0, jsx_runtime_1.jsx)("span", { className: "font-medium", children: (0, centerTruncate_1.default)(recipientAddress) })] })), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "You Pay" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-lg font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] })] })] }) }), (0, jsx_runtime_1.jsx)(react_stripe_js_1.Elements, { stripe: stripePromise, options: {
|
|
158
|
+
clientSecret,
|
|
159
|
+
appearance: {
|
|
160
|
+
theme: "flat",
|
|
161
|
+
variables: {
|
|
162
|
+
colorPrimary: "#2563eb",
|
|
163
|
+
colorBackground: "#ffffff",
|
|
164
|
+
borderRadius: "12px"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, children: (0, jsx_runtime_1.jsx)(StripePaymentForm, { order: createdOrder, onPaymentSuccess: onPaymentSuccess }) })] }));
|
|
168
|
+
}
|
|
169
|
+
// Show initial order summary while waiting for order creation
|
|
170
|
+
return ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { initial: { opacity: 0, y: 20 }, animate: { opacity: 1, y: 0 }, transition: { duration: 0.3 }, className: "mx-auto w-full max-w-[460px]", children: (0, jsx_runtime_1.jsx)("div", { className: "overflow-hidden rounded-xl bg-white", children: (0, jsx_runtime_1.jsxs)("div", { className: "px-6 py-4", children: [(0, jsx_runtime_1.jsx)("h2", { className: "mb-4 text-lg font-semibold", children: "Order summary" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col divide-y", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Receiving" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [destinationToken.metadata?.logoURI && ((0, jsx_runtime_1.jsx)("img", { src: destinationToken.metadata.logoURI, alt: destinationToken.symbol, className: "h-5 w-5 rounded-full" })), (0, jsx_runtime_1.jsxs)("span", { className: "font-medium", children: [anyspendQuote?.data?.currencyOut?.amount
|
|
87
171
|
? Number((0, viem_1.formatUnits)(BigInt(anyspendQuote.data.currencyOut.amount), destinationToken.decimals)).toFixed(4)
|
|
88
|
-
: "0", " ", destinationToken.symbol] })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("
|
|
89
|
-
opacity: 1,
|
|
90
|
-
y: 0,
|
|
91
|
-
filter: "blur(0px)"
|
|
92
|
-
}, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-b3-react-foreground/60", children: "Recipient" }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: (0, jsx_runtime_1.jsx)("span", { className: "text-b3-react-foreground/80", children: (0, centerTruncate_1.default)(recipientAddress) }) })] })), (0, jsx_runtime_1.jsx)("div", { className: "border-b3-react-border border-t pt-3", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-b3-react-foreground font-semibold", children: "You Pay" }), (0, jsx_runtime_1.jsxs)("p", { className: "text-b3-react-foreground text-xl font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] }) })] })] }), isCreatingOrder ? ((0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background border-b3-react-border flex items-center justify-center gap-3 rounded-lg border p-6", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-4 w-4 animate-spin" }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70", children: "Creating payment session..." })] })) : isLoadingGeoOnramp ? ((0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background border-b3-react-border flex items-center justify-center gap-3 rounded-lg border p-6", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-4 w-4 animate-spin" }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70", children: "Loading payment options..." })] })) : ((0, jsx_runtime_1.jsx)("div", { className: "flex flex-col gap-4", children: (0, jsx_runtime_1.jsx)(react_1.Button, { onClick: handleContinueToPayment, disabled: isCreatingOrder || !isStripeWeb2Supported, className: "bg-as-brand hover:bg-as-brand/90 text-as-primary h-14 w-full rounded-xl text-lg font-medium", children: isCreatingOrder ? "Creating Payment..." : "Continue to Payment" }) }))] }));
|
|
172
|
+
: "0", " ", destinationToken.symbol] })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Network" }), (0, jsx_runtime_1.jsx)("span", { className: "font-medium", children: (0, anyspend_1.getChainName)(destinationToken.chainId) })] }), recipientAddress && ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "Recipient" }), (0, jsx_runtime_1.jsx)("span", { className: "font-medium", children: (0, centerTruncate_1.default)(recipientAddress) })] })), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between py-3", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-gray-600", children: "You Pay" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-lg font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] })] })] }) }) }));
|
|
93
173
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAnyspendCreateOnrampOrder = useAnyspendCreateOnrampOrder;
|
|
4
|
+
const constants_1 = require("../../../anyspend/constants");
|
|
4
5
|
const anyspend_1 = require("../../../anyspend/services/anyspend");
|
|
5
6
|
const utils_1 = require("../../../anyspend/utils");
|
|
6
7
|
const react_query_1 = require("@tanstack/react-query");
|
|
7
8
|
const react_1 = require("react");
|
|
8
9
|
const viem_1 = require("viem");
|
|
9
10
|
const chains_1 = require("viem/chains");
|
|
10
|
-
const constants_1 = require("../../../anyspend/constants");
|
|
11
11
|
/**
|
|
12
12
|
* Hook for creating onramp orders in the Anyspend protocol
|
|
13
13
|
* Specifically handles orders that involve fiat-to-crypto onramp functionality
|
|
@@ -15,7 +15,7 @@ const constants_1 = require("../../../anyspend/constants");
|
|
|
15
15
|
function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
16
16
|
const { mutate: createOrder, isPending } = (0, react_query_1.useMutation)({
|
|
17
17
|
mutationFn: async (params) => {
|
|
18
|
-
const { isMainnet, recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload } = params;
|
|
18
|
+
const { isMainnet, recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload, partnerId } = params;
|
|
19
19
|
try {
|
|
20
20
|
// Validate Stripe onramp options
|
|
21
21
|
if (onramp.vendor === "stripe" && !onramp.ipAddress) {
|
|
@@ -57,7 +57,8 @@ function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
57
57
|
tournament,
|
|
58
58
|
payload
|
|
59
59
|
}),
|
|
60
|
-
creatorAddress: creatorAddress ? (0, utils_1.normalizeAddress)(creatorAddress) : undefined
|
|
60
|
+
creatorAddress: creatorAddress ? (0, utils_1.normalizeAddress)(creatorAddress) : undefined,
|
|
61
|
+
partnerId
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
catch (error) {
|
|
@@ -4,7 +4,7 @@ export declare const anyspendService: {
|
|
|
4
4
|
getTokenList: (isMainnet: boolean, chainId: number, query: string) => Promise<Token[]>;
|
|
5
5
|
getToken: (isMainnet: boolean, chainId: number, tokenAddress: string) => Promise<Token>;
|
|
6
6
|
getQuote: (isMainnet: boolean, req: GetQuoteRequest) => Promise<GetQuoteResponse>;
|
|
7
|
-
createOrder: ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress }: {
|
|
7
|
+
createOrder: ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId }: {
|
|
8
8
|
isMainnet: boolean;
|
|
9
9
|
recipientAddress: string;
|
|
10
10
|
type: string;
|
|
@@ -17,6 +17,7 @@ export declare const anyspendService: {
|
|
|
17
17
|
onramp?: OnrampOptions;
|
|
18
18
|
metadata: Record<string, any>;
|
|
19
19
|
creatorAddress?: string;
|
|
20
|
+
partnerId?: string;
|
|
20
21
|
}) => Promise<any>;
|
|
21
22
|
getOrderAndTransactions: (isMainnet: boolean, orderId: string | undefined) => Promise<GetOrderAndTxsResponse>;
|
|
22
23
|
getOrderHistory: (isMainnet: boolean, creatorAddress: string | undefined, limit?: number, offset?: number) => Promise<{
|
|
@@ -43,7 +43,7 @@ exports.anyspendService = {
|
|
|
43
43
|
return data;
|
|
44
44
|
},
|
|
45
45
|
// Order related
|
|
46
|
-
createOrder: async ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress }) => {
|
|
46
|
+
createOrder: async ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId }) => {
|
|
47
47
|
const response = await fetch(`${isMainnet ? constants_1.ANYSPEND_MAINNET_BASE_URL : constants_1.ANYSPEND_TESTNET_BASE_URL}/orders`, {
|
|
48
48
|
method: "POST",
|
|
49
49
|
headers: {
|
|
@@ -60,7 +60,8 @@ exports.anyspendService = {
|
|
|
60
60
|
payload,
|
|
61
61
|
onramp,
|
|
62
62
|
metadata,
|
|
63
|
-
creatorAddress
|
|
63
|
+
creatorAddress,
|
|
64
|
+
partnerId
|
|
64
65
|
})
|
|
65
66
|
});
|
|
66
67
|
const data = await response.json();
|
|
@@ -14,4 +14,8 @@ interface UseTokenFromUrlOptions {
|
|
|
14
14
|
* Looks for parameters: [prefix]Currency
|
|
15
15
|
*/
|
|
16
16
|
export declare function useTokenFromUrl({ defaultToken, prefix }: UseTokenFromUrlOptions): Token;
|
|
17
|
+
export declare function useTokenFromAddress({ address, chainId }: {
|
|
18
|
+
address: string;
|
|
19
|
+
chainId: number;
|
|
20
|
+
}): Token | undefined;
|
|
17
21
|
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.useTokenFromUrl = useTokenFromUrl;
|
|
5
|
+
exports.useTokenFromAddress = useTokenFromAddress;
|
|
5
6
|
const supported_1 = require("../../../shared/constants/chains/supported");
|
|
6
7
|
const react_query_1 = require("@tanstack/react-query");
|
|
7
8
|
const navigation_1 = require("next/navigation");
|
|
@@ -66,3 +67,25 @@ function useTokenFromUrl({ defaultToken, prefix }) {
|
|
|
66
67
|
}
|
|
67
68
|
};
|
|
68
69
|
}
|
|
70
|
+
function useTokenFromAddress({ address, chainId }) {
|
|
71
|
+
const { data: tokenInfo, isError } = (0, react_query_1.useQuery)({
|
|
72
|
+
queryKey: ["tokenInfo", address, chainId],
|
|
73
|
+
queryFn: () => fetchTokenInfo((0, supported_1.getCoingeckoChainInfo)(chainId).coingecko_id, address),
|
|
74
|
+
enabled: Boolean(address),
|
|
75
|
+
staleTime: Infinity,
|
|
76
|
+
gcTime: Infinity
|
|
77
|
+
});
|
|
78
|
+
if (isError || !tokenInfo) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
address,
|
|
83
|
+
chainId,
|
|
84
|
+
name: tokenInfo?.data.attributes.name || "",
|
|
85
|
+
symbol: tokenInfo?.data.attributes.symbol || "",
|
|
86
|
+
decimals: tokenInfo?.data.attributes.decimals || 18,
|
|
87
|
+
metadata: {
|
|
88
|
+
logoURI: tokenInfo?.data.attributes.image_url
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -53,12 +53,8 @@ export declare function getCoingeckoChainInfo(chainId: number): {
|
|
|
53
53
|
name: string;
|
|
54
54
|
native_coin_id: string;
|
|
55
55
|
};
|
|
56
|
+
export declare const b3MainnetThirdWeb: ThirdwebChain;
|
|
57
|
+
export declare const b3TestnetThirdWeb: ThirdwebChain;
|
|
56
58
|
export declare const b3Mainnet: import("viem").Chain | undefined;
|
|
57
59
|
export declare const b3Testnet: import("viem").Chain | undefined;
|
|
58
60
|
export declare const baseMainnet: import("viem").Chain | undefined;
|
|
59
|
-
export declare const b3MainnetThirdWeb: Readonly<import("thirdweb/dist/types/chains/types").ChainOptions & {
|
|
60
|
-
rpc: string;
|
|
61
|
-
}> | undefined;
|
|
62
|
-
export declare const b3TestnetThirdWeb: Readonly<import("thirdweb/dist/types/chains/types").ChainOptions & {
|
|
63
|
-
rpc: string;
|
|
64
|
-
}> | undefined;
|
|
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.baseMainnet = exports.b3Testnet = exports.b3Mainnet = exports.b3TestnetThirdWeb = exports.b3MainnetThirdWeb = exports.coingeckoChains = exports.supportedChainNetworks = exports.supportedChainsTW = exports.supportedChains = void 0;
|
|
7
7
|
exports.getCoingeckoChainInfo = getCoingeckoChainInfo;
|
|
8
8
|
const chain_transformers_1 = require("../../../shared/utils/chain-transformers");
|
|
9
|
+
const invariant_1 = __importDefault(require("invariant"));
|
|
9
10
|
// Import the JSON directly
|
|
10
11
|
// @ts-ignore
|
|
11
12
|
const chain_networks_json_1 = __importDefault(require("../../generated/chain-networks.json"));
|
|
@@ -34,8 +35,10 @@ exports.coingeckoChains = coingecko_chains_json_1.default;
|
|
|
34
35
|
function getCoingeckoChainInfo(chainId) {
|
|
35
36
|
return exports.coingeckoChains[chainId];
|
|
36
37
|
}
|
|
38
|
+
exports.b3MainnetThirdWeb = exports.supportedChainsTW.find(chain => chain.id === 8333);
|
|
39
|
+
(0, invariant_1.default)(exports.b3MainnetThirdWeb, "B3 mainnet chain not found in supported chains TW");
|
|
40
|
+
exports.b3TestnetThirdWeb = exports.supportedChainsTW.find(chain => chain.id === 1993);
|
|
41
|
+
(0, invariant_1.default)(exports.b3TestnetThirdWeb, "B3 testnet chain not found in supported chains TW");
|
|
37
42
|
exports.b3Mainnet = exports.supportedChains.find(chain => chain.id === 8333);
|
|
38
43
|
exports.b3Testnet = exports.supportedChains.find(chain => chain.id === 1993);
|
|
39
44
|
exports.baseMainnet = exports.supportedChains.find(chain => chain.id === 8453);
|
|
40
|
-
exports.b3MainnetThirdWeb = exports.supportedChainsTW.find(chain => chain.id === 8333);
|
|
41
|
-
exports.b3TestnetThirdWeb = exports.supportedChainsTW.find(chain => chain.id === 1993);
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
// Export all hooks
|
|
2
|
-
export * from "./react/hooks";
|
|
2
|
+
export * from "./react/hooks/index.js";
|
|
3
3
|
// Providers
|
|
4
|
-
export * from "./react/providers/AnyspendProvider";
|
|
4
|
+
export * from "./react/providers/AnyspendProvider.js";
|
|
5
5
|
// Types
|
|
6
|
-
export * from "./types";
|
|
6
|
+
export * from "./types/index.js";
|
|
7
7
|
// Utils
|
|
8
|
-
export * from "./utils/address";
|
|
9
|
-
export * from "./utils/chain";
|
|
10
|
-
export * from "./utils/format";
|
|
11
|
-
export * from "./utils/json";
|
|
12
|
-
export * from "./utils/number";
|
|
13
|
-
export * from "./utils/string";
|
|
14
|
-
export * from "./utils/token";
|
|
8
|
+
export * from "./utils/address.js";
|
|
9
|
+
export * from "./utils/chain.js";
|
|
10
|
+
export * from "./utils/format.js";
|
|
11
|
+
export * from "./utils/json.js";
|
|
12
|
+
export * from "./utils/number.js";
|
|
13
|
+
export * from "./utils/string.js";
|
|
14
|
+
export * from "./utils/token.js";
|
|
15
15
|
// Constants
|
|
16
|
-
export * from "./constants";
|
|
16
|
+
export * from "./constants/index.js";
|
|
17
17
|
// Abis
|
|
18
|
-
export * from "./abis/abi-usdc-base";
|
|
19
|
-
export * from "./abis/erc20-staking";
|
|
20
|
-
console.log(`Test CICD`);
|
|
18
|
+
export * from "./abis/abi-usdc-base.js";
|
|
19
|
+
export * from "./abis/erc20-staking.js";
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Export all hooks
|
|
2
|
-
export * from "./react/hooks";
|
|
2
|
+
export * from "./react/hooks/index.js";
|
|
3
3
|
// Providers
|
|
4
|
-
export * from "./react/providers/AnyspendProvider";
|
|
4
|
+
export * from "./react/providers/AnyspendProvider.js";
|
|
5
5
|
// Types
|
|
6
|
-
export * from "./types";
|
|
6
|
+
export * from "./types/index.js";
|
|
7
7
|
// Utils
|
|
8
|
-
export * from "./utils/address";
|
|
9
|
-
export * from "./utils/chain";
|
|
10
|
-
export * from "./utils/format";
|
|
11
|
-
export * from "./utils/json";
|
|
12
|
-
export * from "./utils/number";
|
|
13
|
-
export * from "./utils/string";
|
|
14
|
-
export * from "./utils/token";
|
|
8
|
+
export * from "./utils/address.js";
|
|
9
|
+
export * from "./utils/chain.js";
|
|
10
|
+
export * from "./utils/format.js";
|
|
11
|
+
export * from "./utils/json.js";
|
|
12
|
+
export * from "./utils/number.js";
|
|
13
|
+
export * from "./utils/string.js";
|
|
14
|
+
export * from "./utils/token.js";
|
|
15
15
|
// Constants
|
|
16
|
-
export * from "./constants";
|
|
16
|
+
export * from "./constants/index.js";
|
|
17
17
|
// Abis
|
|
18
|
-
export * from "./abis/abi-usdc-base";
|
|
19
|
-
export * from "./abis/erc20-staking";
|
|
18
|
+
export * from "./abis/abi-usdc-base.js";
|
|
19
|
+
export * from "./abis/erc20-staking.js";
|