@chipi-stack/chipi-react 10.0.0 → 11.0.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/README.md +43 -0
- package/dist/hooks.d.mts +20 -23
- package/dist/hooks.d.ts +20 -23
- package/dist/hooks.js +0 -17
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +1 -17
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Chipi SDK
|
|
2
|
+
|
|
3
|
+
Chipi SDK is the easiest way to integrate USDC staking and withdrawal functionality into your React/Next.js application. Add secure wallet management, token staking, and withdrawals to your application in minutes. All transactions are sponsored thanks to Avnu's paymaster.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- React 18 or later
|
|
8
|
+
- Node.js >=18.17.0 or later
|
|
9
|
+
- A Chipi account. [Create your account for free](https://dashboard.chipipay.com)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
The fastest way to get started with Chipi SDK is by following our [Quickstart Guide](https://docs.chipipay.com/gasless/quickstart).
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @chipi-stack/chipi-react
|
|
17
|
+
# or
|
|
18
|
+
yarn add @chipi-stack/chipi-react
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
For detailed information, guides, and examples visit our [documentation](https://docs.chipipay.com).
|
|
24
|
+
|
|
25
|
+
## Support
|
|
26
|
+
|
|
27
|
+
You can get in touch with us in any of the following ways:
|
|
28
|
+
|
|
29
|
+
- Join our [Telegram community](https://t.me/chipi_pay)
|
|
30
|
+
- Visit our [YouTube channel](https://www.youtube.com/@chipipay) for tutorials
|
|
31
|
+
- Email us at support@chipi.com
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
We're open to all community contributions! If you'd like to contribute in any way, please read our contribution guidelines and code of conduct.
|
|
36
|
+
|
|
37
|
+
## Security
|
|
38
|
+
|
|
39
|
+
@chipi-stack/chipi-react follows best practices for security, but 100% security cannot be assured.
|
|
40
|
+
|
|
41
|
+
@chipi-stack/chipi-react is provided "as is" without any warranty. Use at your own risk.
|
|
42
|
+
|
|
43
|
+
For more information and to report security issues, please refer to our [security documentation](https://docs.chipipay.com).
|
package/dist/hooks.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CreateWalletParams, CreateWalletResponse, GetWalletParams,
|
|
1
|
+
import { CreateWalletParams, CreateWalletResponse, GetWalletParams, WalletData, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, RecordSendTransactionParams, Transaction } from '@chipi-stack/types';
|
|
2
2
|
|
|
3
3
|
type CreateWalletInput = {
|
|
4
|
-
params:
|
|
4
|
+
params: CreateWalletParams;
|
|
5
5
|
bearerToken: string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
@@ -20,8 +20,8 @@ declare function useCreateWallet(): {
|
|
|
20
20
|
|
|
21
21
|
declare function useGetWallet(): {
|
|
22
22
|
getWallet: (params: GetWalletParams) => void;
|
|
23
|
-
getWalletAsync: (params: GetWalletParams) => Promise<
|
|
24
|
-
data:
|
|
23
|
+
getWalletAsync: (params: GetWalletParams) => Promise<WalletData>;
|
|
24
|
+
data: WalletData | undefined;
|
|
25
25
|
isLoading: boolean;
|
|
26
26
|
isError: boolean;
|
|
27
27
|
error: Error | null;
|
|
@@ -47,7 +47,10 @@ declare function useTransfer(): {
|
|
|
47
47
|
reset: () => void;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
type ApproveInput =
|
|
50
|
+
type ApproveInput = {
|
|
51
|
+
params: ApproveParams;
|
|
52
|
+
bearerToken: string;
|
|
53
|
+
};
|
|
51
54
|
/**
|
|
52
55
|
* Hook for approving token spending
|
|
53
56
|
*/
|
|
@@ -62,22 +65,10 @@ declare function useApprove(): {
|
|
|
62
65
|
reset: () => void;
|
|
63
66
|
};
|
|
64
67
|
|
|
65
|
-
type
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*/
|
|
69
|
-
declare function useExecuteTransaction(): {
|
|
70
|
-
executeTransaction: (params: ExecuteTransactionInput) => void;
|
|
71
|
-
executeTransactionAsync: (params: ExecuteTransactionInput) => Promise<string>;
|
|
72
|
-
data: string | undefined;
|
|
73
|
-
isLoading: boolean;
|
|
74
|
-
isError: boolean;
|
|
75
|
-
error: Error | null;
|
|
76
|
-
isSuccess: boolean;
|
|
77
|
-
reset: () => void;
|
|
68
|
+
type StakeVesuUsdcInput = {
|
|
69
|
+
params: StakeVesuUsdcParams;
|
|
70
|
+
bearerToken: string;
|
|
78
71
|
};
|
|
79
|
-
|
|
80
|
-
type StakeVesuUsdcInput = Omit<StakeVesuUsdcParams, 'apiPublicKey'>;
|
|
81
72
|
/**
|
|
82
73
|
* Hook for staking USDC in Vesu protocol
|
|
83
74
|
*/
|
|
@@ -92,7 +83,10 @@ declare function useStakeVesuUsdc(): {
|
|
|
92
83
|
reset: () => void;
|
|
93
84
|
};
|
|
94
85
|
|
|
95
|
-
type WithdrawVesuUsdcInput =
|
|
86
|
+
type WithdrawVesuUsdcInput = {
|
|
87
|
+
params: WithdrawVesuUsdcParams;
|
|
88
|
+
bearerToken: string;
|
|
89
|
+
};
|
|
96
90
|
/**
|
|
97
91
|
* Hook for withdrawing USDC from Vesu protocol
|
|
98
92
|
*/
|
|
@@ -107,7 +101,10 @@ declare function useWithdrawVesuUsdc(): {
|
|
|
107
101
|
reset: () => void;
|
|
108
102
|
};
|
|
109
103
|
|
|
110
|
-
type CallAnyContractInput =
|
|
104
|
+
type CallAnyContractInput = {
|
|
105
|
+
params: CallAnyContractParams;
|
|
106
|
+
bearerToken: string;
|
|
107
|
+
};
|
|
111
108
|
/**
|
|
112
109
|
* Hook for calling any contract method
|
|
113
110
|
*/
|
|
@@ -137,4 +134,4 @@ declare function useRecordSendTransaction(): {
|
|
|
137
134
|
reset: () => void;
|
|
138
135
|
};
|
|
139
136
|
|
|
140
|
-
export { useApprove, useCallAnyContract, useCreateWallet,
|
|
137
|
+
export { useApprove, useCallAnyContract, useCreateWallet, useGetWallet, useRecordSendTransaction, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CreateWalletParams, CreateWalletResponse, GetWalletParams,
|
|
1
|
+
import { CreateWalletParams, CreateWalletResponse, GetWalletParams, WalletData, TransferParams, ApproveParams, StakeVesuUsdcParams, WithdrawVesuUsdcParams, CallAnyContractParams, RecordSendTransactionParams, Transaction } from '@chipi-stack/types';
|
|
2
2
|
|
|
3
3
|
type CreateWalletInput = {
|
|
4
|
-
params:
|
|
4
|
+
params: CreateWalletParams;
|
|
5
5
|
bearerToken: string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
@@ -20,8 +20,8 @@ declare function useCreateWallet(): {
|
|
|
20
20
|
|
|
21
21
|
declare function useGetWallet(): {
|
|
22
22
|
getWallet: (params: GetWalletParams) => void;
|
|
23
|
-
getWalletAsync: (params: GetWalletParams) => Promise<
|
|
24
|
-
data:
|
|
23
|
+
getWalletAsync: (params: GetWalletParams) => Promise<WalletData>;
|
|
24
|
+
data: WalletData | undefined;
|
|
25
25
|
isLoading: boolean;
|
|
26
26
|
isError: boolean;
|
|
27
27
|
error: Error | null;
|
|
@@ -47,7 +47,10 @@ declare function useTransfer(): {
|
|
|
47
47
|
reset: () => void;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
type ApproveInput =
|
|
50
|
+
type ApproveInput = {
|
|
51
|
+
params: ApproveParams;
|
|
52
|
+
bearerToken: string;
|
|
53
|
+
};
|
|
51
54
|
/**
|
|
52
55
|
* Hook for approving token spending
|
|
53
56
|
*/
|
|
@@ -62,22 +65,10 @@ declare function useApprove(): {
|
|
|
62
65
|
reset: () => void;
|
|
63
66
|
};
|
|
64
67
|
|
|
65
|
-
type
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*/
|
|
69
|
-
declare function useExecuteTransaction(): {
|
|
70
|
-
executeTransaction: (params: ExecuteTransactionInput) => void;
|
|
71
|
-
executeTransactionAsync: (params: ExecuteTransactionInput) => Promise<string>;
|
|
72
|
-
data: string | undefined;
|
|
73
|
-
isLoading: boolean;
|
|
74
|
-
isError: boolean;
|
|
75
|
-
error: Error | null;
|
|
76
|
-
isSuccess: boolean;
|
|
77
|
-
reset: () => void;
|
|
68
|
+
type StakeVesuUsdcInput = {
|
|
69
|
+
params: StakeVesuUsdcParams;
|
|
70
|
+
bearerToken: string;
|
|
78
71
|
};
|
|
79
|
-
|
|
80
|
-
type StakeVesuUsdcInput = Omit<StakeVesuUsdcParams, 'apiPublicKey'>;
|
|
81
72
|
/**
|
|
82
73
|
* Hook for staking USDC in Vesu protocol
|
|
83
74
|
*/
|
|
@@ -92,7 +83,10 @@ declare function useStakeVesuUsdc(): {
|
|
|
92
83
|
reset: () => void;
|
|
93
84
|
};
|
|
94
85
|
|
|
95
|
-
type WithdrawVesuUsdcInput =
|
|
86
|
+
type WithdrawVesuUsdcInput = {
|
|
87
|
+
params: WithdrawVesuUsdcParams;
|
|
88
|
+
bearerToken: string;
|
|
89
|
+
};
|
|
96
90
|
/**
|
|
97
91
|
* Hook for withdrawing USDC from Vesu protocol
|
|
98
92
|
*/
|
|
@@ -107,7 +101,10 @@ declare function useWithdrawVesuUsdc(): {
|
|
|
107
101
|
reset: () => void;
|
|
108
102
|
};
|
|
109
103
|
|
|
110
|
-
type CallAnyContractInput =
|
|
104
|
+
type CallAnyContractInput = {
|
|
105
|
+
params: CallAnyContractParams;
|
|
106
|
+
bearerToken: string;
|
|
107
|
+
};
|
|
111
108
|
/**
|
|
112
109
|
* Hook for calling any contract method
|
|
113
110
|
*/
|
|
@@ -137,4 +134,4 @@ declare function useRecordSendTransaction(): {
|
|
|
137
134
|
reset: () => void;
|
|
138
135
|
};
|
|
139
136
|
|
|
140
|
-
export { useApprove, useCallAnyContract, useCreateWallet,
|
|
137
|
+
export { useApprove, useCallAnyContract, useCreateWallet, useGetWallet, useRecordSendTransaction, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|
package/dist/hooks.js
CHANGED
|
@@ -113,22 +113,6 @@ function useApprove() {
|
|
|
113
113
|
reset: mutation.reset
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
-
function useExecuteTransaction() {
|
|
117
|
-
const { chipiSDK } = useChipiContext();
|
|
118
|
-
const mutation = reactQuery.useMutation({
|
|
119
|
-
mutationFn: (params) => chipiSDK.executeTransaction(params)
|
|
120
|
-
});
|
|
121
|
-
return {
|
|
122
|
-
executeTransaction: mutation.mutate,
|
|
123
|
-
executeTransactionAsync: mutation.mutateAsync,
|
|
124
|
-
data: mutation.data,
|
|
125
|
-
isLoading: mutation.isPending,
|
|
126
|
-
isError: mutation.isError,
|
|
127
|
-
error: mutation.error,
|
|
128
|
-
isSuccess: mutation.isSuccess,
|
|
129
|
-
reset: mutation.reset
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
116
|
function useStakeVesuUsdc() {
|
|
133
117
|
const { chipiSDK } = useChipiContext();
|
|
134
118
|
const mutation = reactQuery.useMutation({
|
|
@@ -200,7 +184,6 @@ function useRecordSendTransaction() {
|
|
|
200
184
|
exports.useApprove = useApprove;
|
|
201
185
|
exports.useCallAnyContract = useCallAnyContract;
|
|
202
186
|
exports.useCreateWallet = useCreateWallet;
|
|
203
|
-
exports.useExecuteTransaction = useExecuteTransaction;
|
|
204
187
|
exports.useGetWallet = useGetWallet;
|
|
205
188
|
exports.useRecordSendTransaction = useRecordSendTransaction;
|
|
206
189
|
exports.useStakeVesuUsdc = useStakeVesuUsdc;
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useExecuteTransaction.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["createContext","useContext","useMutation","useQueryClient","useState","useQuery"],"mappings":";;;;;;;;AAUA,IAAM,YAAA,GAAeA,oBAAwC,IAAI,CAAA;AAuD1D,SAAS,eAAA,GAAqC;AACnD,EAAA,MAAM,OAAA,GAAUC,iBAAW,YAAY,CAAA;AAEvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,qDAAqD,CAAA;AAAA,EACvE;AAEA,EAAA,OAAO,OAAA;AACT;;;AC1DO,SAAS,eAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFC,sBAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,YAAA,CAAa;AAAA,MACpB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,cAAc,QAAA,CAAS,MAAA;AAAA,IACvB,mBAAmB,QAAA,CAAS,WAAA;AAAA,IAC5B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;ACzCA,IA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AAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"hooks.js","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: Omit<CreateWalletParams, \"nodeUrl\">;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\n\"use client\";\n\nimport { useState } from \"react\";\nimport { useQuery, useQueryClient, type UseQueryResult } from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletDataResponse } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\n\n\nconst walletKey = (externalUserId: string) => [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletDataResponse>;\n data: WalletDataResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletDataResponse, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || ''),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params, \n staleTime: Infinity, \n gcTime: Infinity, \n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n\n const getWalletAsync = (walletParams: GetWalletParams): Promise<WalletDataResponse> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => { if (params) void query.refetch(); },\n };\n}","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { ApproveParams } from '@chipi-stack/types';\n\ntype ApproveInput = Omit<ApproveParams, 'apiPublicKey'>;\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { ExecuteTransactionParams } from '@chipi-stack/types';\n\ntype ExecuteTransactionInput = Omit<ExecuteTransactionParams, 'apiPublicKey'>;\n\n/**\n * Hook for executing gasless transactions\n */\nexport function useExecuteTransaction(): {\n executeTransaction: (params: ExecuteTransactionInput) => void;\n executeTransactionAsync: (params: ExecuteTransactionInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ExecuteTransactionInput> = useMutation({\n mutationFn: (params: ExecuteTransactionInput) => chipiSDK.executeTransaction(params),\n });\n\n return {\n executeTransaction: mutation.mutate,\n executeTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { StakeVesuUsdcParams } from '@chipi-stack/types';\n\ntype StakeVesuUsdcInput = Omit<StakeVesuUsdcParams, 'apiPublicKey'>;\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> = useMutation({\n mutationFn: (params: StakeVesuUsdcInput) => chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { WithdrawVesuUsdcParams } from '@chipi-stack/types';\n\ntype WithdrawVesuUsdcInput = Omit<WithdrawVesuUsdcParams, 'apiPublicKey'>;\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> = useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) => chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { CallAnyContractParams } from '@chipi-stack/types';\n\ntype CallAnyContractInput = Omit<CallAnyContractParams, 'apiPublicKey'>;\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> = useMutation({\n mutationFn: (params: CallAnyContractInput) => chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["createContext","useContext","useMutation","useQueryClient","useState","useQuery"],"mappings":";;;;;;;;AAUA,IAAM,YAAA,GAAeA,oBAAwC,IAAI,CAAA;AAuD1D,SAAS,eAAA,GAAqC;AACnD,EAAA,MAAM,OAAA,GAAUC,iBAAW,YAAY,CAAA;AAEvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,qDAAqD,CAAA;AAAA,EACvE;AAEA,EAAA,OAAO,OAAA;AACT;;;AC1DO,SAAS,eAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFC,sBAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,YAAA,CAAa;AAAA,MACpB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,cAAc,QAAA,CAAS,MAAA;AAAA,IACvB,mBAAmB,QAAA,CAAS,WAAA;AAAA,IAC5B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OA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AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;AC5BO,SAAS,kBAAA,GASd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WACJA,sBAAAA,CAAY;AAAA,IACV,UAAA,EAAY,CAAC,MAAA,KACX,QAAA,CAAS,gBAAgB,MAAM;AAAA,GAClC,CAAA;AAEH,EAAA,OAAO;AAAA,IACL,iBAAiB,QAAA,CAAS,MAAA;AAAA,IAC1B,sBAAsB,QAAA,CAAS,WAAA;AAAA,IAC/B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;AC5BO,SAAS,wBAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFA,sBAAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,qBAAA,CAAsB;AAAA,MAC7B,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"hooks.js","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: CreateWalletParams;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport {\n useQuery,\n useQueryClient,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletData } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\nconst walletKey = (externalUserId: string) =>\n [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletData>;\n data: WalletData | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletData, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || \"\"),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params,\n staleTime: Infinity,\n gcTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n const getWalletAsync = (\n walletParams: GetWalletParams\n ): Promise<WalletData> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => {\n if (params) void query.refetch();\n },\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { ApproveParams } from \"@chipi-stack/types\";\n\ntype ApproveInput = {\n params: ApproveParams;\n bearerToken: string;\n};\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { StakeVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype StakeVesuUsdcInput = {\n params: StakeVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> =\n useMutation({\n mutationFn: (params: StakeVesuUsdcInput) =>\n chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { WithdrawVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype WithdrawVesuUsdcInput = {\n params: WithdrawVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> =\n useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) =>\n chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { CallAnyContractParams } from \"@chipi-stack/types\";\n\ntype CallAnyContractInput = {\n params: CallAnyContractParams;\n bearerToken: string;\n};\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> =\n useMutation({\n mutationFn: (params: CallAnyContractInput) =>\n chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
package/dist/hooks.mjs
CHANGED
|
@@ -111,22 +111,6 @@ function useApprove() {
|
|
|
111
111
|
reset: mutation.reset
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
function useExecuteTransaction() {
|
|
115
|
-
const { chipiSDK } = useChipiContext();
|
|
116
|
-
const mutation = useMutation({
|
|
117
|
-
mutationFn: (params) => chipiSDK.executeTransaction(params)
|
|
118
|
-
});
|
|
119
|
-
return {
|
|
120
|
-
executeTransaction: mutation.mutate,
|
|
121
|
-
executeTransactionAsync: mutation.mutateAsync,
|
|
122
|
-
data: mutation.data,
|
|
123
|
-
isLoading: mutation.isPending,
|
|
124
|
-
isError: mutation.isError,
|
|
125
|
-
error: mutation.error,
|
|
126
|
-
isSuccess: mutation.isSuccess,
|
|
127
|
-
reset: mutation.reset
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
114
|
function useStakeVesuUsdc() {
|
|
131
115
|
const { chipiSDK } = useChipiContext();
|
|
132
116
|
const mutation = useMutation({
|
|
@@ -195,6 +179,6 @@ function useRecordSendTransaction() {
|
|
|
195
179
|
};
|
|
196
180
|
}
|
|
197
181
|
|
|
198
|
-
export { useApprove, useCallAnyContract, useCreateWallet,
|
|
182
|
+
export { useApprove, useCallAnyContract, useCreateWallet, useGetWallet, useRecordSendTransaction, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|
|
199
183
|
//# sourceMappingURL=hooks.mjs.map
|
|
200
184
|
//# sourceMappingURL=hooks.mjs.map
|
package/dist/hooks.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useExecuteTransaction.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["useMutation"],"mappings":";;;;;;AAUA,IAAM,YAAA,GAAe,cAAwC,IAAI,CAAA;AAuD1D,SAAS,eAAA,GAAqC;AACnD,EAAA,MAAM,OAAA,GAAU,WAAW,YAAY,CAAA;AAEvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,qDAAqD,CAAA;AAAA,EACvE;AAEA,EAAA,OAAO,OAAA;AACT;;;AC1DO,SAAS,eAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIF,WAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,YAAA,CAAa;AAAA,MACpB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,cAAc,QAAA,CAAS,MAAA;AAAA,IACvB,mBAAmB,QAAA,CAAS,WAAA;AAAA,IAC5B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,Q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Q,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"hooks.mjs","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: Omit<CreateWalletParams, \"nodeUrl\">;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\n\"use client\";\n\nimport { useState } from \"react\";\nimport { useQuery, useQueryClient, type UseQueryResult } from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletDataResponse } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\n\n\nconst walletKey = (externalUserId: string) => [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletDataResponse>;\n data: WalletDataResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletDataResponse, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || ''),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params, \n staleTime: Infinity, \n gcTime: Infinity, \n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n\n const getWalletAsync = (walletParams: GetWalletParams): Promise<WalletDataResponse> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => { if (params) void query.refetch(); },\n };\n}","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { ApproveParams } from '@chipi-stack/types';\n\ntype ApproveInput = Omit<ApproveParams, 'apiPublicKey'>;\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { ExecuteTransactionParams } from '@chipi-stack/types';\n\ntype ExecuteTransactionInput = Omit<ExecuteTransactionParams, 'apiPublicKey'>;\n\n/**\n * Hook for executing gasless transactions\n */\nexport function useExecuteTransaction(): {\n executeTransaction: (params: ExecuteTransactionInput) => void;\n executeTransactionAsync: (params: ExecuteTransactionInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ExecuteTransactionInput> = useMutation({\n mutationFn: (params: ExecuteTransactionInput) => chipiSDK.executeTransaction(params),\n });\n\n return {\n executeTransaction: mutation.mutate,\n executeTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { StakeVesuUsdcParams } from '@chipi-stack/types';\n\ntype StakeVesuUsdcInput = Omit<StakeVesuUsdcParams, 'apiPublicKey'>;\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> = useMutation({\n mutationFn: (params: StakeVesuUsdcInput) => chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { WithdrawVesuUsdcParams } from '@chipi-stack/types';\n\ntype WithdrawVesuUsdcInput = Omit<WithdrawVesuUsdcParams, 'apiPublicKey'>;\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> = useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) => chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { CallAnyContractParams } from '@chipi-stack/types';\n\ntype CallAnyContractInput = Omit<CallAnyContractParams, 'apiPublicKey'>;\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> = useMutation({\n mutationFn: (params: CallAnyContractInput) => chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["useMutation"],"mappings":";;;;;;AAUA,IAAM,YAAA,GAAe,cAAwC,IAAI,CAAA;AAuD1D,SAAS,eAAA,GAAqC;AACnD,EAAA,MAAM,OAAA,GAAU,WAAW,YAAY,CAAA;AAEvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,qDAAqD,CAAA;AAAA,EACvE;AAEA,EAAA,OAAO,OAAA;AACT;;;AC1DO,SAAS,eAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIF,WAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,YAAA,CAAa;AAAA,MACpB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,cAAc,QAAA,CAAS,MAAA;AAAA,IACvB,mBAAmB,QAAA,CAAS,WAAA;AAAA,IAC5B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CA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,CAAS;AAAA,GAClB;AACF;AC5BO,SAAS,kBAAA,GASd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WACJA,WAAAA,CAAY;AAAA,IACV,UAAA,EAAY,CAAC,MAAA,KACX,QAAA,CAAS,gBAAgB,MAAM;AAAA,GAClC,CAAA;AAEH,EAAA,OAAO;AAAA,IACL,iBAAiB,QAAA,CAAS,MAAA;AAAA,IAC1B,sBAAsB,QAAA,CAAS,WAAA;AAAA,IAC/B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;AC5BO,SAAS,wBAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFA,WAAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,qBAAA,CAAsB;AAAA,MAC7B,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"hooks.mjs","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: CreateWalletParams;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport {\n useQuery,\n useQueryClient,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletData } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\nconst walletKey = (externalUserId: string) =>\n [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletData>;\n data: WalletData | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletData, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || \"\"),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params,\n staleTime: Infinity,\n gcTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n const getWalletAsync = (\n walletParams: GetWalletParams\n ): Promise<WalletData> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => {\n if (params) void query.refetch();\n },\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { ApproveParams } from \"@chipi-stack/types\";\n\ntype ApproveInput = {\n params: ApproveParams;\n bearerToken: string;\n};\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { StakeVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype StakeVesuUsdcInput = {\n params: StakeVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> =\n useMutation({\n mutationFn: (params: StakeVesuUsdcInput) =>\n chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { WithdrawVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype WithdrawVesuUsdcInput = {\n params: WithdrawVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> =\n useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) =>\n chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { CallAnyContractParams } from \"@chipi-stack/types\";\n\ntype CallAnyContractInput = {\n params: CallAnyContractParams;\n bearerToken: string;\n};\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> =\n useMutation({\n mutationFn: (params: CallAnyContractInput) =>\n chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { ChipiSDK } from '@chipi-stack/backend';
|
|
4
4
|
import { ChipiSDKConfig } from '@chipi-stack/types';
|
|
5
5
|
export * from '@chipi-stack/types';
|
|
6
|
-
export { useApprove, useCallAnyContract, useCreateWallet,
|
|
6
|
+
export { useApprove, useCallAnyContract, useCreateWallet, useGetWallet, useRecordSendTransaction, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc } from './hooks.mjs';
|
|
7
7
|
|
|
8
8
|
interface ChipiContextValue {
|
|
9
9
|
chipiSDK: ChipiSDK;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { ChipiSDK } from '@chipi-stack/backend';
|
|
4
4
|
import { ChipiSDKConfig } from '@chipi-stack/types';
|
|
5
5
|
export * from '@chipi-stack/types';
|
|
6
|
-
export { useApprove, useCallAnyContract, useCreateWallet,
|
|
6
|
+
export { useApprove, useCallAnyContract, useCreateWallet, useGetWallet, useRecordSendTransaction, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc } from './hooks.js';
|
|
7
7
|
|
|
8
8
|
interface ChipiContextValue {
|
|
9
9
|
chipiSDK: ChipiSDK;
|
package/dist/index.js
CHANGED
|
@@ -146,22 +146,6 @@ function useApprove() {
|
|
|
146
146
|
reset: mutation.reset
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function useExecuteTransaction() {
|
|
150
|
-
const { chipiSDK } = useChipiContext();
|
|
151
|
-
const mutation = reactQuery.useMutation({
|
|
152
|
-
mutationFn: (params) => chipiSDK.executeTransaction(params)
|
|
153
|
-
});
|
|
154
|
-
return {
|
|
155
|
-
executeTransaction: mutation.mutate,
|
|
156
|
-
executeTransactionAsync: mutation.mutateAsync,
|
|
157
|
-
data: mutation.data,
|
|
158
|
-
isLoading: mutation.isPending,
|
|
159
|
-
isError: mutation.isError,
|
|
160
|
-
error: mutation.error,
|
|
161
|
-
isSuccess: mutation.isSuccess,
|
|
162
|
-
reset: mutation.reset
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
149
|
function useStakeVesuUsdc() {
|
|
166
150
|
const { chipiSDK } = useChipiContext();
|
|
167
151
|
const mutation = reactQuery.useMutation({
|
|
@@ -235,7 +219,6 @@ exports.useApprove = useApprove;
|
|
|
235
219
|
exports.useCallAnyContract = useCallAnyContract;
|
|
236
220
|
exports.useChipiContext = useChipiContext;
|
|
237
221
|
exports.useCreateWallet = useCreateWallet;
|
|
238
|
-
exports.useExecuteTransaction = useExecuteTransaction;
|
|
239
222
|
exports.useGetWallet = useGetWallet;
|
|
240
223
|
exports.useRecordSendTransaction = useRecordSendTransaction;
|
|
241
224
|
exports.useStakeVesuUsdc = useStakeVesuUsdc;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useExecuteTransaction.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["createContext","QueryClient","React","ChipiSDK","jsx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AAO,QAAA,CAAS;AAAA,GAClB;AACF;AC1BO,SAAS,kBAAA,GASd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAAmEA,sBAAAA,CAAY;AAAA,IACnF,UAAA,EAAY,CAAC,MAAA,KAAiC,QAAA,CAAS,gBAAgB,MAAM;AAAA,GAC9E,CAAA;AAED,EAAA,OAAO;AAAA,IACL,iBAAiB,QAAA,CAAS,MAAA;AAAA,IAC1B,sBAAsB,QAAA,CAAS,WAAA;AAAA,IAC/B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;ACvBO,SAAS,wBAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFA,sBAAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,qBAAA,CAAsB;AAAA,MAC7B,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"index.js","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: Omit<CreateWalletParams, \"nodeUrl\">;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\n\"use client\";\n\nimport { useState } from \"react\";\nimport { useQuery, useQueryClient, type UseQueryResult } from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletDataResponse } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\n\n\nconst walletKey = (externalUserId: string) => [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletDataResponse>;\n data: WalletDataResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletDataResponse, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || ''),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params, \n staleTime: Infinity, \n gcTime: Infinity, \n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n\n const getWalletAsync = (walletParams: GetWalletParams): Promise<WalletDataResponse> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => { if (params) void query.refetch(); },\n };\n}","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { ApproveParams } from '@chipi-stack/types';\n\ntype ApproveInput = Omit<ApproveParams, 'apiPublicKey'>;\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { ExecuteTransactionParams } from '@chipi-stack/types';\n\ntype ExecuteTransactionInput = Omit<ExecuteTransactionParams, 'apiPublicKey'>;\n\n/**\n * Hook for executing gasless transactions\n */\nexport function useExecuteTransaction(): {\n executeTransaction: (params: ExecuteTransactionInput) => void;\n executeTransactionAsync: (params: ExecuteTransactionInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ExecuteTransactionInput> = useMutation({\n mutationFn: (params: ExecuteTransactionInput) => chipiSDK.executeTransaction(params),\n });\n\n return {\n executeTransaction: mutation.mutate,\n executeTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { StakeVesuUsdcParams } from '@chipi-stack/types';\n\ntype StakeVesuUsdcInput = Omit<StakeVesuUsdcParams, 'apiPublicKey'>;\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> = useMutation({\n mutationFn: (params: StakeVesuUsdcInput) => chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { WithdrawVesuUsdcParams } from '@chipi-stack/types';\n\ntype WithdrawVesuUsdcInput = Omit<WithdrawVesuUsdcParams, 'apiPublicKey'>;\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> = useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) => chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { CallAnyContractParams } from '@chipi-stack/types';\n\ntype CallAnyContractInput = Omit<CallAnyContractParams, 'apiPublicKey'>;\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> = useMutation({\n mutationFn: (params: CallAnyContractInput) => chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["createCont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IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;AC5BO,SAAS,wBAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFA,sBAAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,qBAAA,CAAsB;AAAA,MAC7B,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"index.js","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: CreateWalletParams;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport {\n useQuery,\n useQueryClient,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletData } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\nconst walletKey = (externalUserId: string) =>\n [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletData>;\n data: WalletData | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletData, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || \"\"),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params,\n staleTime: Infinity,\n gcTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n const getWalletAsync = (\n walletParams: GetWalletParams\n ): Promise<WalletData> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => {\n if (params) void query.refetch();\n },\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { ApproveParams } from \"@chipi-stack/types\";\n\ntype ApproveInput = {\n params: ApproveParams;\n bearerToken: string;\n};\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { StakeVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype StakeVesuUsdcInput = {\n params: StakeVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> =\n useMutation({\n mutationFn: (params: StakeVesuUsdcInput) =>\n chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { WithdrawVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype WithdrawVesuUsdcInput = {\n params: WithdrawVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> =\n useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) =>\n chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { CallAnyContractParams } from \"@chipi-stack/types\";\n\ntype CallAnyContractInput = {\n params: CallAnyContractParams;\n bearerToken: string;\n};\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> =\n useMutation({\n mutationFn: (params: CallAnyContractInput) =>\n chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -140,22 +140,6 @@ function useApprove() {
|
|
|
140
140
|
reset: mutation.reset
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
function useExecuteTransaction() {
|
|
144
|
-
const { chipiSDK } = useChipiContext();
|
|
145
|
-
const mutation = useMutation({
|
|
146
|
-
mutationFn: (params) => chipiSDK.executeTransaction(params)
|
|
147
|
-
});
|
|
148
|
-
return {
|
|
149
|
-
executeTransaction: mutation.mutate,
|
|
150
|
-
executeTransactionAsync: mutation.mutateAsync,
|
|
151
|
-
data: mutation.data,
|
|
152
|
-
isLoading: mutation.isPending,
|
|
153
|
-
isError: mutation.isError,
|
|
154
|
-
error: mutation.error,
|
|
155
|
-
isSuccess: mutation.isSuccess,
|
|
156
|
-
reset: mutation.reset
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
143
|
function useStakeVesuUsdc() {
|
|
160
144
|
const { chipiSDK } = useChipiContext();
|
|
161
145
|
const mutation = useMutation({
|
|
@@ -224,6 +208,6 @@ function useRecordSendTransaction() {
|
|
|
224
208
|
};
|
|
225
209
|
}
|
|
226
210
|
|
|
227
|
-
export { ChipiProvider, useApprove, useCallAnyContract, useChipiContext, useCreateWallet,
|
|
211
|
+
export { ChipiProvider, useApprove, useCallAnyContract, useChipiContext, useCreateWallet, useGetWallet, useRecordSendTransaction, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|
|
228
212
|
//# sourceMappingURL=index.mjs.map
|
|
229
213
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useExecuteTransaction.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["useMutation"],"mappings":";;;;;;AAUA,IAAM,YAAA,GAAe,cAAwC,IAAI,CAAA;AAQjE,IAAM,wBAAA,GAA2B,MAC/B,IAAI,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AC,MAAA,KAAiC,QAAA,CAAS,gBAAgB,MAAM;AAAA,GAC9E,CAAA;AAED,EAAA,OAAO;AAAA,IACL,iBAAiB,QAAA,CAAS,MAAA;AAAA,IAC1B,sBAAsB,QAAA,CAAS,WAAA;AAAA,IAC/B,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;ACvBO,SAAS,wBAAA,GAWd;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,eAAA,EAAgB;AAErC,EAAA,MAAM,WAIFA,WAAAA,CAAY;AAAA,IACd,UAAA,EAAY,CAAC,KAAA,KACX,QAAA,CAAS,qBAAA,CAAsB;AAAA,MAC7B,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,aAAa,KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"index.mjs","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: Omit<CreateWalletParams, \"nodeUrl\">;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\n\"use client\";\n\nimport { useState } from \"react\";\nimport { useQuery, useQueryClient, type UseQueryResult } from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletDataResponse } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\n\n\nconst walletKey = (externalUserId: string) => [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletDataResponse>;\n data: WalletDataResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletDataResponse, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || ''),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params, \n staleTime: Infinity, \n gcTime: Infinity, \n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n\n const getWalletAsync = (walletParams: GetWalletParams): Promise<WalletDataResponse> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => { if (params) void query.refetch(); },\n };\n}","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { ApproveParams } from '@chipi-stack/types';\n\ntype ApproveInput = Omit<ApproveParams, 'apiPublicKey'>;\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { ExecuteTransactionParams } from '@chipi-stack/types';\n\ntype ExecuteTransactionInput = Omit<ExecuteTransactionParams, 'apiPublicKey'>;\n\n/**\n * Hook for executing gasless transactions\n */\nexport function useExecuteTransaction(): {\n executeTransaction: (params: ExecuteTransactionInput) => void;\n executeTransactionAsync: (params: ExecuteTransactionInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ExecuteTransactionInput> = useMutation({\n mutationFn: (params: ExecuteTransactionInput) => chipiSDK.executeTransaction(params),\n });\n\n return {\n executeTransaction: mutation.mutate,\n executeTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { StakeVesuUsdcParams } from '@chipi-stack/types';\n\ntype StakeVesuUsdcInput = Omit<StakeVesuUsdcParams, 'apiPublicKey'>;\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> = useMutation({\n mutationFn: (params: StakeVesuUsdcInput) => chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { WithdrawVesuUsdcParams } from '@chipi-stack/types';\n\ntype WithdrawVesuUsdcInput = Omit<WithdrawVesuUsdcParams, 'apiPublicKey'>;\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> = useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) => chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { useChipiContext } from '../context';\nimport type { CallAnyContractParams } from '@chipi-stack/types';\n\ntype CallAnyContractInput = Omit<CallAnyContractParams, 'apiPublicKey'>;\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> = useMutation({\n mutationFn: (params: CallAnyContractInput) => chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/context/ChipiProvider.tsx","../src/hooks/useCreateWallet.ts","../src/hooks/useGetWallet.ts","../src/hooks/useTransfer.ts","../src/hooks/useApprove.ts","../src/hooks/useStakeVesuUsdc.ts","../src/hooks/useWithdrawVesuUsdc.ts","../src/hooks/useCallAnyContract.ts","../src/hooks/useRecordSendTransaction.ts"],"names":["useMutation"],"mappings":";;;;;;AAUA,IAAM,YAAA,GAAe,cAAwC,IAAI,CAAA;AAQjE,IAAM,wBAAA,GAA2B,MAC/B,IAAI,WAAA,CAAY;AAAA,EACd,cAAA,EAAgB;AAAA,IACd,OAAA,EAAS;AAAA,MACP,WAAW,E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KAAA,CAAM;AAAA,KACpB;AAAA,GACJ,CAAA;AAED,EAAA,OAAO;AAAA,IACL,uBAAuB,QAAA,CAAS,MAAA;AAAA,IAChC,4BAA4B,QAAA,CAAS,WAAA;AAAA,IACrC,MAAM,QAAA,CAAS,IAAA;AAAA,IACf,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,SAAS,QAAA,CAAS,OAAA;AAAA,IAClB,OAAO,QAAA,CAAS,KAAA;AAAA,IAChB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF","file":"index.mjs","sourcesContent":["import React, { createContext, useContext, ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { ChipiSDK } from \"@chipi-stack/backend\";\nimport type { ChipiSDKConfig } from \"@chipi-stack/types\";\n\ninterface ChipiContextValue {\n chipiSDK: ChipiSDK;\n config: ChipiSDKConfig;\n}\n\nconst ChipiContext = createContext<ChipiContextValue | null>(null);\n\ninterface ChipiProviderProps {\n children: ReactNode;\n config: ChipiSDKConfig;\n}\n\n// Default QueryClient configuration\nconst createDefaultQueryClient = () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 60 * 1000, // 1 minute\n gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)\n retry: (failureCount, error: any) => {\n // Don't retry on 4xx errors\n if (error?.status >= 400 && error?.status < 500) {\n return false;\n }\n return failureCount < 3;\n },\n },\n mutations: {\n retry: false,\n },\n },\n });\n\n/**\n * Provider component that wraps your app and provides Chipi SDK context with QueryClient\n */\nexport function ChipiProvider({ children, config }: ChipiProviderProps) {\n // Create QueryClient\n const queryClient = React.useMemo(() => createDefaultQueryClient(), []);\n\n const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);\n\n const value = React.useMemo(\n () => ({\n chipiSDK,\n config,\n }),\n [chipiSDK, config]\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <ChipiContext.Provider value={value}>{children}</ChipiContext.Provider>\n </QueryClientProvider>\n );\n}\n\n/**\n * Hook to access Chipi SDK context\n */\nexport function useChipiContext(): ChipiContextValue {\n const context = useContext(ChipiContext);\n\n if (!context) {\n throw new Error(\"useChipiContext must be used within a ChipiProvider\");\n }\n\n return context;\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n CreateWalletParams,\n CreateWalletResponse,\n} from \"@chipi-stack/types\";\n\ntype CreateWalletInput = {\n params: CreateWalletParams;\n bearerToken: string;\n};\n\n/**\n * Hook for creating a new wallet\n */\nexport function useCreateWallet(): {\n createWallet: (input: CreateWalletInput) => void;\n createWalletAsync: (\n input: CreateWalletInput\n ) => Promise<CreateWalletResponse>;\n data: CreateWalletResponse | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n CreateWalletResponse,\n Error,\n CreateWalletInput\n > = useMutation({\n mutationFn: (input: CreateWalletInput) =>\n chipiSDK.createWallet({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n createWallet: mutation.mutate,\n createWalletAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport {\n useQuery,\n useQueryClient,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { GetWalletParams, WalletData } from \"@chipi-stack/types\";\nimport { useChipiContext } from \"../context\";\n\nconst walletKey = (externalUserId: string) =>\n [\"wallet\", externalUserId] as const;\n\nexport function useGetWallet(): {\n getWallet: (params: GetWalletParams) => void;\n getWalletAsync: (params: GetWalletParams) => Promise<WalletData>;\n data: WalletData | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n refetch: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n const queryClient = useQueryClient();\n\n const [params, setParams] = useState<GetWalletParams | null>(null);\n\n const query: UseQueryResult<WalletData, Error> = useQuery({\n queryKey: walletKey(params?.externalUserId || \"\"),\n queryFn: () => {\n if (!params) throw new Error(\"No wallet params provided\");\n return chipiSDK.getWallet(params);\n },\n enabled: !!params,\n staleTime: Infinity,\n gcTime: Infinity,\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n });\n\n const getWallet = (walletParams: GetWalletParams) => {\n setParams(walletParams);\n };\n\n const getWalletAsync = (\n walletParams: GetWalletParams\n ): Promise<WalletData> => {\n return queryClient.fetchQuery({\n queryKey: walletKey(walletParams.externalUserId),\n queryFn: () => chipiSDK.getWallet(walletParams),\n staleTime: Infinity,\n gcTime: Infinity,\n });\n };\n\n return {\n getWallet,\n getWalletAsync,\n data: query.data,\n isLoading: query.isLoading,\n isError: query.isError,\n error: query.error ?? null,\n isSuccess: query.isSuccess,\n refetch: () => {\n if (params) void query.refetch();\n },\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { TransferParams } from \"@chipi-stack/types\";\n\ntype TransferInput = { params: TransferParams; bearerToken: string };\n\n/**\n * Hook for transferring tokens\n */\nexport function useTransfer(): {\n transfer: (input: TransferInput) => void;\n transferAsync: (input: TransferInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, TransferInput> = useMutation(\n {\n mutationFn: (input: TransferInput) =>\n chipiSDK.transfer({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n }\n );\n\n return {\n transfer: mutation.mutate,\n transferAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { ApproveParams } from \"@chipi-stack/types\";\n\ntype ApproveInput = {\n params: ApproveParams;\n bearerToken: string;\n};\n\n/**\n * Hook for approving token spending\n */\nexport function useApprove(): {\n approve: (params: ApproveInput) => void;\n approveAsync: (params: ApproveInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, ApproveInput> = useMutation({\n mutationFn: (params: ApproveInput) => chipiSDK.approve(params),\n });\n\n return {\n approve: mutation.mutate,\n approveAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { StakeVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype StakeVesuUsdcInput = {\n params: StakeVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for staking USDC in Vesu protocol\n */\nexport function useStakeVesuUsdc(): {\n stakeVesuUsdc: (params: StakeVesuUsdcInput) => void;\n stakeVesuUsdcAsync: (params: StakeVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, StakeVesuUsdcInput> =\n useMutation({\n mutationFn: (params: StakeVesuUsdcInput) =>\n chipiSDK.stakeVesuUsdc(params),\n });\n\n return {\n stakeVesuUsdc: mutation.mutate,\n stakeVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { WithdrawVesuUsdcParams } from \"@chipi-stack/types\";\n\ntype WithdrawVesuUsdcInput = {\n params: WithdrawVesuUsdcParams;\n bearerToken: string;\n};\n\n/**\n * Hook for withdrawing USDC from Vesu protocol\n */\nexport function useWithdrawVesuUsdc(): {\n withdrawVesuUsdc: (params: WithdrawVesuUsdcInput) => void;\n withdrawVesuUsdcAsync: (params: WithdrawVesuUsdcInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, WithdrawVesuUsdcInput> =\n useMutation({\n mutationFn: (params: WithdrawVesuUsdcInput) =>\n chipiSDK.withdrawVesuUsdc(params),\n });\n\n return {\n withdrawVesuUsdc: mutation.mutate,\n withdrawVesuUsdcAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type { CallAnyContractParams } from \"@chipi-stack/types\";\n\ntype CallAnyContractInput = {\n params: CallAnyContractParams;\n bearerToken: string;\n};\n\n/**\n * Hook for calling any contract method\n */\nexport function useCallAnyContract(): {\n callAnyContract: (params: CallAnyContractInput) => void;\n callAnyContractAsync: (params: CallAnyContractInput) => Promise<string>;\n data: string | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<string, Error, CallAnyContractInput> =\n useMutation({\n mutationFn: (params: CallAnyContractInput) =>\n chipiSDK.callAnyContract(params),\n });\n\n return {\n callAnyContract: mutation.mutate,\n callAnyContractAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n","import { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useChipiContext } from \"../context\";\nimport type {\n RecordSendTransactionParams,\n Transaction,\n} from \"@chipi-stack/types\";\n\ntype RecordSendTransactionInput = {\n params: RecordSendTransactionParams;\n bearerToken: string;\n};\n\nexport function useRecordSendTransaction(): {\n recordSendTransaction: (input: RecordSendTransactionInput) => void;\n recordSendTransactionAsync: (\n input: RecordSendTransactionInput\n ) => Promise<Transaction>;\n data: Transaction | undefined;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n isSuccess: boolean;\n reset: () => void;\n} {\n const { chipiSDK } = useChipiContext();\n\n const mutation: UseMutationResult<\n Transaction,\n Error,\n RecordSendTransactionInput\n > = useMutation({\n mutationFn: (input: RecordSendTransactionInput) =>\n chipiSDK.recordSendTransaction({\n params: input.params,\n bearerToken: input.bearerToken,\n }),\n });\n\n return {\n recordSendTransaction: mutation.mutate,\n recordSendTransactionAsync: mutation.mutateAsync,\n data: mutation.data,\n isLoading: mutation.isPending,\n isError: mutation.isError,\n error: mutation.error,\n isSuccess: mutation.isSuccess,\n reset: mutation.reset,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chipi-stack/chipi-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "React hooks and components for Chipi SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chipi",
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@tanstack/react-query": "^5.85.0",
|
|
77
|
-
"@chipi-stack/backend": "^
|
|
78
|
-
"@chipi-stack/shared": "^
|
|
79
|
-
"@chipi-stack/types": "^
|
|
77
|
+
"@chipi-stack/backend": "^11.0.0",
|
|
78
|
+
"@chipi-stack/shared": "^11.0.0",
|
|
79
|
+
"@chipi-stack/types": "^11.0.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"react": ">=16.8.0",
|