@0xmonaco/react 1.0.83 → 1.0.85

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.
@@ -28,6 +28,8 @@ export declare const COVERED: {
28
28
  close_position: string;
29
29
  batch_close_all_positions: string;
30
30
  create_challenge: string;
31
+ request_invite_codes: string;
32
+ list_invite_codes: string;
31
33
  create_order: string;
32
34
  get_candles: string;
33
35
  get_funding_state: string;
package/dist/coverage.js CHANGED
@@ -28,6 +28,8 @@ export const COVERED = {
28
28
  close_position: "usePositions",
29
29
  batch_close_all_positions: "usePositions",
30
30
  create_challenge: "useAuth",
31
+ request_invite_codes: "useAuth.requestInviteCodes",
32
+ list_invite_codes: "useAuth.listInviteCodes",
31
33
  create_order: "useTrade",
32
34
  get_candles: "useMarket",
33
35
  get_funding_state: "useMarket",
@@ -1,4 +1,4 @@
1
- import type { AuthState, ChallengeResponse, SessionRefreshResponse } from "@0xmonaco/types";
1
+ import type { AuthState, ChallengeResponse, InviteCodeList, InviteCodeRequestSummary, SessionRefreshResponse } from "@0xmonaco/types";
2
2
  import type { AuthenticationStatus } from "../../provider";
3
3
  export interface UseAuthState {
4
4
  /** Current authentication status */
@@ -13,7 +13,12 @@ export interface UseAuthReturn extends UseAuthState {
13
13
  */
14
14
  login: (options?: {
15
15
  connectWebSocket?: boolean;
16
+ inviteCode?: string;
16
17
  }) => Promise<AuthState>;
18
+ /** Mint one available Mainnet invite code immediately; each call consumes a slot. */
19
+ requestInviteCodes: () => Promise<InviteCodeRequestSummary>;
20
+ /** Read the invite allowance and minted codes without consuming a slot. */
21
+ listInviteCodes: () => Promise<InviteCodeList>;
17
22
  /** Logout user and clear state. Revokes the session on the server. */
18
23
  logout: () => Promise<void>;
19
24
  /** Refresh the current session, extending its expiry. */
@@ -4,14 +4,14 @@ import { useMonacoSDK } from "../useMonaco";
4
4
  export const useAuth = () => {
5
5
  const { sdk, clientId } = useMonacoSDK();
6
6
  const { authenticationStatus, setAuthenticationStatus, tokenLifecycle, isWalletConnected } = useMonacoContext();
7
- const login = useCallback(async () => {
7
+ const login = useCallback(async (options) => {
8
8
  if (!sdk)
9
9
  throw new Error("SDK not available");
10
10
  if (!isWalletConnected)
11
11
  throw new Error("Wallet not connected");
12
12
  setAuthenticationStatus(AuthenticationStatus.AUTHENTICATING);
13
13
  try {
14
- const authState = await sdk.login(clientId);
14
+ const authState = await sdk.login(clientId, options);
15
15
  // Initialize token lifecycle management (caching + auto-refresh)
16
16
  tokenLifecycle.initializeTokens(authState);
17
17
  const authenticated = sdk.isAuthenticated();
@@ -23,6 +23,16 @@ export const useAuth = () => {
23
23
  throw error;
24
24
  }
25
25
  }, [sdk, isWalletConnected, clientId, setAuthenticationStatus, tokenLifecycle]);
26
+ const requestInviteCodes = useCallback(async () => {
27
+ if (!sdk)
28
+ throw new Error("SDK not available");
29
+ return await sdk.auth.requestInviteCodes();
30
+ }, [sdk]);
31
+ const listInviteCodes = useCallback(async () => {
32
+ if (!sdk)
33
+ throw new Error("SDK not available");
34
+ return await sdk.auth.listInviteCodes();
35
+ }, [sdk]);
26
36
  const logout = useCallback(async () => {
27
37
  if (!sdk)
28
38
  throw new Error("SDK not available");
@@ -127,6 +137,8 @@ export const useAuth = () => {
127
137
  authenticationStatus,
128
138
  // Primary auth actions
129
139
  login,
140
+ requestInviteCodes,
141
+ listInviteCodes,
130
142
  logout,
131
143
  // Session management
132
144
  refreshAuth,
@@ -598,6 +598,9 @@ export function orderFromSnapshotItem(item) {
598
598
  leverage: item.leverage ?? undefined,
599
599
  reduceOnly: item.reduceOnly,
600
600
  ...(item.clientOrderId === undefined ? {} : { clientOrderId: item.clientOrderId }),
601
+ // What placed the order, as REST reports it. Absent stays absent, so a
602
+ // snapshot that does not report one leaves the label the row already had.
603
+ ...(item.origin === undefined ? {} : { origin: item.origin }),
601
604
  // Carried, not dropped: it is what the merge ranks this row by, and a row
602
605
  // whose state came from the snapshot while its version stayed at the held
603
606
  // value would be internally inconsistent — reporting a step it does not
@@ -678,8 +681,13 @@ export function applyOrderSnapshot(current, items, limit) {
678
681
  // Unranked means neither side carries a version, which is the pre-0XM-2440
679
682
  // world: the snapshot is still the authority on resting state there, so it
680
683
  // keeps its original precedence.
681
- if (ranked === false)
682
- return [];
684
+ if (ranked === false) {
685
+ // What placed the order never changes, so it is merged outside the
686
+ // ranking, as `mergeOrders` does: the stored row's value stands, and a
687
+ // held row that has none gains it from a snapshot that lost on version.
688
+ const origin = row.origin ?? existing.origin;
689
+ return origin === existing.origin ? [] : [{ ...existing, origin }];
690
+ }
683
691
  return [{ ...existing, ...row }];
684
692
  });
685
693
  // Core validates the frame and every order id before delivery. A row this
@@ -810,10 +818,10 @@ export function mergeOrders(current, fetched, limit) {
810
818
  return incoming;
811
819
  const winner = reconcile(incoming, live);
812
820
  // What placed an order never changes, so it is not ranked: whichever row
813
- // knows it supplies it. A snapshot row carries none and learns it from
814
- // REST; a row that learned it from its acknowledgement keeps it against a
815
- // response from a server predating the field. If both report one and they
816
- // differ, the REST row is the stored order and stands.
821
+ // knows it supplies it. A row held without one (from a server predating
822
+ // the field) learns it from REST; a row that learned it from the socket
823
+ // keeps it against a REST response that does not report one. If both
824
+ // report one and they differ, the REST row is the stored order and stands.
817
825
  const origin = incoming.origin ?? live.origin ?? undefined;
818
826
  return origin === winner.origin ? winner : { ...winner, origin };
819
827
  });
@@ -989,7 +997,13 @@ export function updateOrderFromEvent(order, event) {
989
997
  // above is what keeps that value when this event carries none.
990
998
  ...(typeof data.version === "number" ? { version: data.version } : {}),
991
999
  };
992
- return liveEventSupersedes(order, updated, typeof data.version === "number" ? data.version : undefined) ? updated : order;
1000
+ const winner = liveEventSupersedes(order, updated, typeof data.version === "number" ? data.version : undefined) ? updated : order;
1001
+ // What placed the order never changes, so it is merged outside the ranking,
1002
+ // as `mergeOrders` and `applyOrderSnapshot` do: every order frame reports
1003
+ // it, and one labels a row held without it even when the frame loses on
1004
+ // version, but never replaces a value already held (which may be the stored
1005
+ // REST one).
1006
+ return order.origin === undefined && typeof data.origin === "string" ? { ...winner, origin: data.origin } : winner;
993
1007
  }
994
1008
  /**
995
1009
  * Whether a live event can advance the row currently held.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/react",
3
- "version": "1.0.83",
3
+ "version": "1.0.85",
4
4
  "type": "module",
5
5
  "homepage": "https://docs.0xmonaco.com/sdk/typescript",
6
6
  "main": "./dist/index.js",
@@ -16,8 +16,8 @@
16
16
  "lint": "biome lint ."
17
17
  },
18
18
  "dependencies": {
19
- "@0xmonaco/core": "1.0.83",
20
- "@0xmonaco/types": "1.0.83"
19
+ "@0xmonaco/core": "1.0.85",
20
+ "@0xmonaco/types": "1.0.85"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "^19.2.18",