@pear-protocol/hyperliquid-sdk 0.0.60-beta.3 → 0.0.60-beta.5
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/hooks/useAuth.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -13
- package/dist/provider.d.ts +0 -2
- package/package.json +1 -1
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -9,4 +9,6 @@ export declare function useAuth(): {
|
|
|
9
9
|
readonly loginWithPrivyToken: (address: string, appId: string, privyAccessToken: string) => Promise<void>;
|
|
10
10
|
readonly refreshTokens: () => Promise<import("../types").RefreshTokenResponse>;
|
|
11
11
|
readonly logout: () => Promise<void>;
|
|
12
|
+
readonly setAddress: (address: string | null) => void;
|
|
13
|
+
readonly address: string | null;
|
|
12
14
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -9,8 +9,6 @@ interface PearHyperliquidContextType {
|
|
|
9
9
|
lastError: string | null;
|
|
10
10
|
nativeIsConnected: boolean;
|
|
11
11
|
nativeLastError: string | null;
|
|
12
|
-
setAddress: (address: string) => void;
|
|
13
|
-
address: string | null;
|
|
14
12
|
}
|
|
15
13
|
interface PearHyperliquidProviderProps {
|
|
16
14
|
children: ReactNode;
|
|
@@ -1128,6 +1126,8 @@ declare function useAuth(): {
|
|
|
1128
1126
|
readonly loginWithPrivyToken: (address: string, appId: string, privyAccessToken: string) => Promise<void>;
|
|
1129
1127
|
readonly refreshTokens: () => Promise<RefreshTokenResponse>;
|
|
1130
1128
|
readonly logout: () => Promise<void>;
|
|
1129
|
+
readonly setAddress: (address: string | null) => void;
|
|
1130
|
+
readonly address: string | null;
|
|
1131
1131
|
};
|
|
1132
1132
|
|
|
1133
1133
|
interface UseHyperliquidWebSocketProps {
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ const useUserData = create((set) => ({
|
|
|
66
66
|
setAccessToken: (token) => set({ accessToken: token }),
|
|
67
67
|
setRefreshToken: (token) => set({ refreshToken: token }),
|
|
68
68
|
setIsAuthenticated: (value) => set({ isAuthenticated: value }),
|
|
69
|
-
setAddress: (address) =>
|
|
69
|
+
setAddress: (address) => {
|
|
70
70
|
if (typeof window !== "undefined") {
|
|
71
71
|
if (address) {
|
|
72
72
|
window.localStorage.setItem("address", address);
|
|
@@ -75,8 +75,8 @@ const useUserData = create((set) => ({
|
|
|
75
75
|
window.localStorage.removeItem("address");
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
}
|
|
78
|
+
set({ address });
|
|
79
|
+
},
|
|
80
80
|
setTradeHistories: (value) => set({ tradeHistories: value }),
|
|
81
81
|
setRawOpenPositions: (value) => set({ rawOpenPositions: value }),
|
|
82
82
|
setOpenOrders: (value) => set({ openOrders: value }),
|
|
@@ -7029,7 +7029,7 @@ async function logout(baseUrl, refreshTokenVal) {
|
|
|
7029
7029
|
function useAuth() {
|
|
7030
7030
|
const context = useContext(PearHyperliquidContext);
|
|
7031
7031
|
if (!context) {
|
|
7032
|
-
throw new Error("
|
|
7032
|
+
throw new Error("useAuth must be used within a PearHyperliquidProvider");
|
|
7033
7033
|
}
|
|
7034
7034
|
const { apiBaseUrl, clientId } = context;
|
|
7035
7035
|
const [isReady, setIsReady] = useState(false);
|
|
@@ -7047,34 +7047,29 @@ function useAuth() {
|
|
|
7047
7047
|
}
|
|
7048
7048
|
// Get the current address from state if it exists
|
|
7049
7049
|
const currentAddress = address;
|
|
7050
|
+
console.log({ currentAddress });
|
|
7050
7051
|
if (currentAddress) {
|
|
7051
7052
|
// If we already have an address in state, use it to load the session
|
|
7052
7053
|
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7053
7054
|
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7054
7055
|
const storedAccessToken = localStorage.getItem(accessTokenKey);
|
|
7055
7056
|
const storedRefreshToken = localStorage.getItem(refreshTokenKey);
|
|
7057
|
+
console.log({ storedAccessToken, storedRefreshToken });
|
|
7056
7058
|
if (storedAccessToken && storedRefreshToken) {
|
|
7057
7059
|
setAccessToken(storedAccessToken);
|
|
7058
7060
|
setRefreshToken(storedRefreshToken);
|
|
7059
7061
|
setIsAuthenticated(true);
|
|
7060
|
-
return;
|
|
7061
7062
|
}
|
|
7062
7063
|
setIsReady(true);
|
|
7063
7064
|
}
|
|
7064
|
-
}, [
|
|
7065
|
-
setAccessToken,
|
|
7066
|
-
setRefreshToken,
|
|
7067
|
-
setIsAuthenticated,
|
|
7068
|
-
setAddress,
|
|
7069
|
-
address,
|
|
7070
|
-
]);
|
|
7065
|
+
}, [address]);
|
|
7071
7066
|
useEffect(() => {
|
|
7072
7067
|
const cleanup = addAuthInterceptors({
|
|
7073
7068
|
apiBaseUrl,
|
|
7074
7069
|
getAccessToken: () => {
|
|
7075
7070
|
if (typeof window === "undefined")
|
|
7076
7071
|
return null;
|
|
7077
|
-
const currentAddress =
|
|
7072
|
+
const currentAddress = address;
|
|
7078
7073
|
if (!currentAddress)
|
|
7079
7074
|
return null;
|
|
7080
7075
|
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
@@ -7186,6 +7181,8 @@ function useAuth() {
|
|
|
7186
7181
|
loginWithPrivyToken,
|
|
7187
7182
|
refreshTokens,
|
|
7188
7183
|
logout: logout$1,
|
|
7184
|
+
setAddress,
|
|
7185
|
+
address,
|
|
7189
7186
|
};
|
|
7190
7187
|
}
|
|
7191
7188
|
|
package/dist/provider.d.ts
CHANGED
|
@@ -7,8 +7,6 @@ export interface PearHyperliquidContextType {
|
|
|
7
7
|
lastError: string | null;
|
|
8
8
|
nativeIsConnected: boolean;
|
|
9
9
|
nativeLastError: string | null;
|
|
10
|
-
setAddress: (address: string) => void;
|
|
11
|
-
address: string | null;
|
|
12
10
|
}
|
|
13
11
|
export declare const PearHyperliquidContext: React.Context<PearHyperliquidContextType | undefined>;
|
|
14
12
|
interface PearHyperliquidProviderProps {
|