0xtrails 0.2.5 → 0.2.6
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/abortController.d.ts +8 -0
- package/dist/abortController.d.ts.map +1 -0
- package/dist/{ccip-CXlshvBY.js → ccip-Xjh9d1gb.js} +7 -7
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/fees.d.ts +19 -0
- package/dist/fees.d.ts.map +1 -0
- package/dist/{index-_QuyGrjU.js → index-BnhdZ8Ho.js} +34769 -34247
- package/dist/index.js +726 -520
- package/dist/prepareSend.d.ts +11 -77
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/transactions.d.ts +4 -2
- package/dist/transactions.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
- package/dist/widget/components/AccountSettings.d.ts.map +1 -1
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +2 -2
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
- package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
- package/dist/widget/components/Earn.d.ts +2 -2
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
- package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
- package/dist/widget/components/FeeBreakdown.d.ts +9 -0
- package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
- package/dist/widget/components/Fund.d.ts +2 -2
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundSwap.d.ts +2 -2
- package/dist/widget/components/FundSwap.d.ts.map +1 -1
- package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Identicon.d.ts.map +1 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
- package/dist/widget/components/Modal.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts +2 -2
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +3 -2
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/PoolWithdraw.d.ts +3 -2
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts +1 -0
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +2 -2
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Tooltip.d.ts +9 -0
- package/dist/widget/components/Tooltip.d.ts.map +1 -0
- package/dist/widget/components/WaasFeeOptions.d.ts +1 -0
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useQuote.d.ts +83 -0
- package/dist/widget/hooks/useQuote.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.d.ts +2 -2
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/index.js +2 -2
- package/dist/widget/widget.d.ts +5 -0
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/abortController.ts +35 -0
- package/src/constants.ts +3 -0
- package/src/fees.ts +199 -0
- package/src/prepareSend.ts +225 -398
- package/src/trails.ts +3 -3
- package/src/transactions.ts +62 -18
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
- package/src/widget/components/AccountSettings.tsx +48 -36
- package/src/widget/components/ChainFilterDropdown.tsx +24 -3
- package/src/widget/components/ClassicSwap.tsx +24 -62
- package/src/widget/components/ConnectWallet.tsx +4 -1
- package/src/widget/components/ConnectedWallets.tsx +21 -21
- package/src/widget/components/DynamicInputStyles.tsx +76 -0
- package/src/widget/components/Earn.tsx +34 -29
- package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
- package/src/widget/components/FeeBreakdown.tsx +155 -0
- package/src/widget/components/Fund.tsx +10 -26
- package/src/widget/components/FundSwap.tsx +2 -2
- package/src/widget/components/FundingMethodSelectorButton.tsx +24 -14
- package/src/widget/components/Identicon.tsx +164 -95
- package/src/widget/components/MeshConnectExchanges.tsx +2 -15
- package/src/widget/components/Modal.tsx +0 -12
- package/src/widget/components/Pay.tsx +65 -63
- package/src/widget/components/PoolDeposit.tsx +206 -230
- package/src/widget/components/PoolWithdraw.tsx +219 -238
- package/src/widget/components/PriceImpactWarning.tsx +1 -1
- package/src/widget/components/QuoteDetails.tsx +25 -8
- package/src/widget/components/Receipt.tsx +16 -2
- package/src/widget/components/RecipientSelectorButton.tsx +7 -5
- package/src/widget/components/Recipients.tsx +1 -1
- package/src/widget/components/ScreenHeader.tsx +60 -36
- package/src/widget/components/Swap.tsx +2 -2
- package/src/widget/components/ThemeProvider.tsx +2 -1
- package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
- package/src/widget/components/TokenImage.tsx +1 -1
- package/src/widget/components/TokenSelector.tsx +62 -53
- package/src/widget/components/TokenSelectorButton.tsx +38 -15
- package/src/widget/components/Tooltip.tsx +51 -0
- package/src/widget/components/TransferPendingVertical.tsx +1 -1
- package/src/widget/components/WaasFeeOptions.tsx +124 -5
- package/src/widget/components/WalletConfirmation.tsx +23 -13
- package/src/widget/components/WalletConnect.tsx +93 -29
- package/src/widget/hooks/useQuote.ts +413 -0
- package/src/widget/hooks/useSendForm.ts +8 -4
- package/src/widget/widget.tsx +175 -190
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { X } from "lucide-react"
|
|
2
1
|
import { AnimatePresence, motion } from "motion/react"
|
|
3
2
|
import type React from "react"
|
|
4
3
|
import { useEffect, useRef } from "react"
|
|
@@ -70,17 +69,6 @@ const Modal: React.FC<ModalProps> = ({ isOpen, onClose, children }) => {
|
|
|
70
69
|
layoutId="modal-content"
|
|
71
70
|
layout="preserve-aspect"
|
|
72
71
|
>
|
|
73
|
-
<button
|
|
74
|
-
type="button"
|
|
75
|
-
onClick={onClose}
|
|
76
|
-
className="absolute right-4 top-6 flex h-8 w-8 justify-center items-center rounded-full bg-gray-50 dark:bg-gray-700 cursor-pointer transition-colors text-gray-900 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600 z-20"
|
|
77
|
-
title="Close"
|
|
78
|
-
>
|
|
79
|
-
<X
|
|
80
|
-
className="h-4 w-4"
|
|
81
|
-
style={{ transform: "translate(0, -2px)" }}
|
|
82
|
-
/>
|
|
83
|
-
</button>
|
|
84
72
|
{children}
|
|
85
73
|
</motion.div>
|
|
86
74
|
</div>
|
|
@@ -36,12 +36,13 @@ import { TokenSelectorButton } from "./TokenSelectorButton.js"
|
|
|
36
36
|
import { RequiredPropsError } from "./RequiredPropsError.js"
|
|
37
37
|
import { FundingMethodSelectorButton } from "./FundingMethodSelectorButton.js"
|
|
38
38
|
import { PercentageMaxButtons } from "./PercentageMaxButtons.js"
|
|
39
|
+
import { useDynamicInputStyles } from "./DynamicInputStyles.js"
|
|
39
40
|
|
|
40
41
|
interface PayProps {
|
|
41
42
|
selectedToken?: any // Origin token (optional - user can select)
|
|
42
43
|
onBack?: () => void
|
|
43
|
-
account
|
|
44
|
-
walletClient
|
|
44
|
+
account?: Account
|
|
45
|
+
walletClient?: WalletClient
|
|
45
46
|
onTransactionStateChange: (transactionStates: TransactionState[]) => void
|
|
46
47
|
onError: (error: Error | string | null) => void
|
|
47
48
|
onWaitingForWalletConfirm: (props: PrepareSendQuote) => void
|
|
@@ -162,6 +163,19 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
162
163
|
)
|
|
163
164
|
}, [originToken, filteredTokensFormatted])
|
|
164
165
|
|
|
166
|
+
// Calculate effective recipient for useSendForm
|
|
167
|
+
const effectiveRecipient = useMemo(() => {
|
|
168
|
+
const recipient = selectedRecipient || toRecipient || account?.address
|
|
169
|
+
logger.console.log("[trails-sdk] Effective recipient calculated:", {
|
|
170
|
+
selectedRecipient,
|
|
171
|
+
toRecipient,
|
|
172
|
+
accountAddress: account?.address,
|
|
173
|
+
effectiveRecipient: recipient,
|
|
174
|
+
willPassToUseSendForm: recipient,
|
|
175
|
+
})
|
|
176
|
+
return recipient
|
|
177
|
+
}, [selectedRecipient, toRecipient, account?.address])
|
|
178
|
+
|
|
165
179
|
// Use useSendForm for quote functionality with EXACT_OUTPUT trade type
|
|
166
180
|
const {
|
|
167
181
|
amountUsdDisplay,
|
|
@@ -187,7 +201,7 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
187
201
|
} = useSendForm({
|
|
188
202
|
account,
|
|
189
203
|
toAmount: tokenAmountForBackend || toAmount, // Use the input amount as target amount for EXACT_OUTPUT
|
|
190
|
-
toRecipient:
|
|
204
|
+
toRecipient: effectiveRecipient,
|
|
191
205
|
toChainId,
|
|
192
206
|
toToken,
|
|
193
207
|
toCalldata,
|
|
@@ -288,15 +302,31 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
288
302
|
setSelectedDestinationChain,
|
|
289
303
|
])
|
|
290
304
|
|
|
291
|
-
// Initialize selected recipient from toRecipient prop or default to connected wallet
|
|
305
|
+
// Initialize and update selected recipient from toRecipient prop or default to connected wallet
|
|
306
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: selectedRecipient is intentionally excluded to avoid infinite loops
|
|
292
307
|
useEffect(() => {
|
|
293
|
-
|
|
308
|
+
logger.console.log("[trails-sdk] toRecipient prop effect:", {
|
|
309
|
+
toRecipient,
|
|
310
|
+
selectedRecipient,
|
|
311
|
+
accountAddress: account?.address,
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
if (toRecipient) {
|
|
315
|
+
// Always sync with toRecipient prop when it changes
|
|
316
|
+
logger.console.log(
|
|
317
|
+
"[trails-sdk] Setting selectedRecipient to toRecipient:",
|
|
318
|
+
toRecipient,
|
|
319
|
+
)
|
|
294
320
|
setSelectedRecipient(toRecipient)
|
|
295
321
|
} else if (!selectedRecipient && account?.address) {
|
|
296
322
|
// Default to connected wallet address if no recipient is set
|
|
323
|
+
logger.console.log(
|
|
324
|
+
"[trails-sdk] Setting selectedRecipient to account address:",
|
|
325
|
+
account.address,
|
|
326
|
+
)
|
|
297
327
|
setSelectedRecipient(account.address)
|
|
298
328
|
}
|
|
299
|
-
}, [toRecipient,
|
|
329
|
+
}, [toRecipient, setSelectedRecipient, account?.address])
|
|
300
330
|
|
|
301
331
|
// Initialize and update amount from toAmount prop
|
|
302
332
|
useEffect(() => {
|
|
@@ -425,50 +455,12 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
425
455
|
}, [inputDisplayValue])
|
|
426
456
|
|
|
427
457
|
// Dynamic font size based on input length for destination amount
|
|
428
|
-
const inputStyles =
|
|
429
|
-
const inputLength = displayAmount.length
|
|
430
|
-
let fontSize: string
|
|
431
|
-
|
|
432
|
-
if (inputLength > 12) {
|
|
433
|
-
fontSize = "1rem"
|
|
434
|
-
} else if (inputLength > 9) {
|
|
435
|
-
fontSize = "1.25rem"
|
|
436
|
-
} else if (inputLength > 6) {
|
|
437
|
-
fontSize = "1.5rem"
|
|
438
|
-
} else if (inputLength > 3) {
|
|
439
|
-
fontSize = "1.75rem"
|
|
440
|
-
} else {
|
|
441
|
-
fontSize = "2rem"
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
return {
|
|
445
|
-
fontSize,
|
|
446
|
-
transition: "all 0.1s ease-in-out",
|
|
447
|
-
}
|
|
448
|
-
}, [displayAmount.length])
|
|
458
|
+
const inputStyles = useDynamicInputStyles({ inputValue: displayAmount })
|
|
449
459
|
|
|
450
460
|
// Dynamic font size based on input length for origin amount (Pay with section)
|
|
451
|
-
const originInputStyles =
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (inputLength > 12) {
|
|
456
|
-
fontSize = "1rem"
|
|
457
|
-
} else if (inputLength > 9) {
|
|
458
|
-
fontSize = "1.25rem"
|
|
459
|
-
} else if (inputLength > 6) {
|
|
460
|
-
fontSize = "1.5rem"
|
|
461
|
-
} else if (inputLength > 3) {
|
|
462
|
-
fontSize = "1.75rem"
|
|
463
|
-
} else {
|
|
464
|
-
fontSize = "2rem"
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return {
|
|
468
|
-
fontSize,
|
|
469
|
-
transition: "all 0.1s ease-in-out",
|
|
470
|
-
}
|
|
471
|
-
}, [prepareSendQuote?.originAmountFormatted])
|
|
461
|
+
const originInputStyles = useDynamicInputStyles({
|
|
462
|
+
inputValue: prepareSendQuote?.originAmountFormatted || "",
|
|
463
|
+
})
|
|
472
464
|
|
|
473
465
|
const handleOriginTokenSelect = useCallback(
|
|
474
466
|
(token: any) => {
|
|
@@ -649,7 +641,7 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
649
641
|
const missingRequiredProps = []
|
|
650
642
|
if (!toAmount) missingRequiredProps.push("toAmount")
|
|
651
643
|
if (!toToken) missingRequiredProps.push("toToken")
|
|
652
|
-
if (!toRecipient) missingRequiredProps.push("
|
|
644
|
+
if (!toRecipient) missingRequiredProps.push("toAddress")
|
|
653
645
|
|
|
654
646
|
// Check if this is a payment request (all required props are set)
|
|
655
647
|
const isPaymentRequest = !!(toToken && toAmount && toChainId && toRecipient)
|
|
@@ -694,11 +686,11 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
694
686
|
</div>
|
|
695
687
|
|
|
696
688
|
{/* Origin Token Selection for Payment Request */}
|
|
697
|
-
<div className="
|
|
698
|
-
<div className="
|
|
689
|
+
<div className="mb-4">
|
|
690
|
+
<div className="pt-4 pb-4 trails-bg-secondary trails-border-radius-container p-3 group transition-all duration-200 border border-transparent min-h-[120px] flex flex-col">
|
|
699
691
|
{/* Amount to Pay Label */}
|
|
700
|
-
<div className="flex justify-between items-center
|
|
701
|
-
<div className="text-sm font-medium trails-text-secondary text-left">
|
|
692
|
+
<div className="mb-4 flex justify-between items-center">
|
|
693
|
+
<div className="text-sm font-medium trails-text-secondary text-left m-0">
|
|
702
694
|
Pay with
|
|
703
695
|
{fundMethod === "qr-code"
|
|
704
696
|
? " QR Code"
|
|
@@ -717,7 +709,7 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
717
709
|
ref={paymentRequestInputRef}
|
|
718
710
|
type="text"
|
|
719
711
|
value={prepareSendQuote?.originAmountFormatted || ""}
|
|
720
|
-
placeholder={
|
|
712
|
+
placeholder={"0"}
|
|
721
713
|
readOnly={true}
|
|
722
714
|
className={`w-full bg-transparent font-bold trails-text-primary border-none outline-none ${
|
|
723
715
|
isLoadingQuote ? "animate-pulse" : ""
|
|
@@ -741,9 +733,9 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
741
733
|
</div>
|
|
742
734
|
|
|
743
735
|
{/* Bottom Info Row */}
|
|
744
|
-
<div className="mt-
|
|
736
|
+
<div className="mt-4 flex justify-between items-center">
|
|
745
737
|
{/* USD Amount */}
|
|
746
|
-
<div className="text-xs
|
|
738
|
+
<div className="text-xs text-gray-500 dark:text-gray-400">
|
|
747
739
|
{originToken?.symbol &&
|
|
748
740
|
prepareSendQuote?.originAmountFormatted ? (
|
|
749
741
|
<>≈ {prepareSendQuote?.originAmountUsdDisplay || "$0.00"}</>
|
|
@@ -757,7 +749,7 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
757
749
|
<div className="flex items-center space-x-2">
|
|
758
750
|
<button
|
|
759
751
|
type="button"
|
|
760
|
-
className="text-xs
|
|
752
|
+
className="text-xs text-gray-500 dark:text-gray-400 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 transition-colors bg-transparent border-none p-0"
|
|
761
753
|
onClick={() => {
|
|
762
754
|
if (originTokenBalance.balanceFormatted) {
|
|
763
755
|
const balance = parseFloat(
|
|
@@ -933,10 +925,16 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
933
925
|
|
|
934
926
|
<div className="space-y-1">
|
|
935
927
|
{/* Destination Amount Input Section - Like Fund.tsx but for destination token */}
|
|
936
|
-
<div
|
|
928
|
+
<div
|
|
929
|
+
className={`pt-4 pb-4 trails-bg-secondary trails-border-radius-container p-3 group transition-all duration-200 border border-transparent min-h-[120px] flex flex-col ${
|
|
930
|
+
!toAmount
|
|
931
|
+
? "trails-bg-secondary-hover focus-within:!bg-white dark:focus-within:!bg-gray-800 trails-focus-border-secondary"
|
|
932
|
+
: ""
|
|
933
|
+
}`}
|
|
934
|
+
>
|
|
937
935
|
{/* Amount to Pay Label */}
|
|
938
|
-
<div className="flex justify-between items-center
|
|
939
|
-
<div className="text-sm font-medium trails-text-secondary text-left">
|
|
936
|
+
<div className="mb-4 flex justify-between items-center">
|
|
937
|
+
<div className="text-sm font-medium trails-text-secondary text-left m-0">
|
|
940
938
|
Recipient receives
|
|
941
939
|
</div>
|
|
942
940
|
<FundingMethodSelectorButton />
|
|
@@ -976,9 +974,9 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
976
974
|
</div>
|
|
977
975
|
|
|
978
976
|
{/* Bottom Info Row */}
|
|
979
|
-
<div className="mt-
|
|
977
|
+
<div className="mt-4 flex justify-between items-center">
|
|
980
978
|
{/* USD Amount */}
|
|
981
|
-
<div className="text-xs
|
|
979
|
+
<div className="text-xs text-gray-500 dark:text-gray-400">
|
|
982
980
|
{selectedDestToken?.symbol && displayAmount ? (
|
|
983
981
|
<>≈ {amountUsdDisplay || "$0.00"}</>
|
|
984
982
|
) : (
|
|
@@ -1040,7 +1038,7 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
1040
1038
|
|
|
1041
1039
|
{/* Quote Details */}
|
|
1042
1040
|
{prepareSendQuote && (
|
|
1043
|
-
<div className="
|
|
1041
|
+
<div className="mb-4">
|
|
1044
1042
|
<QuoteDetails quote={prepareSendQuote} showContent={true} />
|
|
1045
1043
|
</div>
|
|
1046
1044
|
)}
|
|
@@ -1067,10 +1065,14 @@ export const Pay: React.FC<PayProps> = ({
|
|
|
1067
1065
|
<Loader2 className="w-5 h-5 animate-spin mr-2" />
|
|
1068
1066
|
<span>{buttonText}</span>
|
|
1069
1067
|
</div>
|
|
1068
|
+
) : !account?.address ? (
|
|
1069
|
+
"Connect your wallet"
|
|
1070
1070
|
) : prepareSendQuote?.noSufficientBalance ? (
|
|
1071
1071
|
"Insufficient Balance"
|
|
1072
1072
|
) : !selectedRecipient ? (
|
|
1073
1073
|
"Select recipient address"
|
|
1074
|
+
) : !originToken ? (
|
|
1075
|
+
"Select payment token"
|
|
1074
1076
|
) : !selectedDestToken ? (
|
|
1075
1077
|
"Select destination token"
|
|
1076
1078
|
) : !tokenAmountForBackend ||
|