@tuwaio/nova-transactions 0.0.23 → 0.0.25
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/README.md +89 -58
- package/dist/{WalletInfoModal-BeE6SSek.d.cts → WalletInfoModal-UEEF9E-5.d.cts} +1 -1
- package/dist/{WalletInfoModal-BeE6SSek.d.ts → WalletInfoModal-UEEF9E-5.d.ts} +1 -1
- package/dist/index.cjs +12 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +10 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/index.cjs +12 -1
- package/dist/providers/index.cjs.map +1 -1
- package/dist/providers/index.d.cts +2 -2
- package/dist/providers/index.d.ts +2 -2
- package/dist/providers/index.js +12 -1
- package/dist/providers/index.js.map +1 -1
- package/package.json +6 -16
package/dist/index.css
CHANGED
@@ -599,6 +599,10 @@
|
|
599
599
|
--tw-shadow: 0 20px 25px -5px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 8px 10px -6px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
|
600
600
|
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
601
601
|
}
|
602
|
+
.outline {
|
603
|
+
outline-style: var(--tw-outline-style);
|
604
|
+
outline-width: 1px;
|
605
|
+
}
|
602
606
|
.transition {
|
603
607
|
transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, backdrop-filter, display, content-visibility, overlay, pointer-events;
|
604
608
|
transition-timing-function: var(--tw-ease, cubic-bezier(0.4, 0, 0.2, 1));
|
@@ -949,6 +953,11 @@
|
|
949
953
|
inherits: false;
|
950
954
|
initial-value: 0 0 #0000;
|
951
955
|
}
|
956
|
+
@property --tw-outline-style {
|
957
|
+
syntax: "*";
|
958
|
+
inherits: false;
|
959
|
+
initial-value: solid;
|
960
|
+
}
|
952
961
|
@property --tw-duration {
|
953
962
|
syntax: "*";
|
954
963
|
inherits: false;
|
@@ -1013,6 +1022,7 @@
|
|
1013
1022
|
--tw-ring-offset-width: 0px;
|
1014
1023
|
--tw-ring-offset-color: #fff;
|
1015
1024
|
--tw-ring-offset-shadow: 0 0 #0000;
|
1025
|
+
--tw-outline-style: solid;
|
1016
1026
|
--tw-duration: initial;
|
1017
1027
|
--tw-ease: initial;
|
1018
1028
|
--tw-scale-x: 1;
|
package/dist/index.d.cts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { T as TuwaLabels } from './WalletInfoModal-
|
2
|
-
export { a as HashLink, H as HashLinkProps, b as StatusAwareText, S as StatusAwareTextProps, o as StepProps, n as StepStatus, e as ToastTransaction, c as ToastTransactionCustomization, d as ToastTransactionProps, h as TrackingTxModal, f as TrackingTxModalCustomization, g as TrackingTxModalProps, v as TransactionHistoryItem, t as TransactionHistoryItemCustomization, u as TransactionHistoryItemProps, x as TransactionKey, w as TransactionKeyProps, C as TransactionStatusBadge, B as TransactionStatusBadgeProps, A as TransactionsHistory, y as TransactionsHistoryCustomization, z as TransactionsHistoryProps, j as TxErrorBlock, i as TxErrorBlockProps, m as TxInfoBlock, k as TxInfoBlockCustomization, l as TxInfoBlockProps, q as TxProgressIndicator, p as TxProgressIndicatorProps, s as TxStatusVisual, r as TxStatusVisualProps, D as WalletAddressDisplay, W as WalletAddressDisplayProps, F as WalletAvatar, E as WalletAvatarProps, I as WalletHeader, G as WalletHeaderProps, L as WalletInfoModal, J as WalletInfoModalCustomization, K as WalletInfoModalProps } from './WalletInfoModal-
|
1
|
+
import { T as TuwaLabels } from './WalletInfoModal-UEEF9E-5.cjs';
|
2
|
+
export { a as HashLink, H as HashLinkProps, b as StatusAwareText, S as StatusAwareTextProps, o as StepProps, n as StepStatus, e as ToastTransaction, c as ToastTransactionCustomization, d as ToastTransactionProps, h as TrackingTxModal, f as TrackingTxModalCustomization, g as TrackingTxModalProps, v as TransactionHistoryItem, t as TransactionHistoryItemCustomization, u as TransactionHistoryItemProps, x as TransactionKey, w as TransactionKeyProps, C as TransactionStatusBadge, B as TransactionStatusBadgeProps, A as TransactionsHistory, y as TransactionsHistoryCustomization, z as TransactionsHistoryProps, j as TxErrorBlock, i as TxErrorBlockProps, m as TxInfoBlock, k as TxInfoBlockCustomization, l as TxInfoBlockProps, q as TxProgressIndicator, p as TxProgressIndicatorProps, s as TxStatusVisual, r as TxStatusVisualProps, D as WalletAddressDisplay, W as WalletAddressDisplayProps, F as WalletAvatar, E as WalletAvatarProps, I as WalletHeader, G as WalletHeaderProps, L as WalletInfoModal, J as WalletInfoModalCustomization, K as WalletInfoModalProps } from './WalletInfoModal-UEEF9E-5.cjs';
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import { Transaction, TransactionPool } from '@tuwaio/pulsar-core';
|
5
5
|
import { ButtonHTMLAttributes, ReactNode } from 'react';
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { T as TuwaLabels } from './WalletInfoModal-
|
2
|
-
export { a as HashLink, H as HashLinkProps, b as StatusAwareText, S as StatusAwareTextProps, o as StepProps, n as StepStatus, e as ToastTransaction, c as ToastTransactionCustomization, d as ToastTransactionProps, h as TrackingTxModal, f as TrackingTxModalCustomization, g as TrackingTxModalProps, v as TransactionHistoryItem, t as TransactionHistoryItemCustomization, u as TransactionHistoryItemProps, x as TransactionKey, w as TransactionKeyProps, C as TransactionStatusBadge, B as TransactionStatusBadgeProps, A as TransactionsHistory, y as TransactionsHistoryCustomization, z as TransactionsHistoryProps, j as TxErrorBlock, i as TxErrorBlockProps, m as TxInfoBlock, k as TxInfoBlockCustomization, l as TxInfoBlockProps, q as TxProgressIndicator, p as TxProgressIndicatorProps, s as TxStatusVisual, r as TxStatusVisualProps, D as WalletAddressDisplay, W as WalletAddressDisplayProps, F as WalletAvatar, E as WalletAvatarProps, I as WalletHeader, G as WalletHeaderProps, L as WalletInfoModal, J as WalletInfoModalCustomization, K as WalletInfoModalProps } from './WalletInfoModal-
|
1
|
+
import { T as TuwaLabels } from './WalletInfoModal-UEEF9E-5.js';
|
2
|
+
export { a as HashLink, H as HashLinkProps, b as StatusAwareText, S as StatusAwareTextProps, o as StepProps, n as StepStatus, e as ToastTransaction, c as ToastTransactionCustomization, d as ToastTransactionProps, h as TrackingTxModal, f as TrackingTxModalCustomization, g as TrackingTxModalProps, v as TransactionHistoryItem, t as TransactionHistoryItemCustomization, u as TransactionHistoryItemProps, x as TransactionKey, w as TransactionKeyProps, C as TransactionStatusBadge, B as TransactionStatusBadgeProps, A as TransactionsHistory, y as TransactionsHistoryCustomization, z as TransactionsHistoryProps, j as TxErrorBlock, i as TxErrorBlockProps, m as TxInfoBlock, k as TxInfoBlockCustomization, l as TxInfoBlockProps, q as TxProgressIndicator, p as TxProgressIndicatorProps, s as TxStatusVisual, r as TxStatusVisualProps, D as WalletAddressDisplay, W as WalletAddressDisplayProps, F as WalletAvatar, E as WalletAvatarProps, I as WalletHeader, G as WalletHeaderProps, L as WalletInfoModal, J as WalletInfoModalCustomization, K as WalletInfoModalProps } from './WalletInfoModal-UEEF9E-5.js';
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import { Transaction, TransactionPool } from '@tuwaio/pulsar-core';
|
5
5
|
import { ButtonHTMLAttributes, ReactNode } from 'react';
|
package/dist/index.js
CHANGED
@@ -1,2 +1,13 @@
|
|
1
|
-
import {ArrowTopRightOnSquareIcon,CheckIcon,DocumentDuplicateIcon,XMarkIcon,ArrowPathIcon,XCircleIcon,CheckCircleIcon,ExclamationTriangleIcon,ClockIcon,ExclamationCircleIcon}from'@heroicons/react/24/solid';import {useCopyToClipboard,cn,textCenterEllipsis}from'@tuwaio/nova-core';import {createContext,useContext,useMemo,useState,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {TransactionStatus,selectAdapterByKey,TransactionTracker,TransactionAdapter,selectAllTransactionsByActiveWallet}from'@tuwaio/pulsar-core';import'react-toastify';import {Web3Icon}from'@bgd-labs/react-web3-icons';import {getChainName}from'@bgd-labs/react-web3-icons/dist/utils';import*as h from'@radix-ui/react-dialog';import {AnimatePresence,motion}from'framer-motion';import Rt from'dayjs';import so from'dayjs/plugin/relativeTime';import No from'ethereum-blockies-base64';import {zeroAddress,isHex}from'viem';var j={walletModal:{title:"Wallet & Transactions",header:{notConnected:"Wallet not connected",avatarAlt:"Avatar for"},history:{title:"Transactions History",connectWalletTitle:"Connect Wallet",connectWalletMessage:"Please connect your wallet to see your past activity.",noTransactionsTitle:"No Transactions Yet",noTransactionsMessage:"Once you interact with the app, your transaction history will appear here."}},toast:{openWalletInfo:"Open wallet info"},statuses:{pending:"Pending",success:"Success",failed:"Failed",reverted:"Reverted",replaced:"Replaced",unknown:"Unknown",confirmationsLabel:"Confirmations"},hashLabels:{gelato:"Gelato Task ID",safe:"Safe Tx Hash",original:"Original Tx Hash",replaced:"Replaced Tx Hash",default:"Tx Hash",recentBlockhash:"Recent Blockhash",solana:"Signature"},txInfo:{started:"Started",network:"Network",slot:"Slot"},txError:{title:"Error",copied:"Copied!"},trackingModal:{title:"Transaction Overview",processing:"Processing...",close:"Close",walletInfo:"Wallet Info",retry:"Retry",progressIndicator:{created:"Created",processing:"Processing",succeed:"Succeed"}},trackedTxButton:{loading:"Processing...",succeed:"Success",failed:"Failed",replaced:"Replaced"},actions:{copy:"Copy address",viewOnExplorer:"View on explorer",close:"Close",cancel:"Cancel",speedUp:"Speed up"}};var qt=createContext(j);var m=()=>useContext(qt);({[TransactionStatus.Success]:"success",[TransactionStatus.Failed]:"error",[TransactionStatus.Replaced]:"info"});function z({label:t,hash:e,explorerUrl:o,variant:r="default",className:s}){let{isCopied:n,copy:i}=useCopyToClipboard(),{actions:c,txError:p}=m(),a=cn("flex items-center justify-between",{"text-sm":r==="default","text-xs":r==="compact"},s),l=cn("pr-1",{"font-bold text-[var(--tuwa-text-primary)]":r==="default","font-medium text-[var(--tuwa-text-secondary)]":r==="compact"}),d=jsx("span",{className:"font-mono",children:textCenterEllipsis(e,5,5)});return jsxs("div",{className:a,children:[t&&jsxs("span",{className:l,children:[t,":"]}),jsxs("div",{className:"flex items-center gap-x-2",children:[o?jsxs("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-x-1 text-[var(--tuwa-text-accent)] transition-colors hover:underline",title:c.viewOnExplorer,"aria-label":c.viewOnExplorer,children:[d,jsx(ArrowTopRightOnSquareIcon,{className:"h-4 w-4"})]}):jsx("span",{className:"text-[var(--tuwa-text-primary)]",children:d}),jsx("button",{type:"button",onClick:()=>i(e),className:"cursor-pointer text-[var(--tuwa-text-tertiary)] transition-colors hover:text-[var(--tuwa-text-secondary)]",title:n?p.copied:c.copy,"aria-label":n?p.copied:c.copy,children:n?jsx(CheckIcon,{className:"h-4 w-4 text-[var(--tuwa-success-icon)]"}):jsx(DocumentDuplicateIcon,{className:"h-4 w-4"})})]})]})}var vt={[TransactionStatus.Success]:{index:1,colorClass:"text-[var(--tuwa-success-text)]"},[TransactionStatus.Failed]:{index:2,colorClass:"text-[var(--tuwa-error-text)]"},[TransactionStatus.Replaced]:{index:3,colorClass:"text-[var(--tuwa-text-secondary)]"},default:{index:0,colorClass:"text-[var(--tuwa-text-primary)]"}};function R({txStatus:t,source:e,fallback:o,variant:r,className:s,applyColor:n=false}){let i,c="";if(typeof e=="string")i=e;else if(Array.isArray(e)){let l=vt[t||"default"]??vt.default;i=e[l.index],n&&(c=l.colorClass);}else i=o;return i?jsx("div",{className:cn(r==="title"?"text-sm font-semibold text-[var(--tuwa-text-primary)]":"mt-1 text-xs text-[var(--tuwa-text-secondary)]",c,s),children:i}):null}function Qt({closeToast:t}){let{actions:e}=m();return jsx("button",{type:"button",onClick:t,"aria-label":e.close,title:e.close,className:cn("absolute top-2 right-2 cursor-pointer rounded-full p-1","text-[var(--tuwa-text-tertiary)] transition-colors","hover:bg-[var(--tuwa-bg-muted)] hover:text-[var(--tuwa-text-primary)]"),children:jsx(XMarkIcon,{className:"h-5 w-5"})})}function O({tx:t,adapter:e,variant:o="toast",className:r,renderHashLink:s,confirmations:n}){let{hashLabels:i,statuses:c}=m(),p=selectAdapterByKey({adapterKey:t.adapter,adapter:e});if(!p)return null;let a=f=>s?s(f):jsx(z,{...f}),l=o==="toast"?"mt-2 flex w-full flex-col gap-y-2 border-t border-[var(--tuwa-border-primary)] pt-2":"flex w-full flex-col gap-y-2",d=i[String(t.tracker)],y=d?a({label:d,hash:t.txKey,variant:t.tracker!==TransactionTracker.Solana?"compact":"default",explorerUrl:p.getExplorerTxUrl&&t.tracker===TransactionTracker.Solana?p?.getExplorerTxUrl(t):void 0}):null,x=(()=>{let f=t.hash,g=t.replacedTxHash;return !f&&!g?null:g?jsxs(Fragment,{children:[f&&a({label:i.original,hash:f,variant:"compact"}),typeof p.getExplorerTxUrl<"u"&&a({label:i.replaced,hash:g,explorerUrl:p.getExplorerTxUrl(t)})]}):f&&typeof p.getExplorerTxUrl<"u"&&a({label:i.default,hash:f,explorerUrl:p.getExplorerTxUrl(t)})})(),T=d&&d!==i.default&&t.txKey!==t.hash;return jsxs("div",{className:cn(l,r),children:[T&&y,x,typeof n=="number"&&jsxs("p",{className:"text-xs text-[var(--tuwa-text-tertiary)]",children:[c.confirmationsLabel,": ",n]})]})}var ve=t=>({Pending:{label:t.pending,Icon:ArrowPathIcon,badgeClasses:"bg-[var(--tuwa-pending-bg)] text-[var(--tuwa-pending-text)]",iconClasses:"animate-spin text-[var(--tuwa-pending-icon)]"},[TransactionStatus.Success]:{label:t.success,Icon:CheckCircleIcon,badgeClasses:"bg-[var(--tuwa-success-bg)] text-[var(--tuwa-success-text)]",iconClasses:"text-[var(--tuwa-success-icon)]"},[TransactionStatus.Failed]:{label:t.failed,Icon:XCircleIcon,badgeClasses:"bg-[var(--tuwa-error-bg)] text-[var(--tuwa-error-text)]",iconClasses:"text-[var(--tuwa-error-icon)]"},[TransactionStatus.Replaced]:{label:t.replaced,Icon:ArrowPathIcon,badgeClasses:"bg-[var(--tuwa-info-bg)] text-[var(--tuwa-info-text)]",iconClasses:"text-[var(--tuwa-info-icon)]"}});function $({tx:t,className:e}){let{statuses:o}=m(),r=useMemo(()=>ve(o),[o]),s="inline-flex items-center gap-x-1.5 rounded-full px-2 py-1 text-xs font-medium",n=t.pending?"Pending":t.status,i=n?r[n]:null;if(!i)return jsx("div",{className:cn(s,"bg-[var(--tuwa-info-bg)] text-[var(--tuwa-info-text)]",e),children:t.status??o.unknown});let{label:c,Icon:p,badgeClasses:a,iconClasses:l}=i;return jsxs("div",{className:cn(s,a,e),children:[jsx(p,{className:cn("h-4 w-4",l)}),c]})}var he=({onClick:t,children:e})=>jsx("button",{onClick:t,type:"button",className:"cursor-pointer text-sm font-medium text-[var(--tuwa-text-accent)] transition-opacity hover:opacity-80",children:e}),Pe=({onClick:t,children:e})=>jsx("button",{onClick:t,type:"button",className:"cursor-pointer text-sm font-medium text-[var(--tuwa-text-secondary)] transition-opacity hover:opacity-80",children:e}),Ne=({onClick:t,children:e})=>jsx("button",{className:"cursor-pointer rounded-md bg-gradient-to-r from-[var(--tuwa-button-gradient-from)] to-[var(--tuwa-button-gradient-to)] px-3 py-1 text-xs font-bold text-[var(--tuwa-text-on-accent)] shadow-lg transition-all duration-200 ease-in-out hover:shadow-xl hover:from-[var(--tuwa-button-gradient-from-hover)] hover:to-[var(--tuwa-button-gradient-to-hover)] active:scale-95",onClick:t,type:"button",children:e});function jt({openWalletInfoModal:t,tx:e,icon:o,className:r,customization:s,connectedWalletAddress:n,adapter:i}){let{actions:c,toast:p}=m(),a=selectAdapterByKey({adapterKey:e.adapter,adapter:i}),l=!!(e.tracker==="ethereum"&&e.pending&&a?.speedUpTxAction&&a?.cancelTxAction&&e.from.toLowerCase()===n?.toLowerCase()),d=()=>{l&&a.cancelTxAction(e);},y=()=>{l&&a.speedUpTxAction(e);},{StatusAwareText:x=R,TransactionKey:T=O,StatusBadge:f=$,SpeedUpButton:g=he,CancelButton:I=Pe,WalletInfoButton:v=Ne}=s?.components??{};return jsxs("div",{className:cn("flex w-full flex-col gap-3 rounded-lg bg-[var(--tuwa-bg-primary)] p-4 shadow-md",r),children:[jsxs("div",{className:"flex items-start gap-3",children:[jsx("div",{className:"w-[40px] flex-shrink-0",title:getChainName(e.chainId),children:o??jsx(Web3Icon,{chainId:e.chainId})}),jsxs("div",{className:"flex-1",children:[jsx(x,{txStatus:e.status,source:e.title,fallback:e.type,variant:"title",applyColor:true}),jsx(x,{txStatus:e.status,source:e.description,variant:"description"})]})]}),jsxs("div",{children:[jsx(T,{adapter:i,tx:e,variant:"toast"}),jsxs("div",{className:"mt-3 flex items-center justify-between",children:[jsx(f,{tx:e}),l?jsxs("div",{className:"flex items-center gap-4",children:[jsx(g,{onClick:y,children:c.speedUp}),jsx(I,{onClick:d,children:c.cancel})]}):t&&!!n&&jsx(v,{onClick:t,children:p.openWalletInfo})]})]})]})}function Ct({error:t,className:e}){let{isCopied:o,copy:r}=useCopyToClipboard(),{actions:s,txError:n}=m();return t?jsxs("div",{className:cn("rounded-lg border border-[var(--tuwa-error-icon)]/30 bg-[var(--tuwa-error-bg)] p-3 text-sm",e),children:[jsxs("div",{className:"mb-2 flex items-center justify-between",children:[jsxs("div",{className:"flex items-center gap-2 font-bold text-[var(--tuwa-error-icon)]",children:[jsx(ExclamationTriangleIcon,{className:"h-5 w-5"}),jsx("span",{children:n.title})]}),jsx("button",{type:"button",onClick:()=>r(t),title:o?n.copied:s.copy,"aria-label":o?n.copied:`${s.copy} error message`,className:"cursor-pointer text-[var(--tuwa-error-icon)]/50 transition-colors hover:text-[var(--tuwa-error-icon)]",children:o?jsx(CheckIcon,{className:"h-5 w-5 text-[var(--tuwa-success-icon)]"}):jsx(DocumentDuplicateIcon,{className:"h-5 w-5"})})]}),jsx("div",{className:"max-h-24 overflow-y-auto rounded bg-[var(--tuwa-bg-primary)] p-2",children:jsx("p",{className:"font-mono text-xs text-[var(--tuwa-error-text)] break-all",children:t})})]}):null}function We({label:t,value:e}){return jsxs("div",{className:"flex items-center justify-between text-sm",children:[jsx("span",{className:"text-[var(--tuwa-text-secondary)]",children:t}),jsx("span",{className:"font-medium text-[var(--tuwa-text-primary)]",children:e})]})}function ht({tx:t,adapter:e,className:o,customization:r}){let{txInfo:s,statuses:n,hashLabels:i}=m(),c=selectAdapterByKey({adapterKey:t.adapter,adapter:e});if(!c)return null;let{InfoRow:p=We}=r?.components??{},a="chainId"in t?t.chainId:t.desiredChainID,l=t.adapter===TransactionAdapter.SOLANA,d=l?t:void 0;return jsxs("div",{className:cn("flex flex-col gap-3 rounded-lg border border-[var(--tuwa-border-primary)] bg-[var(--tuwa-bg-primary)] p-3",o),children:[jsx(p,{label:s.network,value:jsxs("div",{className:"flex items-center justify-end gap-2",children:[jsx("div",{className:"h-4 w-4",children:jsx(Web3Icon,{chainId:a})}),jsx("span",{children:getChainName(a)})]})}),t.localTimestamp&&jsx(p,{label:s.started,value:Rt.unix(t.localTimestamp).format("MMM D, HH:mm:ss")}),l&&jsxs(Fragment,{children:[d?.slot&&jsx(p,{label:s.slot,value:jsx(z,{hash:d.slot.toString(),explorerUrl:c?.getExplorerUrl?`${c?.getExplorerUrl(`/block/${d.slot}`)}`:void 0})}),(typeof d?.confirmations=="number"||typeof d?.confirmations=="string")&&jsx(p,{label:n.confirmationsLabel,value:d.confirmations}),d?.recentBlockhash&&jsx(p,{label:i.recentBlockhash,value:jsx(z,{hash:d.recentBlockhash})})]}),"txKey"in t&&t.txKey&&jsx("div",{className:"border-t border-[var(--tuwa-border-primary)] pt-3",children:jsx(O,{tx:t,adapter:e,variant:"history",renderHashLink:r?.components?.transactionKey})})]})}var Ve={completed:{line:"bg-[var(--tuwa-success-icon)]",border:"border-[var(--tuwa-success-icon)]",fill:"bg-[var(--tuwa-success-icon)]"},error:{line:"bg-[var(--tuwa-error-icon)]",border:"border-[var(--tuwa-error-icon)]",fill:"bg-[var(--tuwa-error-icon)]"},replaced:{line:"bg-[var(--tuwa-info-icon)]",border:"border-[var(--tuwa-info-icon)]",fill:"bg-[var(--tuwa-info-icon)]"},active:{line:"bg-[var(--tuwa-pending-icon)]",border:"border-[var(--tuwa-pending-icon)]",fill:"bg-transparent",pulse:"bg-[var(--tuwa-pending-icon)]"},inactive:{line:"bg-[var(--tuwa-border-primary)]",border:"border-[var(--tuwa-border-primary)]",fill:"bg-transparent"}};function _e({status:t,label:e,isFirst:o=false}){let r=Ve[t],s=()=>{switch(t){case "completed":return jsx(CheckIcon,{className:"h-3 w-3 text-white"});case "error":return jsx(ExclamationTriangleIcon,{className:"h-3 w-3 text-white"});case "replaced":return jsx(ArrowPathIcon,{className:"h-3 w-3 text-white"});case "active":return jsx("div",{className:cn("h-2 w-2 animate-pulse rounded-full",r.pulse)});default:return null}};return jsxs("div",{className:"relative flex min-w-[80px] flex-1 flex-col items-center",children:[!o&&jsx("div",{className:cn("absolute right-1/2 top-[10px] h-0.5 w-full",r.line)}),jsx("div",{className:cn("relative z-10 flex h-5 w-5 items-center justify-center rounded-full border-2",r.border,r.fill),children:s()}),jsx("span",{className:cn("mt-2 text-center text-xs",t!=="inactive"?"font-semibold text-[var(--tuwa-text-primary)]":"text-[var(--tuwa-text-secondary)]"),children:e})]})}function Pt({isProcessing:t,isSucceed:e,isFailed:o,isReplaced:r,className:s,StepComponent:n=_e}){let{trackingModal:i,statuses:c}=m(),p=useMemo(()=>{let a=d=>{if(d===1)return "completed";if(d===2){if(e||o||r)return "completed";if(t)return "active"}if(d===3){if(e)return "completed";if(o)return "error";if(r)return "replaced";if(t)return "active"}return "inactive"},l=d=>d===1?i.progressIndicator.created:d===2?i.progressIndicator.processing:o?c.failed:r?c.replaced:i.progressIndicator.succeed;return [{status:a(1),label:l(1),isFirst:true},{status:a(2),label:l(2)},{status:a(3),label:l(3),isLast:true}]},[t,e,o,r,i,c]);return jsx("div",{className:cn("flex w-full items-start px-4 pt-2 pb-1",s),children:p.map((a,l)=>jsx(n,{...a},l))})}var qe={succeed:{Icon:CheckCircleIcon,className:"text-[var(--tuwa-success-icon)]"},failed:{Icon:ExclamationCircleIcon,className:"text-[var(--tuwa-error-icon)]"},replaced:{Icon:ArrowPathIcon,className:"text-[var(--tuwa-info-icon)]"},processing:{Icon:ArrowPathIcon,className:"animate-spin text-[var(--tuwa-text-accent)]"},initializing:{Icon:ClockIcon,className:"animate-pulse text-[var(--tuwa-pending-icon)]"}};function kt({isProcessing:t,isSucceed:e,isFailed:o,isReplaced:r}){let s=e&&"succeed"||o&&"failed"||r&&"replaced"||t&&"processing"||"initializing",{Icon:n,className:i}=qe[s];return jsx("div",{className:"flex justify-center py-4",children:jsx(n,{className:cn("h-16 w-16",i)})})}function Zt({adapter:t,onClose:e,onOpenWalletInfo:o,className:r,customization:s,transactionsPool:n,handleTransaction:i,initialTx:c,connectedWalletAddress:p}){let a=useMemo(()=>c?.lastTxKey?n[c.lastTxKey]:void 0,[n,c]),l=a??c,d=c?.withTrackedModal&&!a||(a?.isTrackedModalOpen??false),{isProcessing:y,isSucceed:x,isFailed:T,isReplaced:f}=useMemo(()=>{let W=a?.status,$t=c?.isInitializing??false,Jt=a?.pending??false;return {isProcessing:$t||Jt,isSucceed:W===TransactionStatus.Success,isFailed:a?.isError||!!c?.errorMessage,isReplaced:W===TransactionStatus.Replaced}},[a,c]),g=useMemo(()=>l?selectAdapterByKey({adapterKey:l.adapter,adapter:t}):void 0,[l,t]),I=!!(T&&l&&c?.actionFunction&&i),v=!!(g?.speedUpTxAction&&g?.cancelTxAction&&a?.pending&&a.tracker==="ethereum"),K=()=>{if(!I||!g?.retryTxAction)return;let W={adapter:l.adapter,type:l.type,desiredChainID:"desiredChainID"in l?l.desiredChainID:l.chainId,actionFunction:c?.actionFunction,title:l.title,description:l.description,payload:l.payload,withTrackedModal:true};g.retryTxAction({tx:W,txKey:a?.txKey??"",onClose:e,handleTransaction:i});},k=()=>{v&&a&&g.cancelTxAction(a);},B=()=>{v&&a&&g.speedUpTxAction(a);},_=s?.components?.Header,dt=s?.components?.Footer,ut=s?.components?.StatusVisual,mt=s?.components?.ProgressIndicator,ft=s?.components?.InfoBlock,xt=s?.components?.ErrorBlock,Xt={initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.2,ease:"easeOut"},...s?.motionProps};return l?jsx(h.Root,{open:d,onOpenChange:W=>!W&&e(a?.txKey),children:jsx(h.Portal,{children:jsx(AnimatePresence,{children:d&&jsxs(Fragment,{children:[jsx(h.Overlay,{asChild:true,children:jsx(motion.div,{className:"fixed inset-0 z-50 bg-black/60",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0}})}),jsx(h.Content,{className:"fixed left-1/2 top-1/2 z-50 w-full max-w-md -translate-x-1/2 -translate-y-1/2 outline-none",...s?.modalProps,asChild:true,children:jsx(motion.div,{...Xt,children:jsxs("div",{className:cn("relative flex max-h-[98dvh] w-full flex-col gap-3 overflow-y-auto rounded-2xl bg-[var(--tuwa-bg-primary)] p-5 pt-0 shadow-2xl",r),children:[_?jsx(_,{onClose:()=>e(a?.txKey),title:jsx(Mt,{tx:l})}):jsx(eo,{onClose:()=>e(a?.txKey),title:jsx(Mt,{tx:l})}),jsxs("main",{className:"flex flex-col gap-3",children:[ut?jsx(ut,{isProcessing:y,isSucceed:x,isFailed:T,isReplaced:f}):jsx(kt,{isProcessing:y,isSucceed:x,isFailed:T,isReplaced:f}),mt?jsx(mt,{isProcessing:y,isSucceed:x,isFailed:T,isReplaced:f}):jsx(Pt,{isProcessing:y,isSucceed:x,isFailed:T,isReplaced:f}),ft?jsx(ft,{tx:l,adapter:t}):jsx(ht,{tx:l,adapter:t}),xt?jsx(xt,{error:a?.errorMessage||c?.errorMessage}):jsx(Ct,{error:a?.errorMessage||c?.errorMessage})]}),dt?jsx(dt,{onClose:()=>e(a?.txKey),onOpenWalletInfo:o,isProcessing:y,isFailed:T,canReplace:v,onRetry:I?K:void 0,onSpeedUp:v?B:void 0,onCancel:v?k:void 0,connectedWalletAddress:p}):jsx(oo,{onClose:()=>e(a?.txKey),onOpenWalletInfo:o,isProcessing:y,isFailed:T,canReplace:v,onRetry:I?K:void 0,onSpeedUp:v?B:void 0,onCancel:v?k:void 0,connectedWalletAddress:p})]})})})]})})})}):null}function Mt({tx:t}){return jsx(R,{txStatus:"status"in t?t.status:void 0,source:t.title,fallback:t.type,variant:"title",className:"text-lg"})}var eo=({onClose:t,title:e})=>{let{actions:o}=m();return jsxs("header",{className:"sticky top-0 z-10 flex w-full items-start justify-between bg-[var(--tuwa-bg-primary)] pt-5 pb-2",children:[jsx(h.Title,{children:e}),jsx(h.Close,{asChild:true,children:jsx("button",{type:"button",onClick:()=>t(),"aria-label":o.close,className:"cursor-pointer -mt-1 ml-2 rounded-full p-1 text-[var(--tuwa-text-tertiary)] transition-colors hover:bg-[var(--tuwa-bg-muted)] hover:text-[var(--tuwa-text-primary)]",children:jsx(XMarkIcon,{className:"h-5 w-5"})})})]})},oo=({onClose:t,onOpenWalletInfo:e,isProcessing:o,onRetry:r,onSpeedUp:s,onCancel:n,canReplace:i,isFailed:c,connectedWalletAddress:p})=>{let{trackingModal:a,actions:l}=m(),d=()=>c&&r?jsx("button",{type:"button",onClick:r,className:"cursor-pointer rounded-md bg-[var(--tuwa-button-gradient-from)] px-4 py-2 text-sm font-semibold text-[var(--tuwa-text-on-accent)] transition-opacity hover:opacity-90",children:a.retry}):!o&&!i&&p?jsx("button",{type:"button",onClick:e,className:"cursor-pointer rounded-md bg-[var(--tuwa-bg-muted)] px-4 py-2 text-sm font-semibold text-[var(--tuwa-text-primary)] transition-colors hover:bg-[var(--tuwa-border-primary)]",children:a.walletInfo}):null;return jsxs("footer",{className:"mt-2 flex w-full items-center justify-between border-t border-[var(--tuwa-border-primary)] pt-4",children:[jsx("div",{className:"flex items-center gap-4",children:i&&s&&n&&jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:s,className:"cursor-pointer text-sm font-medium text-[var(--tuwa-text-accent)] transition-opacity hover:opacity-80",children:l.speedUp}),jsx("button",{type:"button",onClick:n,className:"cursor-pointer text-sm font-medium text-[var(--tuwa-text-secondary)] transition-opacity hover:opacity-80",children:l.cancel})]})}),jsxs("div",{className:"flex items-center gap-3",children:[jsx(d,{}),jsx("button",{type:"button",onClick:t,disabled:o&&!i,className:"cursor-pointer rounded-md bg-[var(--tuwa-bg-muted)] px-4 py-2 text-sm font-semibold text-[var(--tuwa-text-primary)] transition-colors hover:bg-[var(--tuwa-border-primary)] disabled:cursor-not-allowed disabled:opacity-50",children:o&&!i?a.processing:a.close})]})]})};Rt.extend(so);var no=({chainId:t})=>jsx("div",{className:"h-8 w-8 text-[var(--tuwa-text-secondary)]",children:jsx(Web3Icon,{chainId:t})}),io=({timestamp:t})=>jsx("span",{className:"mb-1 block text-xs text-[var(--tuwa-text-secondary)]",children:t?Rt.unix(t).fromNow():"..."});function Lt({tx:t,adapter:e,className:o,customization:r}){let{Icon:s=no,Title:n=R,Description:i=R,Timestamp:c=io,StatusBadge:p=$,TransactionKey:a=O}=r?.components??{};return jsxs("div",{className:cn("flex flex-col gap-2 border-b border-[var(--tuwa-border-secondary)] p-3 transition-colors hover:bg-[var(--tuwa-bg-secondary)]",o),children:[jsxs("div",{className:"flex items-start justify-between",children:[jsxs("div",{className:"flex items-center gap-4",children:[jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-[var(--tuwa-bg-muted)]",children:jsx(s,{chainId:t.chainId})}),jsxs("div",{children:[jsx(n,{txStatus:t.status,source:t.title,fallback:t.type,variant:"title",applyColor:true}),jsx(c,{timestamp:t.localTimestamp}),jsx(i,{txStatus:t.status,source:t.description,variant:"description"})]})]}),jsx(p,{tx:t})]}),jsx(a,{tx:t,adapter:e,variant:"history"})]})}function po({title:t,message:e,className:o}){return jsxs("div",{className:cn("rounded-lg bg-[var(--tuwa-bg-muted)] p-8 text-center",o),children:[jsx("h4",{className:"font-semibold text-[var(--tuwa-text-primary)]",children:t}),jsx("p",{className:"mt-1 text-sm text-[var(--tuwa-text-secondary)]",children:e})]})}function Ht({adapter:t,connectedWalletAddress:e,transactionsPool:o,className:r,customization:s}){let{walletModal:n}=m(),i=useMemo(()=>e?selectAllTransactionsByActiveWallet(o,e).sort((d,y)=>(y.localTimestamp??0)-(d.localTimestamp??0)):[],[o,e]),{Placeholder:c=po,HistoryItem:p=Lt}=s?.components??{},a=()=>e?i.length>0?jsx("div",{className:cn("max-h-[400px] overflow-y-auto rounded-lg border border-[var(--tuwa-border-primary)] bg-[var(--tuwa-bg-primary)]",s?.classNames?.listWrapper),children:i.map(l=>jsx(p,{tx:l,adapter:t},l.txKey))}):jsx(c,{title:n.history.noTransactionsTitle,message:n.history.noTransactionsMessage}):jsx(c,{title:n.history.connectWalletTitle,message:n.history.connectWalletMessage});return jsxs("div",{className:cn("flex flex-col gap-y-3",r),children:[jsx("h3",{className:"text-lg font-bold text-[var(--tuwa-text-primary)]",children:n.history.title}),a()]})}var To=t=>({replaced:jsxs(Fragment,{children:[jsx(ArrowPathIcon,{className:"h-4 w-4"}),jsx("span",{children:t.replaced})]}),loading:jsxs(Fragment,{children:[jsx(ArrowPathIcon,{className:"h-4 w-4 animate-spin"}),jsx("span",{children:t.loading})]}),succeed:jsxs(Fragment,{children:[jsx(CheckCircleIcon,{className:"h-4 w-4"}),jsx("span",{children:t.succeed})]}),failed:jsxs(Fragment,{children:[jsx(ExclamationCircleIcon,{className:"h-4 w-4"}),jsx("span",{children:t.failed})]})});function pn({children:t,action:e,getLastTxKey:o,transactionsPool:r,walletAddress:s,loadingContent:n,succeedContent:i,failedContent:c,replacedContent:p,resetTimeout:a=2500,className:l,...d}){let{trackedTxButton:y}=m(),[x,T]=useState("idle"),[f,g]=useState(void 0),I=useMemo(()=>To(y),[y]);useEffect(()=>{T("idle"),g(void 0);},[s]),useEffect(()=>{if(!f)return;let k=r[f];if(k)switch(k.status){case TransactionStatus.Success:T("succeed");break;case TransactionStatus.Replaced:T("replaced");break;case TransactionStatus.Failed:T("failed");break}},[r,f,s]),useEffect(()=>{if(["succeed","failed","replaced"].includes(x)){let k=setTimeout(()=>{T("idle"),g(void 0);},a);return ()=>clearTimeout(k)}},[x,a]);let v=async()=>{T("loading");try{await e(),g(o());}catch(k){console.error("Transaction initiation failed:",k),T("failed");}},K=()=>{switch(x){case "loading":return n??I.loading;case "succeed":return i??I.succeed;case "failed":return c??I.failed;case "replaced":return p??I.replaced;default:return t}};return jsx("button",{...d,disabled:x!=="idle"||d.disabled,onClick:v,className:cn("flex cursor-pointer items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-70",{"bg-gradient-to-r from-[var(--tuwa-button-gradient-from)] to-[var(--tuwa-button-gradient-to)] text-[var(--tuwa-text-on-accent)] hover:opacity-90":x==="idle","bg-gray-400 text-white":x==="loading","bg-gray-500 text-white":x==="replaced","bg-[var(--tuwa-success-bg)] text-[var(--tuwa-success-text)]":x==="succeed","bg-[var(--tuwa-error-bg)] text-[var(--tuwa-error-text)]":x==="failed"},l),children:K()})}function ct({address:t,explorerUrl:e,className:o}){let{isCopied:r,copy:s}=useCopyToClipboard(),{actions:n,txError:i}=m();return jsxs("div",{className:cn("flex items-center gap-x-3 rounded-full bg-[var(--tuwa-bg-muted)] px-3 py-1 font-mono text-xs text-[var(--tuwa-text-secondary)]",o),children:[jsx("span",{children:textCenterEllipsis(t,6,6)}),jsx("button",{type:"button",title:r?i.copied:n.copy,"aria-label":r?i.copied:`${n.copy} address`,onClick:()=>s(t),className:"cursor-pointer transition-colors hover:text-[var(--tuwa-text-primary)]",children:r?jsx(CheckIcon,{className:"h-4 w-4 text-[var(--tuwa-success-icon)]"}):jsx(DocumentDuplicateIcon,{className:"h-4 w-4"})}),e&&jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"transition-colors hover:text-[var(--tuwa-text-accent)]",title:n.viewOnExplorer,"aria-label":n.viewOnExplorer,children:jsx(ArrowTopRightOnSquareIcon,{className:"h-4 w-4"})})]})}function Ut({address:t,ensAvatar:e,className:o}){let{walletModal:r}=m(),[s,n]=useState(e),i=useMemo(()=>No(isHex(t)?t:zeroAddress),[t]),c=useMemo(()=>`#${t.slice(2,8)}`,[t]);useEffect(()=>{n(e);},[e]);let p=()=>{n(i);};return jsx("div",{className:cn("h-12 w-12 flex-shrink-0 rounded-full",o),style:{backgroundColor:c},children:jsx("img",{className:"h-full w-full rounded-full object-cover",src:s||i,alt:`${r.header.avatarAlt} ${t}`,onError:p},e)})}var Lo=({isLoading:t,ensName:e,walletAddress:o,explorerUrl:r,renderAddressDisplay:s})=>jsxs("div",{className:"flex flex-col",children:[jsx("div",{className:"mb-1.5 flex h-7 items-center",children:t?jsx("div",{className:"h-full w-48 animate-pulse rounded-md bg-[var(--tuwa-bg-muted)]"}):e?jsx("h2",{className:"text-xl font-bold text-[var(--tuwa-text-primary)]",children:e}):jsx(ct,{address:o,explorerUrl:r,className:"rounded-none bg-transparent px-0 py-0 text-xl font-bold text-[var(--tuwa-text-primary)]"})}),jsx("div",{className:"flex h-5 items-center",children:!t&&e&&(s?s({address:o,explorerUrl:r}):jsx(ct,{address:o,explorerUrl:r}))})]});function zt({walletAddress:t,adapter:e,connectedAdapterType:o,className:r,renderAvatar:s,renderName:n,renderAddressDisplay:i,renderNoWalletContent:c,explorerUrl:p}){let{walletModal:a}=m(),[l,d]=useState(null),[y,x]=useState(null),[T,f]=useState(true);if(useEffect(()=>{(async()=>{if(!t||!o){f(false);return}let v=selectAdapterByKey({adapterKey:o,adapter:e}),K=v&&"getName"in v&&typeof v.getName=="function",k=v&&"getAvatar"in v&&typeof v.getAvatar=="function";if(!K){f(false);return}f(true),d(null),x(null);try{let B=v?.getName?await v.getName(t):null;if(B&&(d(B),k)){let _=v?.getAvatar?await v.getAvatar(B):null;x(_);}}catch(B){console.error("Failed to fetch name service data:",B);}finally{f(false);}})();},[t,e,o]),!t)return c?jsx(Fragment,{children:c()}):jsx("div",{className:cn("flex h-20 items-center justify-center rounded-lg bg-[var(--tuwa-bg-muted)] text-[var(--tuwa-text-secondary)]",r),children:a.header.notConnected});let g=l?l.length>30?textCenterEllipsis(l,12,12):l:void 0;return jsxs("div",{className:cn("flex min-h-[4rem] items-center gap-4",r),children:[jsx("div",{children:s?s({address:t,ensAvatar:y}):jsx(Ut,{address:t,ensAvatar:y})}),jsx("div",{className:"flex min-h-[3.5rem] min-w-[200px] flex-col justify-center",children:n?n({ensName:g,isLoading:T,address:t}):jsx(Lo,{isLoading:T,ensName:g,walletAddress:t,explorerUrl:p,renderAddressDisplay:i})})]})}var Uo=({closeModal:t,title:e})=>{let{actions:o}=m();return jsxs("div",{className:"sticky top-0 left-0 z-10 flex w-full items-center justify-between border-b border-[var(--tuwa-border-primary)] bg-[var(--tuwa-bg-secondary)] p-4",children:[jsx(h.Title,{className:"text-lg font-bold text-[var(--tuwa-text-primary)]",children:e}),jsx(h.Close,{asChild:true,children:jsx("button",{type:"button",onClick:t,"aria-label":o.close,className:"cursor-pointer rounded-full p-1 text-[var(--tuwa-text-tertiary)] transition-colors hover:bg-[var(--tuwa-bg-muted)] hover:text-[var(--tuwa-text-primary)]",children:jsx(XMarkIcon,{className:"h-6 w-6"})})})]})};function te({isOpen:t,setIsOpen:e,customization:o,adapter:r,connectedAdapterType:s,connectedWalletAddress:n,transactionsPool:i}){let{walletModal:c}=m(),{explorerUrl:p}=useMemo(()=>s?{explorerUrl:selectAdapterByKey({adapterKey:s,adapter:r})?.getExplorerUrl(`/address/${n}`)}:{explorerUrl:void 0},[s,r,n]),a=()=>e(false),d={...{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.2,ease:"easeOut"}},...o?.motionProps},y=o?.components?.Header,x=o?.components?.WalletInfo,T=o?.components?.History;return jsx(h.Root,{open:t,onOpenChange:f=>!f&&a(),children:jsx(h.Portal,{children:jsx(AnimatePresence,{children:t&&jsxs(Fragment,{children:[jsx(h.Overlay,{asChild:true,children:jsx(motion.div,{className:"fixed inset-0 z-50 bg-black/45",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15}})}),jsx(h.Content,{className:"fixed left-1/2 top-1/2 z-50 w-full max-w-2xl -translate-x-1/2 -translate-y-1/2 outline-none",...o?.modalProps,asChild:true,children:jsx(motion.div,{...d,children:jsxs("div",{className:cn("relative max-h-[98dvh] w-full max-w-2xl overflow-y-auto rounded-2xl bg-[var(--tuwa-bg-secondary)] shadow-xl outline-none",o?.classNames?.contentWrapper),children:[y?jsx(y,{closeModal:a}):jsx(Uo,{closeModal:a,title:c.title}),jsxs("div",{className:"flex flex-col gap-4 p-4 sm:gap-6 sm:p-6",children:[x?jsx(x,{adapter:r,connectedAdapterType:s,walletAddress:n,explorerUrl:p}):jsx(zt,{adapter:r,connectedAdapterType:s,walletAddress:n,explorerUrl:p}),T?jsx(T,{adapter:r,transactionsPool:i,connectedWalletAddress:n}):jsx(Ht,{adapter:r,transactionsPool:i,connectedWalletAddress:n})]})]})})})]})})})})}export{z as HashLink,R as StatusAwareText,Qt as ToastCloseButton,jt as ToastTransaction,Zt as TrackingTxModal,Lt as TransactionHistoryItem,O as TransactionKey,$ as TransactionStatusBadge,Ht as TransactionsHistory,pn as TxActionButton,Ct as TxErrorBlock,ht as TxInfoBlock,Pt as TxProgressIndicator,kt as TxStatusVisual,ct as WalletAddressDisplay,Ut as WalletAvatar,zt as WalletHeader,te as WalletInfoModal,j as defaultLabels};//# sourceMappingURL=index.js.map
|
1
|
+
import {ArrowTopRightOnSquareIcon,CheckIcon,DocumentDuplicateIcon,XMarkIcon,ArrowPathIcon,XCircleIcon,CheckCircleIcon,ExclamationTriangleIcon,ClockIcon,ExclamationCircleIcon}from'@heroicons/react/24/solid';import {useCopyToClipboard,cn,textCenterEllipsis}from'@tuwaio/nova-core';import {createContext,useContext,useMemo,useState,useEffect}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {TransactionStatus,selectAdapterByKey,TransactionTracker,TransactionAdapter,selectAllTransactionsByActiveWallet}from'@tuwaio/pulsar-core';import'react-toastify';import {Web3Icon}from'@bgd-labs/react-web3-icons';import {getChainName}from'@bgd-labs/react-web3-icons/dist/utils';import*as C from'@radix-ui/react-dialog';import {AnimatePresence,motion}from'framer-motion';import Wt from'dayjs';import co from'dayjs/plugin/relativeTime';import Ao from'ethereum-blockies-base64';var ot={walletModal:{title:"Wallet & Transactions",header:{notConnected:"Wallet not connected",avatarAlt:"Avatar for"},history:{title:"Transactions History",connectWalletTitle:"Connect Wallet",connectWalletMessage:"Please connect your wallet to see your past activity.",noTransactionsTitle:"No Transactions Yet",noTransactionsMessage:"Once you interact with the app, your transaction history will appear here."}},toast:{openWalletInfo:"Open wallet info"},statuses:{pending:"Pending",success:"Success",failed:"Failed",reverted:"Reverted",replaced:"Replaced",unknown:"Unknown",confirmationsLabel:"Confirmations"},hashLabels:{gelato:"Gelato Task ID",safe:"Safe Tx Hash",original:"Original Tx Hash",replaced:"Replaced Tx Hash",default:"Tx Hash",recentBlockhash:"Recent Blockhash",solana:"Signature"},txInfo:{started:"Started",network:"Network",slot:"Slot"},txError:{title:"Error",copied:"Copied!"},trackingModal:{title:"Transaction Overview",processing:"Processing...",close:"Close",walletInfo:"Wallet Info",retry:"Retry",progressIndicator:{created:"Created",processing:"Processing",succeed:"Succeed"}},trackedTxButton:{loading:"Processing...",succeed:"Success",failed:"Failed",replaced:"Replaced"},actions:{copy:"Copy address",viewOnExplorer:"View on explorer",close:"Close",cancel:"Cancel",speedUp:"Speed up"}};var te=createContext(ot);var m=()=>useContext(te);({[TransactionStatus.Success]:"success",[TransactionStatus.Failed]:"error",[TransactionStatus.Replaced]:"info"});function _({label:t,hash:e,explorerUrl:o,variant:r="default",className:s}){let{isCopied:n,copy:i}=useCopyToClipboard(),{actions:c,txError:p}=m(),a=cn("flex items-center justify-between",{"text-sm":r==="default","text-xs":r==="compact"},s),l=cn("pr-1",{"font-bold text-[var(--tuwa-text-primary)]":r==="default","font-medium text-[var(--tuwa-text-secondary)]":r==="compact"}),d=jsx("span",{className:"font-mono",children:textCenterEllipsis(e,5,5)});return jsxs("div",{className:a,children:[t&&jsxs("span",{className:l,children:[t,":"]}),jsxs("div",{className:"flex items-center gap-x-2",children:[o?jsxs("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-x-1 text-[var(--tuwa-text-accent)] transition-colors hover:underline",title:c.viewOnExplorer,"aria-label":c.viewOnExplorer,children:[d,jsx(ArrowTopRightOnSquareIcon,{className:"h-4 w-4"})]}):jsx("span",{className:"text-[var(--tuwa-text-primary)]",children:d}),jsx("button",{type:"button",onClick:()=>i(e),className:"cursor-pointer text-[var(--tuwa-text-tertiary)] transition-colors hover:text-[var(--tuwa-text-secondary)]",title:n?p.copied:c.copy,"aria-label":n?p.copied:c.copy,children:n?jsx(CheckIcon,{className:"h-4 w-4 text-[var(--tuwa-success-icon)]"}):jsx(DocumentDuplicateIcon,{className:"h-4 w-4"})})]})]})}var wt={[TransactionStatus.Success]:{index:1,colorClass:"text-[var(--tuwa-success-text)]"},[TransactionStatus.Failed]:{index:2,colorClass:"text-[var(--tuwa-error-text)]"},[TransactionStatus.Replaced]:{index:3,colorClass:"text-[var(--tuwa-text-secondary)]"},default:{index:0,colorClass:"text-[var(--tuwa-text-primary)]"}};function H({txStatus:t,source:e,fallback:o,variant:r,className:s,applyColor:n=false}){let i,c="";if(typeof e=="string")i=e;else if(Array.isArray(e)){let l=wt[t||"default"]??wt.default;i=e[l.index],n&&(c=l.colorClass);}else i=o;return i?jsx("div",{className:cn(r==="title"?"text-sm font-semibold text-[var(--tuwa-text-primary)]":"mt-1 text-xs text-[var(--tuwa-text-secondary)]",c,s),children:i}):null}function ee({closeToast:t}){let{actions:e}=m();return jsx("button",{type:"button",onClick:t,"aria-label":e.close,title:e.close,className:cn("absolute top-2 right-2 cursor-pointer rounded-full p-1","text-[var(--tuwa-text-tertiary)] transition-colors","hover:bg-[var(--tuwa-bg-muted)] hover:text-[var(--tuwa-text-primary)]"),children:jsx(XMarkIcon,{className:"h-5 w-5"})})}function Y(t){switch(t){case "solana:mainnet":return "Solana Mainnet";case "solana:devnet":return "Solana Devnet";case "solana:testnet":return "Solana Testent";default:return t}}var J=({svgCode:t,...e})=>jsx("img",{...e,draggable:false,onDragStart:o=>o.preventDefault(),src:`data:image/svg+xml;base64,${btoa(t)}`,style:{outline:"none !important",pointerEvents:"none"},alt:e.alt});function O({chainId:t,...e}){switch(t){case "solana:mainnet":return jsx(J,{svgCode:'<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="solanamainnet__a" x1="0" x2=".5" y1=".5" y2="0"><stop offset="0%" stop-color="#9844FE"/><stop offset="50%" stop-color="#5496D4" stop-opacity=".8"/><stop offset="100%" stop-color="#16FA9A"/></linearGradient></defs><g fill="none"><circle cx="16" cy="16" r="16" fill="#000"/><path fill="url(#solanamainnet__a)" d="M9.925 19.687a.6.6 0 0 1 .415-.17h14.366a.29.29 0 0 1 .207.497l-2.838 2.815a.6.6 0 0 1-.415.171H7.294a.291.291 0 0 1-.207-.498zm0-10.517A.6.6 0 0 1 10.34 9h14.366c.261 0 .392.314.207.498l-2.838 2.815a.6.6 0 0 1-.415.17H7.294a.291.291 0 0 1-.207-.497zm12.15 5.225a.6.6 0 0 0-.415-.17H7.294a.291.291 0 0 0-.207.498l2.838 2.815c.11.109.26.17.415.17h14.366a.291.291 0 0 0 .207-.498z"/></g></svg>',alt:t,...e});case "solana:devnet":return jsx(J,{svgCode:`<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
2
|
+
<path
|
3
|
+
fill="#C4BFB8"
|
4
|
+
d="M16 0c8.837 0 16 7.163 16 16s-7.163 16-16 16S0 24.837 0 16 7.163 0 16 0m8.706 19.517H10.34a.6.6 0 0 0-.415.17l-2.838 2.815a.291.291 0 0 0 .207.498H21.66a.6.6 0 0 0 .415-.17l2.838-2.816a.291.291 0 0 0-.207-.497m-3.046-5.292H7.294l-.068.007a.291.291 0 0 0-.14.49l2.84 2.816.07.06c.1.07.22.11.344.11h14.366l.068-.007a.291.291 0 0 0 .14-.49l-2.84-2.816-.07-.06a.6.6 0 0 0-.344-.11M24.706 9H10.34a.6.6 0 0 0-.415.17l-2.838 2.816a.291.291 0 0 0 .207.497H21.66a.6.6 0 0 0 .415-.17l2.838-2.815A.291.291 0 0 0 24.706 9"
|
5
|
+
/>
|
6
|
+
</svg>`,alt:t,...e});case "solana:testnet":return jsx(J,{svgCode:`<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
7
|
+
<path
|
8
|
+
fill="#C4BFB8"
|
9
|
+
d="M16 0c8.837 0 16 7.163 16 16s-7.163 16-16 16S0 24.837 0 16 7.163 0 16 0m8.706 19.517H10.34a.6.6 0 0 0-.415.17l-2.838 2.815a.291.291 0 0 0 .207.498H21.66a.6.6 0 0 0 .415-.17l2.838-2.816a.291.291 0 0 0-.207-.497m-3.046-5.292H7.294l-.068.007a.291.291 0 0 0-.14.49l2.84 2.816.07.06c.1.07.22.11.344.11h14.366l.068-.007a.291.291 0 0 0 .14-.49l-2.84-2.816-.07-.06a.6.6 0 0 0-.344-.11M24.706 9H10.34a.6.6 0 0 0-.415.17l-2.838 2.816a.291.291 0 0 0 .207.497H21.66a.6.6 0 0 0 .415-.17l2.838-2.815A.291.291 0 0 0 24.706 9"
|
10
|
+
/>
|
11
|
+
</svg>`,alt:t,...e});default:return jsx(J,{svgCode:'<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="solanamainnet__a" x1="0" x2=".5" y1=".5" y2="0"><stop offset="0%" stop-color="#9844FE"/><stop offset="50%" stop-color="#5496D4" stop-opacity=".8"/><stop offset="100%" stop-color="#16FA9A"/></linearGradient></defs><g fill="none"><circle cx="16" cy="16" r="16" fill="#000"/><path fill="url(#solanamainnet__a)" d="M9.925 19.687a.6.6 0 0 1 .415-.17h14.366a.29.29 0 0 1 .207.497l-2.838 2.815a.6.6 0 0 1-.415.171H7.294a.291.291 0 0 1-.207-.498zm0-10.517A.6.6 0 0 1 10.34 9h14.366c.261 0 .392.314.207.498l-2.838 2.815a.6.6 0 0 1-.415.17H7.294a.291.291 0 0 1-.207-.497zm12.15 5.225a.6.6 0 0 0-.415-.17H7.294a.291.291 0 0 0-.207.498l2.838 2.815c.11.109.26.17.415.17h14.366a.291.291 0 0 0 .207-.498z"/></g></svg>',alt:t,...e})}}function U({tx:t,adapter:e,variant:o="toast",className:r,renderHashLink:s,confirmations:n}){let{hashLabels:i,statuses:c}=m(),p=selectAdapterByKey({adapterKey:t.adapter,adapter:e});if(!p)return null;let a=f=>s?s(f):jsx(_,{...f}),l=o==="toast"?"mt-2 flex w-full flex-col gap-y-2 border-t border-[var(--tuwa-border-primary)] pt-2":"flex w-full flex-col gap-y-2",d=i[String(t.tracker)],v=d?a({label:d,hash:t.txKey,variant:t.tracker!==TransactionTracker.Solana?"compact":"default",explorerUrl:p.getExplorerTxUrl&&t.tracker===TransactionTracker.Solana?p?.getExplorerTxUrl(t):void 0}):null,x=(()=>{let f=t.hash,y=t.replacedTxHash;return !f&&!y?null:y?jsxs(Fragment,{children:[f&&a({label:i.original,hash:f,variant:"compact"}),typeof p.getExplorerTxUrl<"u"&&a({label:i.replaced,hash:y,explorerUrl:p.getExplorerTxUrl(t)})]}):f&&typeof p.getExplorerTxUrl<"u"&&a({label:i.default,hash:f,explorerUrl:p.getExplorerTxUrl(t)})})(),g=d&&d!==i.default&&t.txKey!==t.hash;return jsxs("div",{className:cn(l,r),children:[g&&v,x,typeof n=="number"&&jsxs("p",{className:"text-xs text-[var(--tuwa-text-tertiary)]",children:[c.confirmationsLabel,": ",n]})]})}var we=t=>({Pending:{label:t.pending,Icon:ArrowPathIcon,badgeClasses:"bg-[var(--tuwa-pending-bg)] text-[var(--tuwa-pending-text)]",iconClasses:"animate-spin text-[var(--tuwa-pending-icon)]"},[TransactionStatus.Success]:{label:t.success,Icon:CheckCircleIcon,badgeClasses:"bg-[var(--tuwa-success-bg)] text-[var(--tuwa-success-text)]",iconClasses:"text-[var(--tuwa-success-icon)]"},[TransactionStatus.Failed]:{label:t.failed,Icon:XCircleIcon,badgeClasses:"bg-[var(--tuwa-error-bg)] text-[var(--tuwa-error-text)]",iconClasses:"text-[var(--tuwa-error-icon)]"},[TransactionStatus.Replaced]:{label:t.replaced,Icon:ArrowPathIcon,badgeClasses:"bg-[var(--tuwa-info-bg)] text-[var(--tuwa-info-text)]",iconClasses:"text-[var(--tuwa-info-icon)]"}});function q({tx:t,className:e}){let{statuses:o}=m(),r=useMemo(()=>we(o),[o]),s="inline-flex items-center gap-x-1.5 rounded-full px-2 py-1 text-xs font-medium",n=t.pending?"Pending":t.status,i=n?r[n]:null;if(!i)return jsx("div",{className:cn(s,"bg-[var(--tuwa-info-bg)] text-[var(--tuwa-info-text)]",e),children:t.status??o.unknown});let{label:c,Icon:p,badgeClasses:a,iconClasses:l}=i;return jsxs("div",{className:cn(s,a,e),children:[jsx(p,{className:cn("h-4 w-4",l)}),c]})}var ke=({onClick:t,children:e})=>jsx("button",{onClick:t,type:"button",className:"cursor-pointer text-sm font-medium text-[var(--tuwa-text-accent)] transition-opacity hover:opacity-80",children:e}),Se=({onClick:t,children:e})=>jsx("button",{onClick:t,type:"button",className:"cursor-pointer text-sm font-medium text-[var(--tuwa-text-secondary)] transition-opacity hover:opacity-80",children:e}),Ae=({onClick:t,children:e})=>jsx("button",{className:"cursor-pointer rounded-md bg-gradient-to-r from-[var(--tuwa-button-gradient-from)] to-[var(--tuwa-button-gradient-to)] px-3 py-1 text-xs font-bold text-[var(--tuwa-text-on-accent)] shadow-lg transition-all duration-200 ease-in-out hover:shadow-xl hover:from-[var(--tuwa-button-gradient-from-hover)] hover:to-[var(--tuwa-button-gradient-to-hover)] active:scale-95",onClick:t,type:"button",children:e});function oe({openWalletInfoModal:t,tx:e,icon:o,className:r,customization:s,connectedWalletAddress:n,adapter:i}){let{actions:c,toast:p}=m(),a=selectAdapterByKey({adapterKey:e.adapter,adapter:i}),l=!!(e.tracker==="ethereum"&&e.pending&&a?.speedUpTxAction&&a?.cancelTxAction&&e.from.toLowerCase()===n?.toLowerCase()),d=()=>{l&&a.cancelTxAction(e);},v=()=>{l&&a.speedUpTxAction(e);},{StatusAwareText:x=H,TransactionKey:g=U,StatusBadge:f=q,SpeedUpButton:y=ke,CancelButton:I=Se,WalletInfoButton:T=Ae}=s?.components??{};return jsxs("div",{className:cn("flex w-full flex-col gap-3 rounded-lg bg-[var(--tuwa-bg-primary)] p-4 shadow-md",r),children:[jsxs("div",{className:"flex items-start gap-3",children:[jsx("div",{className:"w-[40px] flex-shrink-0",title:typeof e.chainId=="string"?Y(e.chainId):getChainName(e.chainId),children:o??typeof e.chainId=="string"?jsx(O,{chainId:e.chainId}):jsx(Web3Icon,{chainId:e.chainId})}),jsxs("div",{className:"flex-1",children:[jsx(x,{txStatus:e.status,source:e.title,fallback:e.type,variant:"title",applyColor:true}),jsx(x,{txStatus:e.status,source:e.description,variant:"description"})]})]}),jsxs("div",{children:[jsx(g,{adapter:i,tx:e,variant:"toast"}),jsxs("div",{className:"mt-3 flex items-center justify-between",children:[jsx(f,{tx:e}),l?jsxs("div",{className:"flex items-center gap-4",children:[jsx(y,{onClick:v,children:c.speedUp}),jsx(I,{onClick:d,children:c.cancel})]}):t&&!!n&&jsx(T,{onClick:t,children:p.openWalletInfo})]})]})]})}function It({error:t,className:e}){let{isCopied:o,copy:r}=useCopyToClipboard(),{actions:s,txError:n}=m();return t?jsxs("div",{className:cn("rounded-lg border border-[var(--tuwa-error-icon)]/30 bg-[var(--tuwa-error-bg)] p-3 text-sm",e),children:[jsxs("div",{className:"mb-2 flex items-center justify-between",children:[jsxs("div",{className:"flex items-center gap-2 font-bold text-[var(--tuwa-error-icon)]",children:[jsx(ExclamationTriangleIcon,{className:"h-5 w-5"}),jsx("span",{children:n.title})]}),jsx("button",{type:"button",onClick:()=>r(t),title:o?n.copied:s.copy,"aria-label":o?n.copied:`${s.copy} error message`,className:"cursor-pointer text-[var(--tuwa-error-icon)]/50 transition-colors hover:text-[var(--tuwa-error-icon)]",children:o?jsx(CheckIcon,{className:"h-5 w-5 text-[var(--tuwa-success-icon)]"}):jsx(DocumentDuplicateIcon,{className:"h-5 w-5"})})]}),jsx("div",{className:"max-h-24 overflow-y-auto rounded bg-[var(--tuwa-bg-primary)] p-2",children:jsx("p",{className:"font-mono text-xs text-[var(--tuwa-error-text)] break-all",children:t})})]}):null}function Fe({label:t,value:e}){return jsxs("div",{className:"flex items-center justify-between text-sm",children:[jsx("span",{className:"text-[var(--tuwa-text-secondary)]",children:t}),jsx("span",{className:"font-medium text-[var(--tuwa-text-primary)]",children:e})]})}function kt({tx:t,adapter:e,className:o,customization:r}){let{txInfo:s,statuses:n,hashLabels:i}=m(),c=selectAdapterByKey({adapterKey:t.adapter,adapter:e});if(!c)return null;let{InfoRow:p=Fe}=r?.components??{},a="chainId"in t?t.chainId:t.desiredChainID,l=t.adapter===TransactionAdapter.SOLANA,d=l?t:void 0;return jsxs("div",{className:cn("flex flex-col gap-3 rounded-lg border border-[var(--tuwa-border-primary)] bg-[var(--tuwa-bg-primary)] p-3",o),children:[jsx(p,{label:s.network,value:jsxs("div",{className:"flex items-center justify-end gap-2",children:[jsx("div",{className:"h-4 w-4",children:typeof a=="string"?jsx(O,{chainId:a}):jsx(Web3Icon,{chainId:a})}),jsx("span",{children:typeof a=="string"?Y(a):getChainName(a)})]})}),t.localTimestamp&&jsx(p,{label:s.started,value:Wt.unix(t.localTimestamp).format("MMM D, HH:mm:ss")}),l&&jsxs(Fragment,{children:[d?.slot&&jsx(p,{label:s.slot,value:jsx(_,{hash:d.slot.toString(),explorerUrl:c?.getExplorerUrl?`${c?.getExplorerUrl(`/block/${d.slot}`)}`:void 0})}),(typeof d?.confirmations=="number"||typeof d?.confirmations=="string")&&jsx(p,{label:n.confirmationsLabel,value:d.confirmations}),d?.recentBlockhash&&jsx(p,{label:i.recentBlockhash,value:jsx(_,{hash:d.recentBlockhash})})]}),"txKey"in t&&t.txKey&&jsx("div",{className:"border-t border-[var(--tuwa-border-primary)] pt-3",children:jsx(U,{tx:t,adapter:e,variant:"history",renderHashLink:r?.components?.transactionKey})})]})}var Xe={completed:{line:"bg-[var(--tuwa-success-icon)]",border:"border-[var(--tuwa-success-icon)]",fill:"bg-[var(--tuwa-success-icon)]"},error:{line:"bg-[var(--tuwa-error-icon)]",border:"border-[var(--tuwa-error-icon)]",fill:"bg-[var(--tuwa-error-icon)]"},replaced:{line:"bg-[var(--tuwa-info-icon)]",border:"border-[var(--tuwa-info-icon)]",fill:"bg-[var(--tuwa-info-icon)]"},active:{line:"bg-[var(--tuwa-pending-icon)]",border:"border-[var(--tuwa-pending-icon)]",fill:"bg-transparent",pulse:"bg-[var(--tuwa-pending-icon)]"},inactive:{line:"bg-[var(--tuwa-border-primary)]",border:"border-[var(--tuwa-border-primary)]",fill:"bg-transparent"}};function Je({status:t,label:e,isFirst:o=false}){let r=Xe[t],s=()=>{switch(t){case "completed":return jsx(CheckIcon,{className:"h-3 w-3 text-white"});case "error":return jsx(ExclamationTriangleIcon,{className:"h-3 w-3 text-white"});case "replaced":return jsx(ArrowPathIcon,{className:"h-3 w-3 text-white"});case "active":return jsx("div",{className:cn("h-2 w-2 animate-pulse rounded-full",r.pulse)});default:return null}};return jsxs("div",{className:"relative flex min-w-[80px] flex-1 flex-col items-center",children:[!o&&jsx("div",{className:cn("absolute right-1/2 top-[10px] h-0.5 w-full",r.line)}),jsx("div",{className:cn("relative z-10 flex h-5 w-5 items-center justify-center rounded-full border-2",r.border,r.fill),children:s()}),jsx("span",{className:cn("mt-2 text-center text-xs",t!=="inactive"?"font-semibold text-[var(--tuwa-text-primary)]":"text-[var(--tuwa-text-secondary)]"),children:e})]})}function St({isProcessing:t,isSucceed:e,isFailed:o,isReplaced:r,className:s,StepComponent:n=Je}){let{trackingModal:i,statuses:c}=m(),p=useMemo(()=>{let a=d=>{if(d===1)return "completed";if(d===2){if(e||o||r)return "completed";if(t)return "active"}if(d===3){if(e)return "completed";if(o)return "error";if(r)return "replaced";if(t)return "active"}return "inactive"},l=d=>d===1?i.progressIndicator.created:d===2?i.progressIndicator.processing:o?c.failed:r?c.replaced:i.progressIndicator.succeed;return [{status:a(1),label:l(1),isFirst:true},{status:a(2),label:l(2)},{status:a(3),label:l(3),isLast:true}]},[t,e,o,r,i,c]);return jsx("div",{className:cn("flex w-full items-start px-4 pt-2 pb-1",s),children:p.map((a,l)=>jsx(n,{...a},l))})}var to={succeed:{Icon:CheckCircleIcon,className:"text-[var(--tuwa-success-icon)]"},failed:{Icon:ExclamationCircleIcon,className:"text-[var(--tuwa-error-icon)]"},replaced:{Icon:ArrowPathIcon,className:"text-[var(--tuwa-info-icon)]"},processing:{Icon:ArrowPathIcon,className:"animate-spin text-[var(--tuwa-text-accent)]"},initializing:{Icon:ClockIcon,className:"animate-pulse text-[var(--tuwa-pending-icon)]"}};function Bt({isProcessing:t,isSucceed:e,isFailed:o,isReplaced:r}){let s=e&&"succeed"||o&&"failed"||r&&"replaced"||t&&"processing"||"initializing",{Icon:n,className:i}=to[s];return jsx("div",{className:"flex justify-center py-4",children:jsx(n,{className:cn("h-16 w-16",i)})})}function ae({adapter:t,onClose:e,onOpenWalletInfo:o,className:r,customization:s,transactionsPool:n,handleTransaction:i,initialTx:c,connectedWalletAddress:p}){let a=useMemo(()=>c?.lastTxKey?n[c.lastTxKey]:void 0,[n,c]),l=a??c,d=c?.withTrackedModal&&!a||(a?.isTrackedModalOpen??false),{isProcessing:v,isSucceed:x,isFailed:g,isReplaced:f}=useMemo(()=>{let K=a?.status,qt=c?.isInitializing??false,Qt=a?.pending??false;return {isProcessing:qt||Qt,isSucceed:K===TransactionStatus.Success,isFailed:a?.isError||!!c?.errorMessage,isReplaced:K===TransactionStatus.Replaced}},[a,c]),y=useMemo(()=>l?selectAdapterByKey({adapterKey:l.adapter,adapter:t}):void 0,[l,t]),I=!!(g&&l&&c?.actionFunction&&i),T=!!(y?.speedUpTxAction&&y?.cancelTxAction&&a?.pending&&a.tracker==="ethereum"),W=()=>{if(!I||!y?.retryTxAction)return;let K={adapter:l.adapter,type:l.type,desiredChainID:"desiredChainID"in l?l.desiredChainID:l.chainId,actionFunction:c?.actionFunction,title:l.title,description:l.description,payload:l.payload,withTrackedModal:true};y.retryTxAction({tx:K,txKey:a?.txKey??"",onClose:e,handleTransaction:i});},k=()=>{T&&a&&y.cancelTxAction(a);},B=()=>{T&&a&&y.speedUpTxAction(a);},G=s?.components?.Header,xt=s?.components?.Footer,gt=s?.components?.StatusVisual,Tt=s?.components?.ProgressIndicator,vt=s?.components?.InfoBlock,yt=s?.components?.ErrorBlock,Yt={initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.2,ease:"easeOut"},...s?.motionProps};return l?jsx(C.Root,{open:d,onOpenChange:K=>!K&&e(a?.txKey),children:jsx(C.Portal,{children:jsx(AnimatePresence,{children:d&&jsxs(Fragment,{children:[jsx(C.Overlay,{asChild:true,children:jsx(motion.div,{className:"fixed inset-0 z-50 bg-black/60",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0}})}),jsx(C.Content,{className:"fixed left-1/2 top-1/2 z-50 w-full max-w-md -translate-x-1/2 -translate-y-1/2 outline-none",...s?.modalProps,asChild:true,children:jsx(motion.div,{...Yt,children:jsxs("div",{className:cn("relative flex max-h-[98dvh] w-full flex-col gap-3 overflow-y-auto rounded-2xl bg-[var(--tuwa-bg-primary)] p-5 pt-0 shadow-2xl",r),children:[G?jsx(G,{onClose:()=>e(a?.txKey),title:jsx(Dt,{tx:l})}):jsx(so,{onClose:()=>e(a?.txKey),title:jsx(Dt,{tx:l})}),jsxs("main",{className:"flex flex-col gap-3",children:[gt?jsx(gt,{isProcessing:v,isSucceed:x,isFailed:g,isReplaced:f}):jsx(Bt,{isProcessing:v,isSucceed:x,isFailed:g,isReplaced:f}),Tt?jsx(Tt,{isProcessing:v,isSucceed:x,isFailed:g,isReplaced:f}):jsx(St,{isProcessing:v,isSucceed:x,isFailed:g,isReplaced:f}),vt?jsx(vt,{tx:l,adapter:t}):jsx(kt,{tx:l,adapter:t}),yt?jsx(yt,{error:a?.errorMessage||c?.errorMessage}):jsx(It,{error:a?.errorMessage||c?.errorMessage})]}),xt?jsx(xt,{onClose:()=>e(a?.txKey),onOpenWalletInfo:o,isProcessing:v,isFailed:g,canReplace:T,onRetry:I?W:void 0,onSpeedUp:T?B:void 0,onCancel:T?k:void 0,connectedWalletAddress:p}):jsx(no,{onClose:()=>e(a?.txKey),onOpenWalletInfo:o,isProcessing:v,isFailed:g,canReplace:T,onRetry:I?W:void 0,onSpeedUp:T?B:void 0,onCancel:T?k:void 0,connectedWalletAddress:p})]})})})]})})})}):null}function Dt({tx:t}){return jsx(H,{txStatus:"status"in t?t.status:void 0,source:t.title,fallback:t.type,variant:"title",className:"text-lg"})}var so=({onClose:t,title:e})=>{let{actions:o}=m();return jsxs("header",{className:"sticky top-0 z-10 flex w-full items-start justify-between bg-[var(--tuwa-bg-primary)] pt-5 pb-2",children:[jsx(C.Title,{children:e}),jsx(C.Close,{asChild:true,children:jsx("button",{type:"button",onClick:()=>t(),"aria-label":o.close,className:"cursor-pointer -mt-1 ml-2 rounded-full p-1 text-[var(--tuwa-text-tertiary)] transition-colors hover:bg-[var(--tuwa-bg-muted)] hover:text-[var(--tuwa-text-primary)]",children:jsx(XMarkIcon,{className:"h-5 w-5"})})})]})},no=({onClose:t,onOpenWalletInfo:e,isProcessing:o,onRetry:r,onSpeedUp:s,onCancel:n,canReplace:i,isFailed:c,connectedWalletAddress:p})=>{let{trackingModal:a,actions:l}=m(),d=()=>c&&r?jsx("button",{type:"button",onClick:r,className:"cursor-pointer rounded-md bg-[var(--tuwa-button-gradient-from)] px-4 py-2 text-sm font-semibold text-[var(--tuwa-text-on-accent)] transition-opacity hover:opacity-90",children:a.retry}):!o&&!i&&p?jsx("button",{type:"button",onClick:e,className:"cursor-pointer rounded-md bg-[var(--tuwa-bg-muted)] px-4 py-2 text-sm font-semibold text-[var(--tuwa-text-primary)] transition-colors hover:bg-[var(--tuwa-border-primary)]",children:a.walletInfo}):null;return jsxs("footer",{className:"mt-2 flex w-full items-center justify-between border-t border-[var(--tuwa-border-primary)] pt-4",children:[jsx("div",{className:"flex items-center gap-4",children:i&&s&&n&&jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:s,className:"cursor-pointer text-sm font-medium text-[var(--tuwa-text-accent)] transition-opacity hover:opacity-80",children:l.speedUp}),jsx("button",{type:"button",onClick:n,className:"cursor-pointer text-sm font-medium text-[var(--tuwa-text-secondary)] transition-opacity hover:opacity-80",children:l.cancel})]})}),jsxs("div",{className:"flex items-center gap-3",children:[jsx(d,{}),jsx("button",{type:"button",onClick:t,disabled:o&&!i,className:"cursor-pointer rounded-md bg-[var(--tuwa-bg-muted)] px-4 py-2 text-sm font-semibold text-[var(--tuwa-text-primary)] transition-colors hover:bg-[var(--tuwa-border-primary)] disabled:cursor-not-allowed disabled:opacity-50",children:o&&!i?a.processing:a.close})]})]})};Wt.extend(co);var po=({chainId:t})=>jsx("div",{className:"h-8 w-8 text-[var(--tuwa-text-secondary)]",children:typeof t=="string"?jsx(O,{chainId:t}):jsx(Web3Icon,{chainId:t})}),uo=({timestamp:t})=>jsx("span",{className:"mb-1 block text-xs text-[var(--tuwa-text-secondary)]",children:t?Wt.unix(t).fromNow():"..."});function Kt({tx:t,adapter:e,className:o,customization:r}){let{Icon:s=po,Title:n=H,Description:i=H,Timestamp:c=uo,StatusBadge:p=q,TransactionKey:a=U}=r?.components??{};return jsxs("div",{className:cn("flex flex-col gap-2 border-b border-[var(--tuwa-border-secondary)] p-3 transition-colors hover:bg-[var(--tuwa-bg-secondary)]",o),children:[jsxs("div",{className:"flex items-start justify-between",children:[jsxs("div",{className:"flex items-center gap-4",children:[jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-[var(--tuwa-bg-muted)]",children:jsx(s,{chainId:t.chainId})}),jsxs("div",{children:[jsx(n,{txStatus:t.status,source:t.title,fallback:t.type,variant:"title",applyColor:true}),jsx(c,{timestamp:t.localTimestamp}),jsx(i,{txStatus:t.status,source:t.description,variant:"description"})]})]}),jsx(p,{tx:t})]}),jsx(a,{tx:t,adapter:e,variant:"history"})]})}function xo({title:t,message:e,className:o}){return jsxs("div",{className:cn("rounded-lg bg-[var(--tuwa-bg-muted)] p-8 text-center",o),children:[jsx("h4",{className:"font-semibold text-[var(--tuwa-text-primary)]",children:t}),jsx("p",{className:"mt-1 text-sm text-[var(--tuwa-text-secondary)]",children:e})]})}function Et({adapter:t,connectedWalletAddress:e,transactionsPool:o,className:r,customization:s}){let{walletModal:n}=m(),i=useMemo(()=>e?selectAllTransactionsByActiveWallet(o,e).sort((d,v)=>(v.localTimestamp??0)-(d.localTimestamp??0)):[],[o,e]),{Placeholder:c=xo,HistoryItem:p=Kt}=s?.components??{},a=()=>e?i.length>0?jsx("div",{className:cn("max-h-[400px] overflow-y-auto rounded-lg border border-[var(--tuwa-border-primary)] bg-[var(--tuwa-bg-primary)]",s?.classNames?.listWrapper),children:i.map(l=>jsx(p,{tx:l,adapter:t},l.txKey))}):jsx(c,{title:n.history.noTransactionsTitle,message:n.history.noTransactionsMessage}):jsx(c,{title:n.history.connectWalletTitle,message:n.history.connectWalletMessage});return jsxs("div",{className:cn("flex flex-col gap-y-3",r),children:[jsx("h3",{className:"text-lg font-bold text-[var(--tuwa-text-primary)]",children:n.history.title}),a()]})}var bo=t=>({replaced:jsxs(Fragment,{children:[jsx(ArrowPathIcon,{className:"h-4 w-4"}),jsx("span",{children:t.replaced})]}),loading:jsxs(Fragment,{children:[jsx(ArrowPathIcon,{className:"h-4 w-4 animate-spin"}),jsx("span",{children:t.loading})]}),succeed:jsxs(Fragment,{children:[jsx(CheckCircleIcon,{className:"h-4 w-4"}),jsx("span",{children:t.succeed})]}),failed:jsxs(Fragment,{children:[jsx(ExclamationCircleIcon,{className:"h-4 w-4"}),jsx("span",{children:t.failed})]})});function yn({children:t,action:e,getLastTxKey:o,transactionsPool:r,walletAddress:s,loadingContent:n,succeedContent:i,failedContent:c,replacedContent:p,resetTimeout:a=2500,className:l,...d}){let{trackedTxButton:v}=m(),[x,g]=useState("idle"),[f,y]=useState(void 0),I=useMemo(()=>bo(v),[v]);useEffect(()=>{g("idle"),y(void 0);},[s]),useEffect(()=>{if(!f)return;let k=r[f];if(k)switch(k.status){case TransactionStatus.Success:g("succeed");break;case TransactionStatus.Replaced:g("replaced");break;case TransactionStatus.Failed:g("failed");break}},[r,f,s]),useEffect(()=>{if(["succeed","failed","replaced"].includes(x)){let k=setTimeout(()=>{g("idle"),y(void 0);},a);return ()=>clearTimeout(k)}},[x,a]);let T=async()=>{g("loading");try{await e(),y(o());}catch(k){console.error("Transaction initiation failed:",k),g("failed");}},W=()=>{switch(x){case "loading":return n??I.loading;case "succeed":return i??I.succeed;case "failed":return c??I.failed;case "replaced":return p??I.replaced;default:return t}};return jsx("button",{...d,disabled:x!=="idle"||d.disabled,onClick:T,className:cn("flex cursor-pointer items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-70",{"bg-gradient-to-r from-[var(--tuwa-button-gradient-from)] to-[var(--tuwa-button-gradient-to)] text-[var(--tuwa-text-on-accent)] hover:opacity-90":x==="idle","bg-gray-400 text-white":x==="loading","bg-gray-500 text-white":x==="replaced","bg-[var(--tuwa-success-bg)] text-[var(--tuwa-success-text)]":x==="succeed","bg-[var(--tuwa-error-bg)] text-[var(--tuwa-error-text)]":x==="failed"},l),children:W()})}function mt({address:t,explorerUrl:e,className:o}){let{isCopied:r,copy:s}=useCopyToClipboard(),{actions:n,txError:i}=m();return jsxs("div",{className:cn("flex items-center gap-x-3 rounded-full bg-[var(--tuwa-bg-muted)] px-3 py-1 font-mono text-xs text-[var(--tuwa-text-secondary)]",o),children:[jsx("span",{children:textCenterEllipsis(t,6,6)}),jsx("button",{type:"button",title:r?i.copied:n.copy,"aria-label":r?i.copied:`${n.copy} address`,onClick:()=>s(t),className:"cursor-pointer transition-colors hover:text-[var(--tuwa-text-primary)]",children:r?jsx(CheckIcon,{className:"h-4 w-4 text-[var(--tuwa-success-icon)]"}):jsx(DocumentDuplicateIcon,{className:"h-4 w-4"})}),e&&jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"transition-colors hover:text-[var(--tuwa-text-accent)]",title:n.viewOnExplorer,"aria-label":n.viewOnExplorer,children:jsx(ArrowTopRightOnSquareIcon,{className:"h-4 w-4"})})]})}function Ho(t,{strict:e=true}={}){return !t||typeof t!="string"?false:e?/^0x[0-9a-fA-F]*$/.test(t):t.startsWith("0x")}var Ro="0x0000000000000000000000000000000000000000";function Vt({address:t,ensAvatar:e,className:o}){let{walletModal:r}=m(),[s,n]=useState(e),i=useMemo(()=>Ao(Ho(t)?t:Ro),[t]),c=useMemo(()=>`#${t.slice(2,8)}`,[t]);useEffect(()=>{n(e);},[e]);let p=()=>{n(i);};return jsx("div",{className:cn("h-12 w-12 flex-shrink-0 rounded-full",o),style:{backgroundColor:c},children:jsx("img",{className:"h-full w-full rounded-full object-cover",src:s||i,alt:`${r.header.avatarAlt} ${t}`,onError:p},e)})}var Ko=({isLoading:t,ensName:e,walletAddress:o,explorerUrl:r,renderAddressDisplay:s})=>jsxs("div",{className:"flex flex-col",children:[jsx("div",{className:"mb-1.5 flex h-7 items-center",children:t?jsx("div",{className:"h-full w-48 animate-pulse rounded-md bg-[var(--tuwa-bg-muted)]"}):e?jsx("h2",{className:"text-xl font-bold text-[var(--tuwa-text-primary)]",children:e}):jsx(mt,{address:o,explorerUrl:r,className:"rounded-none bg-transparent px-0 py-0 text-xl font-bold text-[var(--tuwa-text-primary)]"})}),jsx("div",{className:"flex h-5 items-center",children:!t&&e&&(s?s({address:o,explorerUrl:r}):jsx(mt,{address:o,explorerUrl:r}))})]});function Gt({walletAddress:t,adapter:e,connectedAdapterType:o,className:r,renderAvatar:s,renderName:n,renderAddressDisplay:i,renderNoWalletContent:c,explorerUrl:p}){let{walletModal:a}=m(),[l,d]=useState(null),[v,x]=useState(null),[g,f]=useState(true);if(useEffect(()=>{(async()=>{if(!t||!o){f(false);return}let T=selectAdapterByKey({adapterKey:o,adapter:e}),W=T&&"getName"in T&&typeof T.getName=="function",k=T&&"getAvatar"in T&&typeof T.getAvatar=="function";if(!W){f(false);return}f(true),d(null),x(null);try{let B=T?.getName?await T.getName(t):null;if(B&&(d(B),k)){let G=T?.getAvatar?await T.getAvatar(B):null;x(G);}}catch(B){console.error("Failed to fetch name service data:",B);}finally{f(false);}})();},[t,e,o]),!t)return c?jsx(Fragment,{children:c()}):jsx("div",{className:cn("flex h-20 items-center justify-center rounded-lg bg-[var(--tuwa-bg-muted)] text-[var(--tuwa-text-secondary)]",r),children:a.header.notConnected});let y=l?l.length>30?textCenterEllipsis(l,12,12):l:void 0;return jsxs("div",{className:cn("flex min-h-[4rem] items-center gap-4",r),children:[jsx("div",{children:s?s({address:t,ensAvatar:v}):jsx(Vt,{address:t,ensAvatar:v})}),jsx("div",{className:"flex min-h-[3.5rem] min-w-[200px] flex-col justify-center",children:n?n({ensName:y,isLoading:g,address:t}):jsx(Ko,{isLoading:g,ensName:y,walletAddress:t,explorerUrl:p,renderAddressDisplay:i})})]})}var Vo=({closeModal:t,title:e})=>{let{actions:o}=m();return jsxs("div",{className:"sticky top-0 left-0 z-10 flex w-full items-center justify-between border-b border-[var(--tuwa-border-primary)] bg-[var(--tuwa-bg-secondary)] p-4",children:[jsx(C.Title,{className:"text-lg font-bold text-[var(--tuwa-text-primary)]",children:e}),jsx(C.Close,{asChild:true,children:jsx("button",{type:"button",onClick:t,"aria-label":o.close,className:"cursor-pointer rounded-full p-1 text-[var(--tuwa-text-tertiary)] transition-colors hover:bg-[var(--tuwa-bg-muted)] hover:text-[var(--tuwa-text-primary)]",children:jsx(XMarkIcon,{className:"h-6 w-6"})})})]})};function re({isOpen:t,setIsOpen:e,customization:o,adapter:r,connectedAdapterType:s,connectedWalletAddress:n,transactionsPool:i}){let{walletModal:c}=m(),{explorerUrl:p}=useMemo(()=>s?{explorerUrl:selectAdapterByKey({adapterKey:s,adapter:r})?.getExplorerUrl(`/address/${n}`)}:{explorerUrl:void 0},[s,r,n]),a=()=>e(false),d={...{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.2,ease:"easeOut"}},...o?.motionProps},v=o?.components?.Header,x=o?.components?.WalletInfo,g=o?.components?.History;return jsx(C.Root,{open:t,onOpenChange:f=>!f&&a(),children:jsx(C.Portal,{children:jsx(AnimatePresence,{children:t&&jsxs(Fragment,{children:[jsx(C.Overlay,{asChild:true,children:jsx(motion.div,{className:"fixed inset-0 z-50 bg-black/45",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15}})}),jsx(C.Content,{className:"fixed left-1/2 top-1/2 z-50 w-full max-w-2xl -translate-x-1/2 -translate-y-1/2 outline-none",...o?.modalProps,asChild:true,children:jsx(motion.div,{...d,children:jsxs("div",{className:cn("relative max-h-[98dvh] w-full max-w-2xl overflow-y-auto rounded-2xl bg-[var(--tuwa-bg-secondary)] shadow-xl outline-none",o?.classNames?.contentWrapper),children:[v?jsx(v,{closeModal:a}):jsx(Vo,{closeModal:a,title:c.title}),jsxs("div",{className:"flex flex-col gap-4 p-4 sm:gap-6 sm:p-6",children:[x?jsx(x,{adapter:r,connectedAdapterType:s,walletAddress:n,explorerUrl:p}):jsx(Gt,{adapter:r,connectedAdapterType:s,walletAddress:n,explorerUrl:p}),g?jsx(g,{adapter:r,transactionsPool:i,connectedWalletAddress:n}):jsx(Et,{adapter:r,transactionsPool:i,connectedWalletAddress:n})]})]})})})]})})})})}
|
12
|
+
export{_ as HashLink,H as StatusAwareText,ee as ToastCloseButton,oe as ToastTransaction,ae as TrackingTxModal,Kt as TransactionHistoryItem,U as TransactionKey,q as TransactionStatusBadge,Et as TransactionsHistory,yn as TxActionButton,It as TxErrorBlock,kt as TxInfoBlock,St as TxProgressIndicator,Bt as TxStatusVisual,mt as WalletAddressDisplay,Vt as WalletAvatar,Gt as WalletHeader,re as WalletInfoModal,ot as defaultLabels};//# sourceMappingURL=index.js.map
|
2
13
|
//# sourceMappingURL=index.js.map
|