@hfunlabs/hypurr-connect 0.1.8 → 0.1.10
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 +80 -64
- package/dist/index.d.ts +23 -15
- package/dist/index.js +361 -254
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/GrpcExchangeTransport.ts +30 -9
- package/src/HypurrConnectProvider.tsx +366 -125
- package/src/LoginModal.tsx +15 -74
- package/src/grpc.ts +2 -2
- package/src/index.ts +0 -2
- package/src/types.ts +27 -5
package/src/LoginModal.tsx
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
} from "framer-motion";
|
|
7
7
|
import {
|
|
8
8
|
useCallback,
|
|
9
|
-
useEffect,
|
|
10
9
|
useSyncExternalStore,
|
|
11
10
|
type CSSProperties,
|
|
12
11
|
type ReactNode,
|
|
@@ -14,8 +13,6 @@ import {
|
|
|
14
13
|
import { useHypurrConnectInternal } from "./HypurrConnectProvider";
|
|
15
14
|
import { MetaMaskColorIcon } from "./icons/MetaMaskColorIcon";
|
|
16
15
|
import { TelegramColorIcon } from "./icons/TelegramColorIcon";
|
|
17
|
-
import { TelegramLoginWidget } from "./TelegramLoginWidget";
|
|
18
|
-
import type { TelegramLoginData } from "./types";
|
|
19
16
|
|
|
20
17
|
export interface LoginModalProps {
|
|
21
18
|
onConnectWallet: () => void;
|
|
@@ -131,62 +128,13 @@ function HoverButton({
|
|
|
131
128
|
}
|
|
132
129
|
|
|
133
130
|
export function LoginModal({ onConnectWallet, walletIcon }: LoginModalProps) {
|
|
134
|
-
const {
|
|
135
|
-
|
|
136
|
-
loginModalOpen,
|
|
137
|
-
closeLoginModal,
|
|
138
|
-
botId,
|
|
139
|
-
botUsername,
|
|
140
|
-
useWidget,
|
|
141
|
-
} = useHypurrConnectInternal();
|
|
142
|
-
|
|
143
|
-
const handleTelegramAuth = useCallback(
|
|
144
|
-
(user: TelegramLoginData) => {
|
|
145
|
-
loginTelegram(user);
|
|
146
|
-
closeLoginModal();
|
|
147
|
-
},
|
|
148
|
-
[loginTelegram, closeLoginModal],
|
|
149
|
-
);
|
|
131
|
+
const { loginTelegram, loginModalOpen, closeLoginModal } =
|
|
132
|
+
useHypurrConnectInternal();
|
|
150
133
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
const data = typeof e.data === "string" ? JSON.parse(e.data) : e.data;
|
|
157
|
-
if (data?.event === "auth_result" && data.result) {
|
|
158
|
-
const r = data.result;
|
|
159
|
-
handleTelegramAuth({
|
|
160
|
-
id: r.id,
|
|
161
|
-
first_name: r.first_name ?? "",
|
|
162
|
-
last_name: r.last_name ?? undefined,
|
|
163
|
-
username: r.username ?? undefined,
|
|
164
|
-
photo_url: r.photo_url ?? undefined,
|
|
165
|
-
auth_date: r.auth_date,
|
|
166
|
-
hash: r.hash,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
} catch {
|
|
170
|
-
/* ignore non-JSON */
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
window.addEventListener("message", onMessage);
|
|
174
|
-
return () => window.removeEventListener("message", onMessage);
|
|
175
|
-
}, [loginModalOpen, handleTelegramAuth]);
|
|
176
|
-
|
|
177
|
-
const openTelegramOAuth = useCallback(() => {
|
|
178
|
-
const origin = encodeURIComponent(window.location.origin);
|
|
179
|
-
const url = `https://oauth.telegram.org/auth?bot_id=${botId}&origin=${origin}&request_access=write`;
|
|
180
|
-
const w = 550;
|
|
181
|
-
const h = 470;
|
|
182
|
-
const left = window.screenX + (window.outerWidth - w) / 2;
|
|
183
|
-
const top = window.screenY + (window.outerHeight - h) / 2;
|
|
184
|
-
window.open(
|
|
185
|
-
url,
|
|
186
|
-
"telegram_auth",
|
|
187
|
-
`width=${w},height=${h},left=${left},top=${top}`,
|
|
188
|
-
);
|
|
189
|
-
}, [botId]);
|
|
134
|
+
const handleTelegramAuth = useCallback(() => {
|
|
135
|
+
closeLoginModal();
|
|
136
|
+
loginTelegram();
|
|
137
|
+
}, [loginTelegram, closeLoginModal]);
|
|
190
138
|
|
|
191
139
|
const isMobile = useIsMobile();
|
|
192
140
|
|
|
@@ -202,17 +150,10 @@ export function LoginModal({ onConnectWallet, walletIcon }: LoginModalProps) {
|
|
|
202
150
|
overflow: "hidden",
|
|
203
151
|
}}
|
|
204
152
|
>
|
|
205
|
-
{
|
|
206
|
-
<
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
/>
|
|
210
|
-
) : (
|
|
211
|
-
<HoverButton onClick={openTelegramOAuth}>
|
|
212
|
-
<TelegramColorIcon style={iconSize} />
|
|
213
|
-
Telegram
|
|
214
|
-
</HoverButton>
|
|
215
|
-
)}
|
|
153
|
+
<HoverButton onClick={handleTelegramAuth}>
|
|
154
|
+
<TelegramColorIcon style={iconSize} />
|
|
155
|
+
Telegram
|
|
156
|
+
</HoverButton>
|
|
216
157
|
</div>
|
|
217
158
|
|
|
218
159
|
<div style={dividerStyle} />
|
|
@@ -258,13 +199,13 @@ export function LoginModal({ onConnectWallet, walletIcon }: LoginModalProps) {
|
|
|
258
199
|
>
|
|
259
200
|
<motion.div
|
|
260
201
|
style={modalBoxStyle}
|
|
261
|
-
initial={{
|
|
262
|
-
animate={{
|
|
263
|
-
exit={{
|
|
264
|
-
transition={{ duration: 0.
|
|
202
|
+
initial={{ scale: 0.96, opacity: 0, y: 8 }}
|
|
203
|
+
animate={{ scale: 1, opacity: 1, y: 0 }}
|
|
204
|
+
exit={{ scale: 0.96, opacity: 0, y: 8 }}
|
|
205
|
+
transition={{ duration: 0.12 }}
|
|
265
206
|
onClick={(e) => e.stopPropagation()}
|
|
266
207
|
>
|
|
267
|
-
<
|
|
208
|
+
<h2 style={headingStyle}>Connect</h2>
|
|
268
209
|
{modalContent}
|
|
269
210
|
</motion.div>
|
|
270
211
|
</motion.div>
|
package/src/grpc.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { StaticClient } from "hypurr-grpc/ts/hypurr/static/static_service.client
|
|
|
3
3
|
import { TelegramClient } from "hypurr-grpc/ts/hypurr/telegram/telegram_service.client";
|
|
4
4
|
import type { HypurrConnectConfig } from "./types";
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const DEFAULT_GRPC_URL = "https://grpc.hypurr.fun";
|
|
7
7
|
|
|
8
8
|
function createTransport(config: HypurrConnectConfig) {
|
|
9
9
|
return new GrpcWebFetchTransport({
|
|
10
|
-
baseUrl:
|
|
10
|
+
baseUrl: config.grpcUrl ?? DEFAULT_GRPC_URL,
|
|
11
11
|
timeout: config.grpcTimeout ?? 15_000,
|
|
12
12
|
});
|
|
13
13
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,8 +4,6 @@ export {
|
|
|
4
4
|
} from "./HypurrConnectProvider";
|
|
5
5
|
export { LoginModal } from "./LoginModal";
|
|
6
6
|
export type { LoginModalProps } from "./LoginModal";
|
|
7
|
-
export { TelegramLoginWidget } from "./TelegramLoginWidget";
|
|
8
|
-
export type { TelegramLoginWidgetProps } from "./TelegramLoginWidget";
|
|
9
7
|
export { GrpcExchangeTransport } from "./GrpcExchangeTransport";
|
|
10
8
|
export type { GrpcExchangeTransportConfig } from "./GrpcExchangeTransport";
|
|
11
9
|
export { createTelegramClient, createStaticClient } from "./grpc";
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExchangeClient } from "@hfunlabs/hyperliquid";
|
|
2
|
+
import type { RpcOptions } from "@protobuf-ts/runtime-rpc";
|
|
2
3
|
import type { StaticClient } from "hypurr-grpc/ts/hypurr/static/static_service.client";
|
|
3
4
|
import type {
|
|
4
5
|
HyperliquidScaleCreateRequest,
|
|
@@ -16,19 +17,31 @@ import type { HyperliquidWallet } from "hypurr-grpc/ts/hypurr/wallet";
|
|
|
16
17
|
// ─── Config ──────────────────────────────────────────────────────
|
|
17
18
|
|
|
18
19
|
export interface HypurrConnectConfig {
|
|
20
|
+
/** gRPC-web base URL. Defaults to https://grpc.hypurr.fun. */
|
|
21
|
+
grpcUrl?: string;
|
|
19
22
|
grpcTimeout?: number;
|
|
20
23
|
isTestnet?: boolean;
|
|
21
24
|
/** Polling interval in ms for TWAP/Scale session updates. Default 5000. Set 0 to disable. */
|
|
22
25
|
sessionPollInterval?: number;
|
|
23
26
|
telegram: {
|
|
24
|
-
|
|
27
|
+
/** Deprecated for the hub flow; retained for older consumers. */
|
|
28
|
+
botUsername?: string;
|
|
29
|
+
/** Deprecated for the hub flow; retained for older consumers. */
|
|
25
30
|
botId?: string;
|
|
26
|
-
|
|
31
|
+
/** Deprecated: Telegram login is now handled by the auth hub. */
|
|
32
|
+
useWidget?: boolean;
|
|
33
|
+
/** Auth hub login URL. Defaults to https://auth.hypurr.fun/login. */
|
|
34
|
+
authHubUrl?: string;
|
|
35
|
+
/** Optional callback URL. Defaults to the current page without auth query params. */
|
|
36
|
+
returnTo?: string | (() => string);
|
|
37
|
+
/** Requested hub scopes. Defaults to the scopes required by this SDK. */
|
|
38
|
+
scope?: string | string[];
|
|
27
39
|
};
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
// ─── Telegram login ──────────────────────────────────────────────
|
|
31
43
|
|
|
44
|
+
/** @deprecated Telegram login is handled by the auth hub; raw Telegram data is no longer used by the provider. */
|
|
32
45
|
export interface TelegramLoginData {
|
|
33
46
|
id: number;
|
|
34
47
|
first_name: string;
|
|
@@ -180,12 +193,18 @@ export interface HypurrConnectState {
|
|
|
180
193
|
}) => Promise<void>;
|
|
181
194
|
|
|
182
195
|
// TWAP sessions (Telegram only)
|
|
183
|
-
createTwap: (
|
|
184
|
-
|
|
196
|
+
createTwap: (
|
|
197
|
+
params: TwapCreateParams,
|
|
198
|
+
) => Promise<HyperliquidWalletTwapSession>;
|
|
199
|
+
modifyTwap: (
|
|
200
|
+
params: TwapModifyParams,
|
|
201
|
+
) => Promise<HyperliquidWalletTwapSession>;
|
|
185
202
|
cancelTwap: (sessionId: number) => Promise<void>;
|
|
186
203
|
|
|
187
204
|
// Scale sessions (Telegram only)
|
|
188
|
-
createScale: (
|
|
205
|
+
createScale: (
|
|
206
|
+
params: ScaleCreateParams,
|
|
207
|
+
) => Promise<HyperliquidWalletScaleSession>;
|
|
189
208
|
cancelScale: (sessionId: number) => Promise<void>;
|
|
190
209
|
|
|
191
210
|
// Login modal
|
|
@@ -210,7 +229,10 @@ export interface HypurrConnectState {
|
|
|
210
229
|
botId: string;
|
|
211
230
|
|
|
212
231
|
// Low-level access
|
|
232
|
+
/** Deprecated: JWT auth leaves authData empty; use `telegramRpcOptions` for low-level calls. */
|
|
213
233
|
authDataMap: Record<string, string>;
|
|
234
|
+
authToken: string | null;
|
|
235
|
+
telegramRpcOptions?: RpcOptions;
|
|
214
236
|
telegramClient: TelegramClient;
|
|
215
237
|
staticClient: StaticClient;
|
|
216
238
|
}
|