@permi/react 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -4,7 +4,8 @@ import { Address, Hex } from 'viem';
4
4
  import * as _tanstack_react_query from '@tanstack/react-query';
5
5
  import { QueryClient } from '@tanstack/react-query';
6
6
  import * as _permi_core from '@permi/core';
7
- import { balanceOptions, addressOptions } from '@permi/core/hooks';
7
+ import { Options, SignMessageData, SignTypedDataData, SignTransactionData } from '@permi/core';
8
+ import { balanceOptions, addressOptions, signMessageMutation, signTypedDataMutation, signTransactionMutation } from '@permi/core/hooks';
8
9
  import React from 'react';
9
10
  import * as react_oidc_context from 'react-oidc-context';
10
11
 
@@ -21,6 +22,81 @@ declare const useAuth: () => {
21
22
  */
22
23
  declare const useBalance: (queryOptions?: ReturnType<typeof balanceOptions>) => _tanstack_react_query.UseQueryResult<number, _permi_core.BalanceError>;
23
24
  declare const useAddress: (queryOptions?: ReturnType<typeof addressOptions>) => _tanstack_react_query.UseQueryResult<string, _permi_core.AddressError>;
25
+ declare const useSignMessage: (mutationOptions?: ReturnType<typeof signMessageMutation>) => _tanstack_react_query.UseMutationResult<string, {
26
+ message: string;
27
+ code: string;
28
+ issues?: Array<{
29
+ message: string;
30
+ }>;
31
+ } | {
32
+ message: string;
33
+ code: string;
34
+ issues?: Array<{
35
+ message: string;
36
+ }>;
37
+ } | {
38
+ message: string;
39
+ code: string;
40
+ issues?: Array<{
41
+ message: string;
42
+ }>;
43
+ } | {
44
+ message: string;
45
+ code: string;
46
+ issues?: Array<{
47
+ message: string;
48
+ }>;
49
+ }, Options<SignMessageData>, unknown>;
50
+ declare const useSignTypedData: (mutationOptions?: ReturnType<typeof signTypedDataMutation>) => _tanstack_react_query.UseMutationResult<string, {
51
+ message: string;
52
+ code: string;
53
+ issues?: Array<{
54
+ message: string;
55
+ }>;
56
+ } | {
57
+ message: string;
58
+ code: string;
59
+ issues?: Array<{
60
+ message: string;
61
+ }>;
62
+ } | {
63
+ message: string;
64
+ code: string;
65
+ issues?: Array<{
66
+ message: string;
67
+ }>;
68
+ } | {
69
+ message: string;
70
+ code: string;
71
+ issues?: Array<{
72
+ message: string;
73
+ }>;
74
+ }, Options<SignTypedDataData>, unknown>;
75
+ declare const useSignTransaction: (mutationOptions?: ReturnType<typeof signTransactionMutation>) => _tanstack_react_query.UseMutationResult<string, {
76
+ message: string;
77
+ code: string;
78
+ issues?: Array<{
79
+ message: string;
80
+ }>;
81
+ } | {
82
+ message: string;
83
+ code: string;
84
+ issues?: Array<{
85
+ message: string;
86
+ }>;
87
+ } | {
88
+ message: string;
89
+ code: string;
90
+ issues?: Array<{
91
+ message: string;
92
+ }>;
93
+ } | {
94
+ message: string;
95
+ code: string;
96
+ issues?: Array<{
97
+ message: string;
98
+ }>;
99
+ }, Options<SignTransactionData>, unknown>;
24
100
  declare const useAccount: () => {
25
101
  data: {
26
102
  address: Address;
@@ -60,4 +136,4 @@ interface PermiContextValue {
60
136
  declare const usePermiContext: () => PermiContextValue;
61
137
  declare const PermiProvider: React.FC<Props>;
62
138
 
63
- export { PermiProvider, useAccount, useAddress, useAuth, useBalance, usePermiContext };
139
+ export { PermiProvider, useAccount, useAddress, useAuth, useBalance, usePermiContext, useSignMessage, useSignTransaction, useSignTypedData };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,8 @@ import { Address, Hex } from 'viem';
4
4
  import * as _tanstack_react_query from '@tanstack/react-query';
5
5
  import { QueryClient } from '@tanstack/react-query';
6
6
  import * as _permi_core from '@permi/core';
7
- import { balanceOptions, addressOptions } from '@permi/core/hooks';
7
+ import { Options, SignMessageData, SignTypedDataData, SignTransactionData } from '@permi/core';
8
+ import { balanceOptions, addressOptions, signMessageMutation, signTypedDataMutation, signTransactionMutation } from '@permi/core/hooks';
8
9
  import React from 'react';
9
10
  import * as react_oidc_context from 'react-oidc-context';
10
11
 
@@ -21,6 +22,81 @@ declare const useAuth: () => {
21
22
  */
22
23
  declare const useBalance: (queryOptions?: ReturnType<typeof balanceOptions>) => _tanstack_react_query.UseQueryResult<number, _permi_core.BalanceError>;
23
24
  declare const useAddress: (queryOptions?: ReturnType<typeof addressOptions>) => _tanstack_react_query.UseQueryResult<string, _permi_core.AddressError>;
25
+ declare const useSignMessage: (mutationOptions?: ReturnType<typeof signMessageMutation>) => _tanstack_react_query.UseMutationResult<string, {
26
+ message: string;
27
+ code: string;
28
+ issues?: Array<{
29
+ message: string;
30
+ }>;
31
+ } | {
32
+ message: string;
33
+ code: string;
34
+ issues?: Array<{
35
+ message: string;
36
+ }>;
37
+ } | {
38
+ message: string;
39
+ code: string;
40
+ issues?: Array<{
41
+ message: string;
42
+ }>;
43
+ } | {
44
+ message: string;
45
+ code: string;
46
+ issues?: Array<{
47
+ message: string;
48
+ }>;
49
+ }, Options<SignMessageData>, unknown>;
50
+ declare const useSignTypedData: (mutationOptions?: ReturnType<typeof signTypedDataMutation>) => _tanstack_react_query.UseMutationResult<string, {
51
+ message: string;
52
+ code: string;
53
+ issues?: Array<{
54
+ message: string;
55
+ }>;
56
+ } | {
57
+ message: string;
58
+ code: string;
59
+ issues?: Array<{
60
+ message: string;
61
+ }>;
62
+ } | {
63
+ message: string;
64
+ code: string;
65
+ issues?: Array<{
66
+ message: string;
67
+ }>;
68
+ } | {
69
+ message: string;
70
+ code: string;
71
+ issues?: Array<{
72
+ message: string;
73
+ }>;
74
+ }, Options<SignTypedDataData>, unknown>;
75
+ declare const useSignTransaction: (mutationOptions?: ReturnType<typeof signTransactionMutation>) => _tanstack_react_query.UseMutationResult<string, {
76
+ message: string;
77
+ code: string;
78
+ issues?: Array<{
79
+ message: string;
80
+ }>;
81
+ } | {
82
+ message: string;
83
+ code: string;
84
+ issues?: Array<{
85
+ message: string;
86
+ }>;
87
+ } | {
88
+ message: string;
89
+ code: string;
90
+ issues?: Array<{
91
+ message: string;
92
+ }>;
93
+ } | {
94
+ message: string;
95
+ code: string;
96
+ issues?: Array<{
97
+ message: string;
98
+ }>;
99
+ }, Options<SignTransactionData>, unknown>;
24
100
  declare const useAccount: () => {
25
101
  data: {
26
102
  address: Address;
@@ -60,4 +136,4 @@ interface PermiContextValue {
60
136
  declare const usePermiContext: () => PermiContextValue;
61
137
  declare const PermiProvider: React.FC<Props>;
62
138
 
63
- export { PermiProvider, useAccount, useAddress, useAuth, useBalance, usePermiContext };
139
+ export { PermiProvider, useAccount, useAddress, useAuth, useBalance, usePermiContext, useSignMessage, useSignTransaction, useSignTypedData };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/hooks/index.ts
2
2
  import { useMemo as useMemo3 } from "react";
3
- import { useQuery } from "@tanstack/react-query";
3
+ import { useMutation, useQuery } from "@tanstack/react-query";
4
4
  import { toAccount } from "viem/accounts";
5
5
 
6
6
  // ../core/src/@tanstack/react-query.gen.ts
@@ -830,7 +830,7 @@ var createClient = (config = {}) => {
830
830
  };
831
831
 
832
832
  // ../core/src/client.gen.ts
833
- var client = createClient(createConfig({ baseUrl: "https://permi.xyz/api/v1" }));
833
+ var client = createClient(createConfig({ baseUrl: "https://www.permi.xyz/api/v1" }));
834
834
 
835
835
  // ../core/src/sdk.gen.ts
836
836
  var address = (options) => (options?.client ?? client).get({
@@ -920,6 +920,45 @@ var balanceOptions = (options) => queryOptions({
920
920
  },
921
921
  queryKey: balanceQueryKey(options)
922
922
  });
923
+ var signMessageMutation = (options) => {
924
+ const mutationOptions = {
925
+ mutationFn: async (fnOptions) => {
926
+ const { data } = await signMessage({
927
+ ...options,
928
+ ...fnOptions,
929
+ throwOnError: true
930
+ });
931
+ return data;
932
+ }
933
+ };
934
+ return mutationOptions;
935
+ };
936
+ var signTypedDataMutation = (options) => {
937
+ const mutationOptions = {
938
+ mutationFn: async (fnOptions) => {
939
+ const { data } = await signTypedData({
940
+ ...options,
941
+ ...fnOptions,
942
+ throwOnError: true
943
+ });
944
+ return data;
945
+ }
946
+ };
947
+ return mutationOptions;
948
+ };
949
+ var signTransactionMutation = (options) => {
950
+ const mutationOptions = {
951
+ mutationFn: async (fnOptions) => {
952
+ const { data } = await signTransaction({
953
+ ...options,
954
+ ...fnOptions,
955
+ throwOnError: true
956
+ });
957
+ return data;
958
+ }
959
+ };
960
+ return mutationOptions;
961
+ };
923
962
 
924
963
  // src/providers/index.tsx
925
964
  import { useMemo as useMemo2, createContext, useContext } from "react";
@@ -1036,61 +1075,59 @@ var useAuth2 = () => {
1036
1075
  };
1037
1076
 
1038
1077
  // src/hooks/index.ts
1039
- var getOptions = (options, getAccessToken) => {
1040
- return {
1041
- ...options,
1042
- throwOnError: true,
1043
- headers: {
1044
- ...options.headers,
1045
- Authorization: `Bearer ${getAccessToken()}`
1046
- }
1047
- };
1048
- };
1049
1078
  var useOptions = (options) => {
1050
1079
  const { baseUrl, getAccessToken } = usePermiContext();
1051
1080
  return useMemo3(
1052
- () => getOptions(
1053
- {
1054
- baseUrl,
1055
- ...options ?? {}
1056
- },
1057
- getAccessToken
1058
- ),
1081
+ () => ({
1082
+ ...options,
1083
+ ...baseUrl ? { baseUrl } : {},
1084
+ throwOnError: true,
1085
+ headers: {
1086
+ ...options?.headers ?? {},
1087
+ Authorization: `Bearer ${getAccessToken()}`
1088
+ }
1089
+ }),
1059
1090
  [options, baseUrl, getAccessToken]
1060
1091
  );
1061
1092
  };
1062
1093
  var useBalance = (queryOptions2) => useQuery({ ...balanceOptions(useOptions()), ...queryOptions2 });
1063
1094
  var useAddress = (queryOptions2) => useQuery({ ...addressOptions(useOptions()), ...queryOptions2 });
1095
+ var useSignMessage = (mutationOptions) => useMutation({
1096
+ ...signMessageMutation(useOptions()),
1097
+ ...mutationOptions
1098
+ });
1099
+ var useSignTypedData = (mutationOptions) => useMutation({
1100
+ ...signTypedDataMutation(useOptions()),
1101
+ ...mutationOptions
1102
+ });
1103
+ var useSignTransaction = (mutationOptions) => useMutation({
1104
+ ...signTransactionMutation(useOptions()),
1105
+ ...mutationOptions
1106
+ });
1064
1107
  var useAccount = () => {
1065
1108
  const { data: address2, isLoading: isAddressLoading } = useAddress();
1066
- const { baseUrl, getAccessToken } = usePermiContext();
1067
- const getAuthOptions = (options) => {
1068
- return getOptions(
1069
- {
1070
- baseUrl,
1071
- ...options
1072
- },
1073
- getAccessToken
1074
- );
1075
- };
1109
+ const { mutateAsync: signMessage2 } = useSignMessage();
1110
+ const { mutateAsync: signTypedData2 } = useSignTypedData();
1111
+ const { mutateAsync: signTransaction2 } = useSignTransaction();
1076
1112
  const account = !address2 ? void 0 : toAccount({
1077
1113
  address: address2,
1078
1114
  signMessage: async (params) => {
1079
- return await signMessage(
1080
- getAuthOptions({
1081
- body: params
1082
- })
1083
- ).then((res) => res.data);
1115
+ const signature = await signMessage2({
1116
+ body: params
1117
+ });
1118
+ return signature;
1084
1119
  },
1085
1120
  signTransaction: async (params) => {
1086
- return await signTransaction(
1087
- getAuthOptions({ body: params })
1088
- ).then((res) => res.data);
1121
+ const signature = await signTransaction2({
1122
+ body: params
1123
+ });
1124
+ return signature;
1089
1125
  },
1090
1126
  signTypedData: async (params) => {
1091
- return await signTypedData(getAuthOptions({ body: params })).then(
1092
- (res) => res.data
1093
- );
1127
+ const signature = await signTypedData2({
1128
+ body: params
1129
+ });
1130
+ return signature;
1094
1131
  }
1095
1132
  });
1096
1133
  return {
@@ -1104,6 +1141,9 @@ export {
1104
1141
  useAddress,
1105
1142
  useAuth2 as useAuth,
1106
1143
  useBalance,
1107
- usePermiContext
1144
+ usePermiContext,
1145
+ useSignMessage,
1146
+ useSignTransaction,
1147
+ useSignTypedData
1108
1148
  };
1109
1149
  //# sourceMappingURL=index.js.map