PageSourceSearch

https://cspr.trade/assets/useTokenApprovalFlow-CDKVN2AZ.js

js cspr.trade collected 2026-10-07 18:31:09 UTC 2,754 bytes, 1 lines download raw bytes

1(function(){try{var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{};e.SENTRY_RELEASE={id:`d45967a7a15b6813a46aeb4b91bcc998928c8498`},e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:cspr-trade":!0});var t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`b7810070-7a3f-4fa2-a1dd-d79010c1565d`,e._sentryDebugIdIdentifier=`sentry-dbid-b7810070-7a3f-4fa2-a1dd-d79010c1565d`)}catch{}})();import{a as e}from"./rolldown-runtime-A1eKrzzz.js";import{i as t}from"./react-Dq0qlzK_.js";import{l as n}from"./CSPRBalanceErrorMessage-Cos9K3nu.js";import{M as r}from"./index-BpylJyUa.js";var i=e(t(),1),a=()=>{let{activeAccount:e}=r(),{tokenStateService:t,contractService:a}=n(),o=(0,i.useCallback)(async n=>{if(!e?.public_key)return!1;try{return await t.checkApprovalRequired({contractPackageHash:n.contractPackageHash,publicKey:e.public_key,requiredAmount:n.requiredAmount})}catch(e){return console.error(`Failed to check approval:`,e),!1}},[e,t]),s=(0,i.useCallback)(async(e,t)=>{let[n,r]=await Promise.all([o(e),o(t)]);return{first:n,second:r}},[o]),c=(0,i.useCallback)(async(t,n)=>{if(!e?.public_key)throw Error(`No active account`);return new Promise((r,i)=>{a.approveTokenSpending({contractPackageHash:t.contractPackageHash,publicKey:e.public_key,balance:t.balance},{onSent:e=>{console.log(`Approval transaction sent:`,e),n?.onSent?.(e)},onProcessed:()=>{console.log(`Approval transaction processed`),n?.onProcessed?.(),r()},onError:e=>{console.error(`Approval transaction error:`,e),n?.onError?.(e),i(e)},onCancelled:()=>{console.log(`Approval transaction cancelled`),n?.onCancelled?.(),i(Error(`Approval cancelled`))}}).catch(e=>{console.error(`Unhandled error in approval:`,e),i(e)})})},[e,a]),l=(0,i.useCallback)(async(e,t,n,r,i)=>{i?.onCheckStart?.();let{first:a,second:o}=await s(e,t);return i?.onCheckComplete?.({firstRequired:a,secondRequired:o}),a&&(i?.onFirstApprovalStart?.(),await c(n,i?.onFirstApproval),i?.onFirstApprovalComplete?.()),o&&(i?.onSecondApprovalStart?.(),await c(r,i?.onSecondApproval),i?.onSecondApprovalComplete?.()),{firstRequired:a,secondRequired:o}},[s,c]);return{checkApprovalRequired:o,executeApproval:c,checkTwoApprovalsRequired:s,checkAndApprove:(0,i.useCallback)(async(e,t,n)=>{n?.onCheckStart?.();let r=await o(e);return n?.onCheckComplete?.(r),r&&(n?.onApprovalStart?.(),await c(t,n),n?.onApprovalComplete?.()),r},[o,c]),checkAndApproveTwoTokens:l}};export{a as t};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.