@tuwaio/pulsar-core 0.4.1 → 0.5.0
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/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrbitAdapter, BaseAdapter, OrbitGenericAdapter } from '@tuwaio/orbit-core';
|
|
1
|
+
import { TuwaErrorState, OrbitAdapter, BaseAdapter, OrbitGenericAdapter } from '@tuwaio/orbit-core';
|
|
2
2
|
import * as zustand from 'zustand';
|
|
3
3
|
import { StoreApi } from 'zustand';
|
|
4
4
|
import { PersistOptions } from 'zustand/middleware';
|
|
@@ -70,8 +70,8 @@ type BaseTransaction = {
|
|
|
70
70
|
* description: ['Swapping...', 'Swapped Successfully', 'Swap Failed', 'Swap Replaced']
|
|
71
71
|
*/
|
|
72
72
|
description?: string | [string, string, string, string];
|
|
73
|
-
/** The error
|
|
74
|
-
|
|
73
|
+
/** The error state if the transaction failed, containing message and raw error details. */
|
|
74
|
+
error?: TuwaErrorState;
|
|
75
75
|
/** The on-chain timestamp (in seconds) when the transaction was finalized. */
|
|
76
76
|
finishedTimestamp?: number;
|
|
77
77
|
/** The sender's wallet address. */
|
|
@@ -192,8 +192,8 @@ type InitialTransactionParams = {
|
|
|
192
192
|
* This is used for UI feedback while the transaction is being signed and sent.
|
|
193
193
|
*/
|
|
194
194
|
type InitialTransaction = InitialTransactionParams & {
|
|
195
|
-
/**
|
|
196
|
-
|
|
195
|
+
/** Normalized error if the initialization fails (e.g., user rejects signature). */
|
|
196
|
+
error?: TuwaErrorState;
|
|
197
197
|
/** A flag indicating if the transaction is being processed (e.g., waiting for signature). */
|
|
198
198
|
isInitializing: boolean;
|
|
199
199
|
/** The `txKey` of the on-chain transaction that this action produced, used for linking the states. */
|
|
@@ -307,7 +307,7 @@ type TransactionPool<T extends Transaction> = Record<string, T>;
|
|
|
307
307
|
* on a transaction object via the `updateTxParams` action. This ensures type safety
|
|
308
308
|
* and prevents accidental modification of immutable properties.
|
|
309
309
|
*/
|
|
310
|
-
type UpdatableTransactionFields = Partial<Pick<EvmTransaction, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | '
|
|
310
|
+
type UpdatableTransactionFields = Partial<Pick<EvmTransaction, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | 'error' | 'finishedTimestamp' | 'isTrackedModalOpen' | 'isError' | 'maxPriorityFeePerGas' | 'maxFeePerGas' | 'input' | 'value'>> & Partial<Pick<SolanaTransaction, 'slot' | 'confirmations' | 'fee' | 'instructions' | 'recentBlockhash' | 'rpcUrl'>>;
|
|
311
311
|
/**
|
|
312
312
|
* The interface for the base transaction tracking store slice.
|
|
313
313
|
* It includes the state and actions for managing the transaction lifecycle.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrbitAdapter, BaseAdapter, OrbitGenericAdapter } from '@tuwaio/orbit-core';
|
|
1
|
+
import { TuwaErrorState, OrbitAdapter, BaseAdapter, OrbitGenericAdapter } from '@tuwaio/orbit-core';
|
|
2
2
|
import * as zustand from 'zustand';
|
|
3
3
|
import { StoreApi } from 'zustand';
|
|
4
4
|
import { PersistOptions } from 'zustand/middleware';
|
|
@@ -70,8 +70,8 @@ type BaseTransaction = {
|
|
|
70
70
|
* description: ['Swapping...', 'Swapped Successfully', 'Swap Failed', 'Swap Replaced']
|
|
71
71
|
*/
|
|
72
72
|
description?: string | [string, string, string, string];
|
|
73
|
-
/** The error
|
|
74
|
-
|
|
73
|
+
/** The error state if the transaction failed, containing message and raw error details. */
|
|
74
|
+
error?: TuwaErrorState;
|
|
75
75
|
/** The on-chain timestamp (in seconds) when the transaction was finalized. */
|
|
76
76
|
finishedTimestamp?: number;
|
|
77
77
|
/** The sender's wallet address. */
|
|
@@ -192,8 +192,8 @@ type InitialTransactionParams = {
|
|
|
192
192
|
* This is used for UI feedback while the transaction is being signed and sent.
|
|
193
193
|
*/
|
|
194
194
|
type InitialTransaction = InitialTransactionParams & {
|
|
195
|
-
/**
|
|
196
|
-
|
|
195
|
+
/** Normalized error if the initialization fails (e.g., user rejects signature). */
|
|
196
|
+
error?: TuwaErrorState;
|
|
197
197
|
/** A flag indicating if the transaction is being processed (e.g., waiting for signature). */
|
|
198
198
|
isInitializing: boolean;
|
|
199
199
|
/** The `txKey` of the on-chain transaction that this action produced, used for linking the states. */
|
|
@@ -307,7 +307,7 @@ type TransactionPool<T extends Transaction> = Record<string, T>;
|
|
|
307
307
|
* on a transaction object via the `updateTxParams` action. This ensures type safety
|
|
308
308
|
* and prevents accidental modification of immutable properties.
|
|
309
309
|
*/
|
|
310
|
-
type UpdatableTransactionFields = Partial<Pick<EvmTransaction, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | '
|
|
310
|
+
type UpdatableTransactionFields = Partial<Pick<EvmTransaction, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | 'error' | 'finishedTimestamp' | 'isTrackedModalOpen' | 'isError' | 'maxPriorityFeePerGas' | 'maxFeePerGas' | 'input' | 'value'>> & Partial<Pick<SolanaTransaction, 'slot' | 'confirmations' | 'fee' | 'instructions' | 'recentBlockhash' | 'rpcUrl'>>;
|
|
311
311
|
/**
|
|
312
312
|
* The interface for the base transaction tracking store slice.
|
|
313
313
|
* It includes the state and actions for managing the transaction lifecycle.
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var immer=require('immer'),orbitCore=require('@tuwaio/orbit-core'),C=require('dayjs'),middleware=require('zustand/middleware'),vanilla=require('zustand/vanilla'),zustand=require('zustand');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var C__default=/*#__PURE__*/_interopDefault(C);function h({maxTransactions:o}){return (t,
|
|
1
|
+
'use strict';var immer=require('immer'),orbitCore=require('@tuwaio/orbit-core'),C=require('dayjs'),middleware=require('zustand/middleware'),vanilla=require('zustand/vanilla'),zustand=require('zustand');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var C__default=/*#__PURE__*/_interopDefault(C);function h({maxTransactions:o}){return (t,a)=>({transactionsPool:{},lastAddedTxKey:void 0,initialTx:void 0,addTxToPool:e=>{t(r=>immer.produce(r,n=>{if(n.lastAddedTxKey=e.txKey,e.txKey){if(Object.keys(n.transactionsPool).length>=o){let d=Object.values(n.transactionsPool).sort((l,x)=>l.localTimestamp-x.localTimestamp);if(d.length>0){let l=d[0];delete n.transactionsPool[l.txKey];}}let s={...e,pending:true};n.transactionsPool[e.txKey]=s;}}));},updateTxParams:(e,r)=>{t(n=>immer.produce(n,i=>{let s=i.transactionsPool[e];s&&Object.assign(s,r);}));},removeTxFromPool:e=>{t(r=>immer.produce(r,n=>{delete n.transactionsPool[e];}));},closeTxTrackedModal:e=>{t(r=>immer.produce(r,n=>{if(e&&n.transactionsPool[e]){let i=n.transactionsPool[e];n.transactionsPool[e]={...i,isTrackedModalOpen:false};}n.initialTx=void 0;}));},getLastTxKey:()=>a().lastAddedTxKey})}var b=o=>Object.values(o).sort((t,a)=>Number(t.localTimestamp)-Number(a.localTimestamp)),_=o=>b(o).filter(t=>t.pending),H=(o,t)=>o[t],E=(o,t)=>b(o).filter(a=>a.from.toLowerCase()===t.toLowerCase()),V=(o,t)=>E(o,t).filter(a=>a.pending);function te({adapter:o,maxTransactions:t=50,...a}){return vanilla.createStore()(middleware.persist((e,r)=>({...h({maxTransactions:t})(e,r),getAdapter:()=>o,initializeTransactionsPool:async()=>{let n=Object.values(r().transactionsPool).filter(i=>i.pending);await Promise.all(n.map(i=>orbitCore.selectAdapterByKey({adapterKey:i.adapter,adapter:o})?.checkAndInitializeTrackerInStore({tx:i,...r()})));},executeTxAction:async({defaultTracker:n,actionFunction:i,params:s,...d})=>{let{desiredChainID:l,...x}=s,{onSuccess:g,onError:m,onReplaced:u}=d,y=C__default.default().unix();e({initialTx:{...s,actionFunction:i,localTimestamp:y,isInitializing:true}});let c=orbitCore.selectAdapterByKey({adapterKey:x.adapter,adapter:o}),A=T=>{e(f=>immer.produce(f,p=>{p.initialTx&&(p.initialTx.isInitializing=false,p.initialTx.error=orbitCore.normalizeError(T));}));};if(!c){let T=new Error("No adapter found for this transaction.");throw A(T),T}try{let{connectorType:T,walletAddress:f}=c.getConnectorInfo();await c.checkChainForTx(l);let p=await i();if(!p){e({initialTx:void 0});return}let{tracker:v,txKey:k}=c.checkTransactionsTracker(p,T),w={...x,connectorType:T,from:f,tracker:v||n,chainId:orbitCore.setChainId(l),localTimestamp:y,txKey:k,hash:v==="ethereum"?p:void 0,pending:!1,isTrackedModalOpen:s.withTrackedModal};r().addTxToPool(w),e(F=>immer.produce(F,S=>{S.initialTx&&(S.initialTx.isInitializing=!1,S.initialTx.lastTxKey=k);}));let R=r().transactionsPool[k];await c.checkAndInitializeTrackerInStore({tx:R,onSuccess:g,onError:m,onReplaced:u,...r()});}catch(T){throw A(T),T}}}),{...a}))}var U=(r=>(r.Ethereum="ethereum",r.Safe="safe",r.Gelato="gelato",r.Solana="solana",r))(U||{}),j=(e=>(e.Failed="Failed",e.Success="Success",e.Replaced="Replaced",e))(j||{});var ae=(o=>t=>zustand.useStore(o,t));var M=5e3,$=10;function ce(o){let{tx:t,fetcher:a,onInitialize:e,onSuccess:r,onFailure:n,onIntervalTick:i,onReplaced:s,removeTxFromPool:d,pollingInterval:l=M,maxRetries:x=$}=o;if(!t.pending)return;e?.();let g=x,m=true,u=c=>{m&&(m=false,d&&!c?.withoutRemoving&&d(t.txKey));};(async()=>{for(;m&&g>0;)try{if(await new Promise(c=>setTimeout(c,l)),!m)break;await a({tx:t,stopPolling:u,onSuccess:r,onFailure:n,onIntervalTick:i,onReplaced:s});}catch(c){console.error(`Polling fetcher for txKey ${t.txKey} threw an error:`,c),g--;}g<=0&&(console.warn(`Polling for txKey ${t.txKey} stopped after reaching the maximum number of retries.`),n(),u());})();}exports.TransactionStatus=j;exports.TransactionTracker=U;exports.createBoundedUseStore=ae;exports.createPulsarStore=te;exports.initializePollingTracker=ce;exports.initializeTxTrackingStore=h;exports.selectAllTransactions=b;exports.selectAllTransactionsByActiveWallet=E;exports.selectPendingTransactions=_;exports.selectPendingTransactionsByActiveWallet=V;exports.selectTxByKey=H;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {produce}from'immer';import {selectAdapterByKey,setChainId}from'@tuwaio/orbit-core';import C from'dayjs';import {persist}from'zustand/middleware';import {createStore}from'zustand/vanilla';import {useStore}from'zustand';function h({maxTransactions:o}){return (t,
|
|
1
|
+
import {produce}from'immer';import {selectAdapterByKey,setChainId,normalizeError}from'@tuwaio/orbit-core';import C from'dayjs';import {persist}from'zustand/middleware';import {createStore}from'zustand/vanilla';import {useStore}from'zustand';function h({maxTransactions:o}){return (t,a)=>({transactionsPool:{},lastAddedTxKey:void 0,initialTx:void 0,addTxToPool:e=>{t(r=>produce(r,n=>{if(n.lastAddedTxKey=e.txKey,e.txKey){if(Object.keys(n.transactionsPool).length>=o){let d=Object.values(n.transactionsPool).sort((l,x)=>l.localTimestamp-x.localTimestamp);if(d.length>0){let l=d[0];delete n.transactionsPool[l.txKey];}}let s={...e,pending:true};n.transactionsPool[e.txKey]=s;}}));},updateTxParams:(e,r)=>{t(n=>produce(n,i=>{let s=i.transactionsPool[e];s&&Object.assign(s,r);}));},removeTxFromPool:e=>{t(r=>produce(r,n=>{delete n.transactionsPool[e];}));},closeTxTrackedModal:e=>{t(r=>produce(r,n=>{if(e&&n.transactionsPool[e]){let i=n.transactionsPool[e];n.transactionsPool[e]={...i,isTrackedModalOpen:false};}n.initialTx=void 0;}));},getLastTxKey:()=>a().lastAddedTxKey})}var b=o=>Object.values(o).sort((t,a)=>Number(t.localTimestamp)-Number(a.localTimestamp)),_=o=>b(o).filter(t=>t.pending),H=(o,t)=>o[t],E=(o,t)=>b(o).filter(a=>a.from.toLowerCase()===t.toLowerCase()),V=(o,t)=>E(o,t).filter(a=>a.pending);function te({adapter:o,maxTransactions:t=50,...a}){return createStore()(persist((e,r)=>({...h({maxTransactions:t})(e,r),getAdapter:()=>o,initializeTransactionsPool:async()=>{let n=Object.values(r().transactionsPool).filter(i=>i.pending);await Promise.all(n.map(i=>selectAdapterByKey({adapterKey:i.adapter,adapter:o})?.checkAndInitializeTrackerInStore({tx:i,...r()})));},executeTxAction:async({defaultTracker:n,actionFunction:i,params:s,...d})=>{let{desiredChainID:l,...x}=s,{onSuccess:g,onError:m,onReplaced:u}=d,y=C().unix();e({initialTx:{...s,actionFunction:i,localTimestamp:y,isInitializing:true}});let c=selectAdapterByKey({adapterKey:x.adapter,adapter:o}),A=T=>{e(f=>produce(f,p=>{p.initialTx&&(p.initialTx.isInitializing=false,p.initialTx.error=normalizeError(T));}));};if(!c){let T=new Error("No adapter found for this transaction.");throw A(T),T}try{let{connectorType:T,walletAddress:f}=c.getConnectorInfo();await c.checkChainForTx(l);let p=await i();if(!p){e({initialTx:void 0});return}let{tracker:v,txKey:k}=c.checkTransactionsTracker(p,T),w={...x,connectorType:T,from:f,tracker:v||n,chainId:setChainId(l),localTimestamp:y,txKey:k,hash:v==="ethereum"?p:void 0,pending:!1,isTrackedModalOpen:s.withTrackedModal};r().addTxToPool(w),e(F=>produce(F,S=>{S.initialTx&&(S.initialTx.isInitializing=!1,S.initialTx.lastTxKey=k);}));let R=r().transactionsPool[k];await c.checkAndInitializeTrackerInStore({tx:R,onSuccess:g,onError:m,onReplaced:u,...r()});}catch(T){throw A(T),T}}}),{...a}))}var U=(r=>(r.Ethereum="ethereum",r.Safe="safe",r.Gelato="gelato",r.Solana="solana",r))(U||{}),j=(e=>(e.Failed="Failed",e.Success="Success",e.Replaced="Replaced",e))(j||{});var ae=(o=>t=>useStore(o,t));var M=5e3,$=10;function ce(o){let{tx:t,fetcher:a,onInitialize:e,onSuccess:r,onFailure:n,onIntervalTick:i,onReplaced:s,removeTxFromPool:d,pollingInterval:l=M,maxRetries:x=$}=o;if(!t.pending)return;e?.();let g=x,m=true,u=c=>{m&&(m=false,d&&!c?.withoutRemoving&&d(t.txKey));};(async()=>{for(;m&&g>0;)try{if(await new Promise(c=>setTimeout(c,l)),!m)break;await a({tx:t,stopPolling:u,onSuccess:r,onFailure:n,onIntervalTick:i,onReplaced:s});}catch(c){console.error(`Polling fetcher for txKey ${t.txKey} threw an error:`,c),g--;}g<=0&&(console.warn(`Polling for txKey ${t.txKey} stopped after reaching the maximum number of retries.`),n(),u());})();}export{j as TransactionStatus,U as TransactionTracker,ae as createBoundedUseStore,te as createPulsarStore,ce as initializePollingTracker,h as initializeTxTrackingStore,b as selectAllTransactions,E as selectAllTransactionsByActiveWallet,_ as selectPendingTransactions,V as selectPendingTransactionsByActiveWallet,H as selectTxByKey};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/pulsar-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@tuwaio/orbit-core": ">=0.2",
|
|
43
|
+
"@tuwaio/orbit-core": ">=0.2.7",
|
|
44
44
|
"dayjs": "1.x.x",
|
|
45
45
|
"immer": "11.x.x",
|
|
46
46
|
"zustand": "5.x.x"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tuwaio/orbit-core": "^0.2.
|
|
49
|
+
"@tuwaio/orbit-core": "^0.2.7",
|
|
50
50
|
"dayjs": "^1.11.19",
|
|
51
51
|
"immer": "^11.1.3",
|
|
52
52
|
"tsup": "^8.5.1",
|
|
53
53
|
"typescript": "^5.9.3",
|
|
54
|
-
"zustand": "^5.0.
|
|
54
|
+
"zustand": "^5.0.11"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"start": "tsup src/index.ts --watch",
|