@b3dotfun/sdk 0.0.16-alpha.2 → 0.0.16-alpha.3
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/AnySpendCustom.js +23 -28
- package/dist/cjs/anyspend/react/components/common/PanelOnrampPayment.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +24 -29
- package/dist/esm/anyspend/react/components/common/PanelOnrampPayment.js +0 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +30 -33
- package/src/anyspend/react/components/common/PanelOnrampPayment.tsx +0 -2
|
@@ -162,8 +162,8 @@ function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", recipient
|
|
|
162
162
|
const getRelayQuoteRequest = (0, react_4.useMemo)(() => {
|
|
163
163
|
return generateGetRelayQuoteRequest({
|
|
164
164
|
orderType: orderType,
|
|
165
|
-
srcChainId: srcChainId,
|
|
166
|
-
srcToken: srcToken,
|
|
165
|
+
srcChainId: activeTab === "fiat" ? chains_1.base.id : srcChainId,
|
|
166
|
+
srcToken: activeTab === "fiat" ? constants_1.USDC_BASE : srcToken,
|
|
167
167
|
dstChainId: dstChainId,
|
|
168
168
|
dstToken: dstToken,
|
|
169
169
|
dstAmount: dstAmount,
|
|
@@ -174,12 +174,15 @@ function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", recipient
|
|
|
174
174
|
spenderAddress: spenderAddress,
|
|
175
175
|
});
|
|
176
176
|
}, [
|
|
177
|
+
activeTab,
|
|
177
178
|
contractAddress,
|
|
178
179
|
dstAmount,
|
|
179
180
|
dstChainId,
|
|
180
181
|
dstToken,
|
|
181
182
|
encodedData,
|
|
182
|
-
metadata,
|
|
183
|
+
metadata.nftContract.tokenId,
|
|
184
|
+
metadata.nftContract.type,
|
|
185
|
+
metadata.type,
|
|
183
186
|
orderType,
|
|
184
187
|
spenderAddress,
|
|
185
188
|
srcChainId,
|
|
@@ -195,33 +198,25 @@ function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", recipient
|
|
|
195
198
|
params.set("orderId", selectedOrderId);
|
|
196
199
|
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
197
200
|
};
|
|
198
|
-
const [srcAmount, setSrcAmount] = (0, react_4.useState)(null);
|
|
199
|
-
const formattedSrcAmount = srcAmount ? (0, number_1.formatUnits)(srcAmount.toString(), srcToken.decimals) : null;
|
|
200
|
-
// Get geo data and onramp options (after quote is available)
|
|
201
|
-
const { geoData, isOnrampSupported } = (0, react_1.useGeoOnrampOptions)(isMainnet, formattedSrcAmount || "0");
|
|
202
|
-
// Update the selected src token to USDC and chain to base when the active tab is fiat,
|
|
203
|
-
// also force not to update srcToken by setting dirtySelectSrcToken to true.
|
|
204
|
-
(0, react_4.useEffect)(() => {
|
|
205
|
-
if (activeTab === "fiat") {
|
|
206
|
-
setSrcChainId(chains_1.base.id);
|
|
207
|
-
setSrcToken(constants_1.USDC_BASE);
|
|
208
|
-
setDirtySelectSrcToken(true);
|
|
209
|
-
}
|
|
210
|
-
}, [activeTab]);
|
|
211
201
|
// Update dependent amount when relay price changes
|
|
212
|
-
(0, react_4.
|
|
213
|
-
if (anyspendQuote?.data
|
|
214
|
-
anyspendQuote
|
|
215
|
-
anyspendQuote
|
|
216
|
-
|
|
217
|
-
|
|
202
|
+
const srcAmount = (0, react_4.useMemo)(() => {
|
|
203
|
+
if (!anyspendQuote?.data ||
|
|
204
|
+
!anyspendQuote?.data?.currencyIn?.amount ||
|
|
205
|
+
!anyspendQuote?.data?.currencyIn?.currency?.decimals)
|
|
206
|
+
return null;
|
|
207
|
+
const amount = anyspendQuote.data.currencyIn.amount;
|
|
208
|
+
if (activeTab === "fiat") {
|
|
218
209
|
const roundUpAmount = (0, anyspend_1.roundUpUSDCBaseAmountToNearest)(amount);
|
|
219
|
-
|
|
210
|
+
return BigInt(roundUpAmount);
|
|
220
211
|
}
|
|
221
212
|
else {
|
|
222
|
-
|
|
213
|
+
return BigInt(amount);
|
|
223
214
|
}
|
|
224
|
-
}, [anyspendQuote?.data]);
|
|
215
|
+
}, [activeTab, anyspendQuote?.data]);
|
|
216
|
+
const formattedSrcAmount = srcAmount ? (0, number_1.formatTokenAmount)(srcAmount, srcToken.decimals, 6, false) : null;
|
|
217
|
+
const srcFiatAmount = (0, react_4.useMemo)(() => (activeTab === "fiat" && srcAmount ? (0, number_1.formatUnits)(srcAmount.toString(), constants_1.USDC_BASE.decimals) : "0"), [activeTab, srcAmount]);
|
|
218
|
+
// Get geo data and onramp options (after quote is available)
|
|
219
|
+
const { geoData, isOnrampSupported } = (0, react_1.useGeoOnrampOptions)(isMainnet, srcFiatAmount);
|
|
225
220
|
(0, react_4.useEffect)(() => {
|
|
226
221
|
if (oat?.data?.order.status === "executed") {
|
|
227
222
|
console.log("Calling onSuccess");
|
|
@@ -255,9 +250,9 @@ function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", recipient
|
|
|
255
250
|
const createOrderParams = {
|
|
256
251
|
isMainnet: isMainnet,
|
|
257
252
|
orderType: orderType,
|
|
258
|
-
srcChain: srcChainId,
|
|
253
|
+
srcChain: activeTab === "fiat" ? chains_1.base.id : srcChainId,
|
|
259
254
|
dstChain: dstChainId,
|
|
260
|
-
srcToken: srcToken,
|
|
255
|
+
srcToken: activeTab === "fiat" ? constants_1.USDC_BASE : srcToken,
|
|
261
256
|
dstToken: dstToken,
|
|
262
257
|
srcAmount: srcAmount.toString(),
|
|
263
258
|
recipientAddress,
|
|
@@ -306,7 +301,7 @@ function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", recipient
|
|
|
306
301
|
(0, invariant_1.default)(srcChainId === chains_1.base.id, "Selected src chain is not base");
|
|
307
302
|
void createOnrampOrder({
|
|
308
303
|
...createOrderParams,
|
|
309
|
-
srcFiatAmount:
|
|
304
|
+
srcFiatAmount: srcFiatAmount,
|
|
310
305
|
onramp: {
|
|
311
306
|
vendor: onramp.vendor,
|
|
312
307
|
paymentMethod: onramp.paymentMethod,
|
|
@@ -19,7 +19,6 @@ function PanelOnrampPayment(props) {
|
|
|
19
19
|
}
|
|
20
20
|
function PanelOnrampPaymentInner(props) {
|
|
21
21
|
const { srcAmountOnRamp, recipientAddress, isMainnet, isBuyMode, destinationTokenChainId, destinationTokenAddress, selectedDstChainId, selectedDstToken, anyspendQuote, globalAddress, onOrderCreated, onBack, orderType, nft, tournament, payload, recipientEnsName, recipientImageUrl, } = props;
|
|
22
|
-
console.log(`PanelOnrampPaymentInner:srcAmountOnRamp`, srcAmountOnRamp);
|
|
23
22
|
const { geoData, coinbaseOnrampOptions, coinbaseAvailablePaymentMethods, isStripeOnrampSupported, stripeWeb2Support, isLoading: isLoadingGeoOnramp, } = (0, react_1.useGeoOnrampOptions)(isMainnet, srcAmountOnRamp);
|
|
24
23
|
const isLoading = isLoadingGeoOnramp;
|
|
25
24
|
const { createOrder, isCreatingOrder } = (0, react_1.useAnyspendCreateOnrampOrder)({
|
|
@@ -5,7 +5,7 @@ import { useAnyspendCreateOnrampOrder, useAnyspendCreateOrder, useAnyspendOrderA
|
|
|
5
5
|
import { Badge, Button, Dialog, DialogContent, Input, ShinyButton, Skeleton, StyleRoot, Tabs, TabsContent, TabsList, TabTrigger, TextShimmer, Tooltip, TooltipContent, TooltipTrigger, TransitionPanel, useAccountWallet, useHasMounted, useProfile, useRouter, useSearchParamsSSR, useTokenBalancesByChain, } from "../../../global-account/react/index.js";
|
|
6
6
|
import { cn } from "../../../shared/utils/index.js";
|
|
7
7
|
import centerTruncate from "../../../shared/utils/centerTruncate.js";
|
|
8
|
-
import { formatUnits } from "../../../shared/utils/number.js";
|
|
8
|
+
import { formatTokenAmount, formatUnits } from "../../../shared/utils/number.js";
|
|
9
9
|
import { simpleHashChainToChainName } from "../../../shared/utils/simplehash.js";
|
|
10
10
|
import invariant from "invariant";
|
|
11
11
|
import { ChevronRightCircle, Loader2 } from "lucide-react";
|
|
@@ -156,8 +156,8 @@ export function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", re
|
|
|
156
156
|
const getRelayQuoteRequest = useMemo(() => {
|
|
157
157
|
return generateGetRelayQuoteRequest({
|
|
158
158
|
orderType: orderType,
|
|
159
|
-
srcChainId: srcChainId,
|
|
160
|
-
srcToken: srcToken,
|
|
159
|
+
srcChainId: activeTab === "fiat" ? base.id : srcChainId,
|
|
160
|
+
srcToken: activeTab === "fiat" ? USDC_BASE : srcToken,
|
|
161
161
|
dstChainId: dstChainId,
|
|
162
162
|
dstToken: dstToken,
|
|
163
163
|
dstAmount: dstAmount,
|
|
@@ -168,12 +168,15 @@ export function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", re
|
|
|
168
168
|
spenderAddress: spenderAddress,
|
|
169
169
|
});
|
|
170
170
|
}, [
|
|
171
|
+
activeTab,
|
|
171
172
|
contractAddress,
|
|
172
173
|
dstAmount,
|
|
173
174
|
dstChainId,
|
|
174
175
|
dstToken,
|
|
175
176
|
encodedData,
|
|
176
|
-
metadata,
|
|
177
|
+
metadata.nftContract.tokenId,
|
|
178
|
+
metadata.nftContract.type,
|
|
179
|
+
metadata.type,
|
|
177
180
|
orderType,
|
|
178
181
|
spenderAddress,
|
|
179
182
|
srcChainId,
|
|
@@ -189,33 +192,25 @@ export function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", re
|
|
|
189
192
|
params.set("orderId", selectedOrderId);
|
|
190
193
|
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
191
194
|
};
|
|
192
|
-
const [srcAmount, setSrcAmount] = useState(null);
|
|
193
|
-
const formattedSrcAmount = srcAmount ? formatUnits(srcAmount.toString(), srcToken.decimals) : null;
|
|
194
|
-
// Get geo data and onramp options (after quote is available)
|
|
195
|
-
const { geoData, isOnrampSupported } = useGeoOnrampOptions(isMainnet, formattedSrcAmount || "0");
|
|
196
|
-
// Update the selected src token to USDC and chain to base when the active tab is fiat,
|
|
197
|
-
// also force not to update srcToken by setting dirtySelectSrcToken to true.
|
|
198
|
-
useEffect(() => {
|
|
199
|
-
if (activeTab === "fiat") {
|
|
200
|
-
setSrcChainId(base.id);
|
|
201
|
-
setSrcToken(USDC_BASE);
|
|
202
|
-
setDirtySelectSrcToken(true);
|
|
203
|
-
}
|
|
204
|
-
}, [activeTab]);
|
|
205
195
|
// Update dependent amount when relay price changes
|
|
206
|
-
|
|
207
|
-
if (anyspendQuote?.data
|
|
208
|
-
anyspendQuote
|
|
209
|
-
anyspendQuote
|
|
210
|
-
|
|
211
|
-
|
|
196
|
+
const srcAmount = useMemo(() => {
|
|
197
|
+
if (!anyspendQuote?.data ||
|
|
198
|
+
!anyspendQuote?.data?.currencyIn?.amount ||
|
|
199
|
+
!anyspendQuote?.data?.currencyIn?.currency?.decimals)
|
|
200
|
+
return null;
|
|
201
|
+
const amount = anyspendQuote.data.currencyIn.amount;
|
|
202
|
+
if (activeTab === "fiat") {
|
|
212
203
|
const roundUpAmount = roundUpUSDCBaseAmountToNearest(amount);
|
|
213
|
-
|
|
204
|
+
return BigInt(roundUpAmount);
|
|
214
205
|
}
|
|
215
206
|
else {
|
|
216
|
-
|
|
207
|
+
return BigInt(amount);
|
|
217
208
|
}
|
|
218
|
-
}, [anyspendQuote?.data]);
|
|
209
|
+
}, [activeTab, anyspendQuote?.data]);
|
|
210
|
+
const formattedSrcAmount = srcAmount ? formatTokenAmount(srcAmount, srcToken.decimals, 6, false) : null;
|
|
211
|
+
const srcFiatAmount = useMemo(() => (activeTab === "fiat" && srcAmount ? formatUnits(srcAmount.toString(), USDC_BASE.decimals) : "0"), [activeTab, srcAmount]);
|
|
212
|
+
// Get geo data and onramp options (after quote is available)
|
|
213
|
+
const { geoData, isOnrampSupported } = useGeoOnrampOptions(isMainnet, srcFiatAmount);
|
|
219
214
|
useEffect(() => {
|
|
220
215
|
if (oat?.data?.order.status === "executed") {
|
|
221
216
|
console.log("Calling onSuccess");
|
|
@@ -249,9 +244,9 @@ export function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", re
|
|
|
249
244
|
const createOrderParams = {
|
|
250
245
|
isMainnet: isMainnet,
|
|
251
246
|
orderType: orderType,
|
|
252
|
-
srcChain: srcChainId,
|
|
247
|
+
srcChain: activeTab === "fiat" ? base.id : srcChainId,
|
|
253
248
|
dstChain: dstChainId,
|
|
254
|
-
srcToken: srcToken,
|
|
249
|
+
srcToken: activeTab === "fiat" ? USDC_BASE : srcToken,
|
|
255
250
|
dstToken: dstToken,
|
|
256
251
|
srcAmount: srcAmount.toString(),
|
|
257
252
|
recipientAddress,
|
|
@@ -300,7 +295,7 @@ export function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", re
|
|
|
300
295
|
invariant(srcChainId === base.id, "Selected src chain is not base");
|
|
301
296
|
void createOnrampOrder({
|
|
302
297
|
...createOrderParams,
|
|
303
|
-
srcFiatAmount:
|
|
298
|
+
srcFiatAmount: srcFiatAmount,
|
|
304
299
|
onramp: {
|
|
305
300
|
vendor: onramp.vendor,
|
|
306
301
|
paymentMethod: onramp.paymentMethod,
|
|
@@ -13,7 +13,6 @@ export function PanelOnrampPayment(props) {
|
|
|
13
13
|
}
|
|
14
14
|
function PanelOnrampPaymentInner(props) {
|
|
15
15
|
const { srcAmountOnRamp, recipientAddress, isMainnet, isBuyMode, destinationTokenChainId, destinationTokenAddress, selectedDstChainId, selectedDstToken, anyspendQuote, globalAddress, onOrderCreated, onBack, orderType, nft, tournament, payload, recipientEnsName, recipientImageUrl, } = props;
|
|
16
|
-
console.log(`PanelOnrampPaymentInner:srcAmountOnRamp`, srcAmountOnRamp);
|
|
17
16
|
const { geoData, coinbaseOnrampOptions, coinbaseAvailablePaymentMethods, isStripeOnrampSupported, stripeWeb2Support, isLoading: isLoadingGeoOnramp, } = useGeoOnrampOptions(isMainnet, srcAmountOnRamp);
|
|
18
17
|
const isLoading = isLoadingGeoOnramp;
|
|
19
18
|
const { createOrder, isCreatingOrder } = useAnyspendCreateOnrampOrder({
|
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
} from "@b3dotfun/sdk/global-account/react";
|
|
39
39
|
import { cn } from "@b3dotfun/sdk/shared/utils";
|
|
40
40
|
import centerTruncate from "@b3dotfun/sdk/shared/utils/centerTruncate";
|
|
41
|
-
import { formatUnits } from "@b3dotfun/sdk/shared/utils/number";
|
|
41
|
+
import { formatTokenAmount, formatUnits } from "@b3dotfun/sdk/shared/utils/number";
|
|
42
42
|
import { simpleHashChainToChainName } from "@b3dotfun/sdk/shared/utils/simplehash";
|
|
43
43
|
import invariant from "invariant";
|
|
44
44
|
import { ChevronRightCircle, Loader2 } from "lucide-react";
|
|
@@ -274,8 +274,8 @@ export function AnySpendCustom({
|
|
|
274
274
|
const getRelayQuoteRequest = useMemo(() => {
|
|
275
275
|
return generateGetRelayQuoteRequest({
|
|
276
276
|
orderType: orderType,
|
|
277
|
-
srcChainId: srcChainId,
|
|
278
|
-
srcToken: srcToken,
|
|
277
|
+
srcChainId: activeTab === "fiat" ? base.id : srcChainId,
|
|
278
|
+
srcToken: activeTab === "fiat" ? USDC_BASE : srcToken,
|
|
279
279
|
dstChainId: dstChainId,
|
|
280
280
|
dstToken: dstToken,
|
|
281
281
|
dstAmount: dstAmount,
|
|
@@ -286,12 +286,15 @@ export function AnySpendCustom({
|
|
|
286
286
|
spenderAddress: spenderAddress,
|
|
287
287
|
});
|
|
288
288
|
}, [
|
|
289
|
+
activeTab,
|
|
289
290
|
contractAddress,
|
|
290
291
|
dstAmount,
|
|
291
292
|
dstChainId,
|
|
292
293
|
dstToken,
|
|
293
294
|
encodedData,
|
|
294
|
-
metadata,
|
|
295
|
+
metadata.nftContract.tokenId,
|
|
296
|
+
metadata.nftContract.type,
|
|
297
|
+
metadata.type,
|
|
295
298
|
orderType,
|
|
296
299
|
spenderAddress,
|
|
297
300
|
srcChainId,
|
|
@@ -310,37 +313,31 @@ export function AnySpendCustom({
|
|
|
310
313
|
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
311
314
|
};
|
|
312
315
|
|
|
313
|
-
const [srcAmount, setSrcAmount] = useState<bigint | null>(null);
|
|
314
|
-
const formattedSrcAmount = srcAmount ? formatUnits(srcAmount.toString(), srcToken.decimals) : null;
|
|
315
|
-
|
|
316
|
-
// Get geo data and onramp options (after quote is available)
|
|
317
|
-
const { geoData, isOnrampSupported } = useGeoOnrampOptions(isMainnet, formattedSrcAmount || "0");
|
|
318
|
-
|
|
319
|
-
// Update the selected src token to USDC and chain to base when the active tab is fiat,
|
|
320
|
-
// also force not to update srcToken by setting dirtySelectSrcToken to true.
|
|
321
|
-
useEffect(() => {
|
|
322
|
-
if (activeTab === "fiat") {
|
|
323
|
-
setSrcChainId(base.id);
|
|
324
|
-
setSrcToken(USDC_BASE);
|
|
325
|
-
setDirtySelectSrcToken(true);
|
|
326
|
-
}
|
|
327
|
-
}, [activeTab]);
|
|
328
|
-
|
|
329
316
|
// Update dependent amount when relay price changes
|
|
330
|
-
|
|
317
|
+
const srcAmount = useMemo(() => {
|
|
331
318
|
if (
|
|
332
|
-
anyspendQuote?.data
|
|
333
|
-
anyspendQuote
|
|
334
|
-
anyspendQuote
|
|
335
|
-
)
|
|
336
|
-
|
|
337
|
-
|
|
319
|
+
!anyspendQuote?.data ||
|
|
320
|
+
!anyspendQuote?.data?.currencyIn?.amount ||
|
|
321
|
+
!anyspendQuote?.data?.currencyIn?.currency?.decimals
|
|
322
|
+
)
|
|
323
|
+
return null;
|
|
324
|
+
|
|
325
|
+
const amount = anyspendQuote.data.currencyIn.amount;
|
|
326
|
+
if (activeTab === "fiat") {
|
|
338
327
|
const roundUpAmount = roundUpUSDCBaseAmountToNearest(amount);
|
|
339
|
-
|
|
328
|
+
return BigInt(roundUpAmount);
|
|
340
329
|
} else {
|
|
341
|
-
|
|
330
|
+
return BigInt(amount);
|
|
342
331
|
}
|
|
343
|
-
}, [anyspendQuote?.data]);
|
|
332
|
+
}, [activeTab, anyspendQuote?.data]);
|
|
333
|
+
const formattedSrcAmount = srcAmount ? formatTokenAmount(srcAmount, srcToken.decimals, 6, false) : null;
|
|
334
|
+
const srcFiatAmount = useMemo(
|
|
335
|
+
() => (activeTab === "fiat" && srcAmount ? formatUnits(srcAmount.toString(), USDC_BASE.decimals) : "0"),
|
|
336
|
+
[activeTab, srcAmount],
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
// Get geo data and onramp options (after quote is available)
|
|
340
|
+
const { geoData, isOnrampSupported } = useGeoOnrampOptions(isMainnet, srcFiatAmount);
|
|
344
341
|
|
|
345
342
|
useEffect(() => {
|
|
346
343
|
if (oat?.data?.order.status === "executed") {
|
|
@@ -383,9 +380,9 @@ export function AnySpendCustom({
|
|
|
383
380
|
const createOrderParams = {
|
|
384
381
|
isMainnet: isMainnet,
|
|
385
382
|
orderType: orderType,
|
|
386
|
-
srcChain: srcChainId,
|
|
383
|
+
srcChain: activeTab === "fiat" ? base.id : srcChainId,
|
|
387
384
|
dstChain: dstChainId,
|
|
388
|
-
srcToken: srcToken,
|
|
385
|
+
srcToken: activeTab === "fiat" ? USDC_BASE : srcToken,
|
|
389
386
|
dstToken: dstToken,
|
|
390
387
|
srcAmount: srcAmount.toString(),
|
|
391
388
|
recipientAddress,
|
|
@@ -438,7 +435,7 @@ export function AnySpendCustom({
|
|
|
438
435
|
invariant(srcChainId === base.id, "Selected src chain is not base");
|
|
439
436
|
void createOnrampOrder({
|
|
440
437
|
...createOrderParams,
|
|
441
|
-
srcFiatAmount:
|
|
438
|
+
srcFiatAmount: srcFiatAmount,
|
|
442
439
|
onramp: {
|
|
443
440
|
vendor: onramp.vendor,
|
|
444
441
|
paymentMethod: onramp.paymentMethod,
|