@b3dotfun/sdk 0.0.5-alpha.0 → 0.0.5-alpha.2
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/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/esm/anyspend/react/components/AnySpend.js +2 -2
- package/dist/esm/anyspend/react/components/index.d.ts +1 -0
- package/dist/esm/anyspend/react/components/index.js +1 -0
- 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 +139 -59
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +5 -4
- package/dist/esm/anyspend/services/anyspend.d.ts +2 -1
- package/dist/esm/anyspend/services/anyspend.js +3 -2
- package/dist/esm/global-account/react/hooks/useTokenFromUrl.d.ts +4 -0
- package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +22 -0
- 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/package.json +1 -1
- package/src/anyspend/README.md +694 -0
- 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
|
@@ -1,16 +1,65 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
2
|
-
import { getChainName, OnrampVendor, OrderType, useAnyspendCreateOnrampOrder, useGeoOnrampOptions } from "../../../../anyspend/index.js";
|
|
3
|
-
import { Button } from "../../../../global-account/react/index.js";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getChainName, OnrampVendor, OrderType, STRIPE_CONFIG, useAnyspendCreateOnrampOrder, useGeoOnrampOptions, useStripeClientSecret } from "../../../../anyspend/index.js";
|
|
4
3
|
import centerTruncate from "../../../../shared/utils/centerTruncate.js";
|
|
4
|
+
import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
5
|
+
import { loadStripe } from "@stripe/stripe-js";
|
|
5
6
|
import { motion } from "framer-motion";
|
|
6
7
|
import { Loader2 } from "lucide-react";
|
|
7
8
|
import { useEffect, useRef, useState } from "react";
|
|
8
9
|
import { toast } from "sonner";
|
|
9
10
|
import { formatUnits } from "viem";
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const stripePromise = loadStripe(STRIPE_CONFIG.publishableKey);
|
|
12
|
+
// Stripe Payment Form Component
|
|
13
|
+
function StripePaymentForm({ order, onPaymentSuccess }) {
|
|
14
|
+
const stripe = useStripe();
|
|
15
|
+
const elements = useElements();
|
|
16
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
17
|
+
const [error, setError] = useState(null);
|
|
18
|
+
const handleSubmit = async (e) => {
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
if (!stripe || !elements) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
setIsProcessing(true);
|
|
24
|
+
setError(null);
|
|
25
|
+
try {
|
|
26
|
+
const { error: submitError } = await stripe.confirmPayment({
|
|
27
|
+
elements,
|
|
28
|
+
redirect: "if_required"
|
|
29
|
+
});
|
|
30
|
+
if (submitError) {
|
|
31
|
+
setError(submitError.message || "An error occurred");
|
|
32
|
+
console.error("Payment error:", submitError);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log("Payment successful");
|
|
36
|
+
onPaymentSuccess(order.id);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
setError(err.message || "An error occurred");
|
|
41
|
+
console.error("Payment error:", err);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
setIsProcessing(false);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const stripeElementOptions = {
|
|
48
|
+
layout: "tabs",
|
|
49
|
+
defaultValues: {
|
|
50
|
+
billingDetails: {
|
|
51
|
+
name: "",
|
|
52
|
+
email: ""
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return (_jsx("form", { onSubmit: handleSubmit, className: "w-full", children: _jsx("div", { className: "overflow-hidden rounded-xl bg-white", children: _jsxs("div", { className: "px-6 py-4", children: [_jsx("h2", { className: "mb-4 text-lg font-semibold", children: "Payment Details" }), _jsx(PaymentElement, { options: stripeElementOptions }), error && (_jsx("div", { className: "mt-4 rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-600", children: error })), _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 ? (_jsxs("div", { className: "flex items-center justify-center gap-2", children: [_jsx(Loader2, { className: "h-5 w-5 animate-spin" }), _jsx("span", { children: "Processing..." })] })) : (_jsx("span", { children: "Complete Payment" })) })] }) }) }));
|
|
57
|
+
}
|
|
58
|
+
export function WebviewOnrampPayment({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote, onPaymentSuccess, userId, partnerId }) {
|
|
12
59
|
const [stableAmountForGeo, setStableAmountForGeo] = useState(srcAmountOnRamp);
|
|
13
60
|
const hasInitialized = useRef(false);
|
|
61
|
+
const [createdOrder, setCreatedOrder] = useState(null);
|
|
62
|
+
const orderCreationAttempted = useRef(false);
|
|
14
63
|
// Only update the stable amount on first render or when explicitly needed
|
|
15
64
|
useEffect(() => {
|
|
16
65
|
if (!hasInitialized.current && srcAmountOnRamp) {
|
|
@@ -19,69 +68,100 @@ export function WebviewOnrampPayment({ srcAmountOnRamp, recipientAddress, destin
|
|
|
19
68
|
}
|
|
20
69
|
}, [srcAmountOnRamp]);
|
|
21
70
|
const { geoData, isStripeWeb2Supported, isLoading: isLoadingGeoOnramp } = useGeoOnrampOptions(true, stableAmountForGeo);
|
|
22
|
-
console.log("isStripeWeb2Supported", isStripeWeb2Supported);
|
|
23
71
|
const { createOrder, isCreatingOrder } = useAnyspendCreateOnrampOrder({
|
|
24
72
|
onSuccess: data => {
|
|
25
73
|
const orderId = data.data.id;
|
|
26
|
-
|
|
74
|
+
setCreatedOrder(data.data);
|
|
27
75
|
},
|
|
28
76
|
onError: error => {
|
|
29
77
|
console.error(error);
|
|
30
78
|
toast.error("Failed to create order: " + error.message);
|
|
31
79
|
}
|
|
32
80
|
});
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
81
|
+
const { clientSecret, isLoadingStripeClientSecret } = useStripeClientSecret(true, createdOrder?.stripePaymentIntentId || "");
|
|
82
|
+
// Create order when component mounts and all required data is available
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const createOrderIfPossible = async () => {
|
|
85
|
+
if (!orderCreationAttempted.current &&
|
|
86
|
+
recipientAddress &&
|
|
87
|
+
srcAmountOnRamp &&
|
|
88
|
+
parseFloat(srcAmountOnRamp) > 0 &&
|
|
89
|
+
isStripeWeb2Supported &&
|
|
90
|
+
anyspendQuote &&
|
|
91
|
+
geoData) {
|
|
92
|
+
orderCreationAttempted.current = true;
|
|
93
|
+
try {
|
|
94
|
+
const getDstToken = () => {
|
|
95
|
+
return {
|
|
96
|
+
...destinationToken,
|
|
97
|
+
chainId: destinationToken.chainId,
|
|
98
|
+
address: destinationToken.address
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
createOrder({
|
|
102
|
+
isMainnet: true,
|
|
103
|
+
recipientAddress,
|
|
104
|
+
orderType: OrderType.Swap,
|
|
105
|
+
dstChain: getDstToken().chainId,
|
|
106
|
+
dstToken: getDstToken(),
|
|
107
|
+
srcFiatAmount: srcAmountOnRamp,
|
|
108
|
+
onramp: {
|
|
109
|
+
vendor: OnrampVendor.StripeWeb2,
|
|
110
|
+
paymentMethod: "",
|
|
111
|
+
country: geoData.country || "US",
|
|
112
|
+
ipAddress: geoData.ip,
|
|
113
|
+
redirectUrl: `${window.location.origin}${userId ? `?userId=${userId}` : ""}`
|
|
114
|
+
},
|
|
115
|
+
expectedDstAmount: anyspendQuote.data?.currencyOut?.amount?.toString() || "0",
|
|
116
|
+
partnerId
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
console.error(err);
|
|
121
|
+
toast.error("Failed to create order: " + err.message);
|
|
122
|
+
}
|
|
50
123
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
124
|
+
};
|
|
125
|
+
createOrderIfPossible();
|
|
126
|
+
}, [
|
|
127
|
+
recipientAddress,
|
|
128
|
+
srcAmountOnRamp,
|
|
129
|
+
isStripeWeb2Supported,
|
|
130
|
+
anyspendQuote,
|
|
131
|
+
geoData,
|
|
132
|
+
createOrder,
|
|
133
|
+
destinationToken,
|
|
134
|
+
userId,
|
|
135
|
+
partnerId
|
|
136
|
+
]);
|
|
137
|
+
// Check if all required data is loaded
|
|
138
|
+
const isLoading = isLoadingGeoOnramp || !anyspendQuote || !destinationToken.metadata?.logoURI;
|
|
139
|
+
// Show loading state while data is being fetched or order is being created
|
|
140
|
+
if (isLoading || isCreatingOrder || isLoadingStripeClientSecret) {
|
|
141
|
+
return (_jsxs("div", { className: "mx-auto flex w-full max-w-[460px] flex-col items-center justify-center gap-3 py-12", children: [_jsx(Loader2, { className: "text-as-brand h-8 w-8 animate-spin" }), _jsx("span", { className: "text-as-primary/70", children: isCreatingOrder
|
|
142
|
+
? "Creating payment session..."
|
|
143
|
+
: isLoadingStripeClientSecret
|
|
144
|
+
? "Loading payment form..."
|
|
145
|
+
: "Loading payment details..." })] }));
|
|
146
|
+
}
|
|
147
|
+
// If we have a created order and client secret, show the payment form
|
|
148
|
+
if (createdOrder && clientSecret) {
|
|
149
|
+
return (_jsxs("div", { className: "mx-auto flex w-full max-w-[460px] flex-col gap-6", children: [_jsx("div", { className: "overflow-hidden rounded-xl bg-white", children: _jsxs("div", { className: "px-6 py-4", children: [_jsx("h2", { className: "mb-4 text-lg font-semibold", children: "Order summary" }), _jsxs("div", { className: "flex flex-col divide-y", children: [_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Receiving" }), _jsxs("div", { className: "flex items-center gap-2", children: [destinationToken.metadata?.logoURI && (_jsx("img", { src: destinationToken.metadata.logoURI, alt: destinationToken.symbol, className: "h-5 w-5 rounded-full" })), _jsxs("span", { className: "font-medium", children: [anyspendQuote?.data?.currencyOut?.amount
|
|
150
|
+
? Number(formatUnits(BigInt(anyspendQuote.data.currencyOut.amount), destinationToken.decimals)).toFixed(4)
|
|
151
|
+
: "0", " ", destinationToken.symbol] })] })] }), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Network" }), _jsx("span", { className: "font-medium", children: getChainName(destinationToken.chainId) })] }), recipientAddress && (_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Recipient" }), _jsx("span", { className: "font-medium", children: centerTruncate(recipientAddress) })] })), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "You Pay" }), _jsxs("span", { className: "text-lg font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] })] })] }) }), _jsx(Elements, { stripe: stripePromise, options: {
|
|
152
|
+
clientSecret,
|
|
153
|
+
appearance: {
|
|
154
|
+
theme: "flat",
|
|
155
|
+
variables: {
|
|
156
|
+
colorPrimary: "#2563eb",
|
|
157
|
+
colorBackground: "#ffffff",
|
|
158
|
+
borderRadius: "12px"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}, children: _jsx(StripePaymentForm, { order: createdOrder, onPaymentSuccess: onPaymentSuccess }) })] }));
|
|
162
|
+
}
|
|
163
|
+
// Show initial order summary while waiting for order creation
|
|
164
|
+
return (_jsx(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: _jsx("div", { className: "overflow-hidden rounded-xl bg-white", children: _jsxs("div", { className: "px-6 py-4", children: [_jsx("h2", { className: "mb-4 text-lg font-semibold", children: "Order summary" }), _jsxs("div", { className: "flex flex-col divide-y", children: [_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Receiving" }), _jsxs("div", { className: "flex items-center gap-2", children: [destinationToken.metadata?.logoURI && (_jsx("img", { src: destinationToken.metadata.logoURI, alt: destinationToken.symbol, className: "h-5 w-5 rounded-full" })), _jsxs("span", { className: "font-medium", children: [anyspendQuote?.data?.currencyOut?.amount
|
|
81
165
|
? Number(formatUnits(BigInt(anyspendQuote.data.currencyOut.amount), destinationToken.decimals)).toFixed(4)
|
|
82
|
-
: "0", " ", destinationToken.symbol] })] })] }), _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("
|
|
83
|
-
opacity: 1,
|
|
84
|
-
y: 0,
|
|
85
|
-
filter: "blur(0px)"
|
|
86
|
-
}, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "flex items-center justify-between", children: [_jsx("p", { className: "text-b3-react-foreground/60", children: "Recipient" }), _jsx("div", { className: "flex items-center gap-2", children: _jsx("span", { className: "text-b3-react-foreground/80", children: centerTruncate(recipientAddress) }) })] })), _jsx("div", { className: "border-b3-react-border border-t pt-3", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("p", { className: "text-b3-react-foreground font-semibold", children: "You Pay" }), _jsxs("p", { className: "text-b3-react-foreground text-xl font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] }) })] })] }), isCreatingOrder ? (_jsxs("div", { className: "bg-b3-react-background border-b3-react-border flex items-center justify-center gap-3 rounded-lg border p-6", children: [_jsx(Loader2, { className: "h-4 w-4 animate-spin" }), _jsx("span", { className: "text-as-primary/70", children: "Creating payment session..." })] })) : isLoadingGeoOnramp ? (_jsxs("div", { className: "bg-b3-react-background border-b3-react-border flex items-center justify-center gap-3 rounded-lg border p-6", children: [_jsx(Loader2, { className: "h-4 w-4 animate-spin" }), _jsx("span", { className: "text-as-primary/70", children: "Loading payment options..." })] })) : (_jsx("div", { className: "flex flex-col gap-4", children: _jsx(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" }) }))] }));
|
|
166
|
+
: "0", " ", destinationToken.symbol] })] })] }), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Network" }), _jsx("span", { className: "font-medium", children: getChainName(destinationToken.chainId) })] }), recipientAddress && (_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Recipient" }), _jsx("span", { className: "font-medium", children: centerTruncate(recipientAddress) })] })), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "You Pay" }), _jsxs("span", { className: "text-lg font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] })] })] }) }) }));
|
|
87
167
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { USDC_BASE } from "../../../anyspend/constants/index.js";
|
|
1
2
|
import { anyspendService } from "../../../anyspend/services/anyspend.js";
|
|
2
|
-
import {
|
|
3
|
+
import { buildMetadata, buildPayload, normalizeAddress } from "../../../anyspend/utils/index.js";
|
|
3
4
|
import { useMutation } from "@tanstack/react-query";
|
|
4
5
|
import { useMemo } from "react";
|
|
5
6
|
import { parseUnits } from "viem";
|
|
6
7
|
import { base } from "viem/chains";
|
|
7
|
-
import { USDC_BASE } from "../../../anyspend/constants/index.js";
|
|
8
8
|
/**
|
|
9
9
|
* Hook for creating onramp orders in the Anyspend protocol
|
|
10
10
|
* Specifically handles orders that involve fiat-to-crypto onramp functionality
|
|
@@ -12,7 +12,7 @@ import { USDC_BASE } from "../../../anyspend/constants/index.js";
|
|
|
12
12
|
export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
13
13
|
const { mutate: createOrder, isPending } = useMutation({
|
|
14
14
|
mutationFn: async (params) => {
|
|
15
|
-
const { isMainnet, recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload } = params;
|
|
15
|
+
const { isMainnet, recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload, partnerId } = params;
|
|
16
16
|
try {
|
|
17
17
|
// Validate Stripe onramp options
|
|
18
18
|
if (onramp.vendor === "stripe" && !onramp.ipAddress) {
|
|
@@ -54,7 +54,8 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
54
54
|
tournament,
|
|
55
55
|
payload
|
|
56
56
|
}),
|
|
57
|
-
creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined
|
|
57
|
+
creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
|
|
58
|
+
partnerId
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
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<{
|
|
@@ -37,7 +37,7 @@ export const anyspendService = {
|
|
|
37
37
|
return data;
|
|
38
38
|
},
|
|
39
39
|
// Order related
|
|
40
|
-
createOrder: async ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress }) => {
|
|
40
|
+
createOrder: async ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId }) => {
|
|
41
41
|
const response = await fetch(`${isMainnet ? ANYSPEND_MAINNET_BASE_URL : ANYSPEND_TESTNET_BASE_URL}/orders`, {
|
|
42
42
|
method: "POST",
|
|
43
43
|
headers: {
|
|
@@ -54,7 +54,8 @@ export const anyspendService = {
|
|
|
54
54
|
payload,
|
|
55
55
|
onramp,
|
|
56
56
|
metadata,
|
|
57
|
-
creatorAddress
|
|
57
|
+
creatorAddress,
|
|
58
|
+
partnerId
|
|
58
59
|
})
|
|
59
60
|
});
|
|
60
61
|
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 {};
|
|
@@ -63,3 +63,25 @@ export function useTokenFromUrl({ defaultToken, prefix }) {
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
export function useTokenFromAddress({ address, chainId }) {
|
|
67
|
+
const { data: tokenInfo, isError } = useQuery({
|
|
68
|
+
queryKey: ["tokenInfo", address, chainId],
|
|
69
|
+
queryFn: () => fetchTokenInfo(getCoingeckoChainInfo(chainId).coingecko_id, address),
|
|
70
|
+
enabled: Boolean(address),
|
|
71
|
+
staleTime: Infinity,
|
|
72
|
+
gcTime: Infinity
|
|
73
|
+
});
|
|
74
|
+
if (isError || !tokenInfo) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
address,
|
|
79
|
+
chainId,
|
|
80
|
+
name: tokenInfo?.data.attributes.name || "",
|
|
81
|
+
symbol: tokenInfo?.data.attributes.symbol || "",
|
|
82
|
+
decimals: tokenInfo?.data.attributes.decimals || 18,
|
|
83
|
+
metadata: {
|
|
84
|
+
logoURI: tokenInfo?.data.attributes.image_url
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|