@provable-games/budokan-sdk 0.1.19 → 0.1.21

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/react.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  var react = require('react');
4
4
  var starknet = require('starknet');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
+ var react$1 = require('@provable-games/denshokan-sdk/react');
6
7
 
7
8
  // src/react/context.tsx
8
9
 
@@ -243,7 +244,6 @@ async function getTournament(baseUrl, tournamentId, ctx) {
243
244
  }
244
245
  async function getTournamentRegistrations(baseUrl, tournamentId, params, ctx) {
245
246
  const qs = buildQueryString({
246
- player_address: params?.playerAddress,
247
247
  game_token_ids: params?.gameTokenIds?.length ? params.gameTokenIds.join(",") : void 0,
248
248
  has_submitted: params?.hasSubmitted,
249
249
  is_banned: params?.isBanned,
@@ -316,42 +316,8 @@ function normalizeAddress(address) {
316
316
  return ("0x" + stripped.padStart(64, "0")).toLowerCase();
317
317
  }
318
318
 
319
- // src/api/players.ts
320
- function fetchOpts2(ctx) {
321
- return {
322
- retryAttempts: ctx?.retryAttempts,
323
- retryDelay: ctx?.retryDelay,
324
- timeout: ctx?.timeout
325
- };
326
- }
327
- async function getPlayerTournaments(baseUrl, address, params, ctx) {
328
- const normalized = normalizeAddress(address);
329
- const qs = buildQueryString({
330
- limit: params?.limit,
331
- offset: params?.offset,
332
- phase: params?.phase,
333
- game_token_ids: params?.gameTokenIds?.join(",")
334
- });
335
- const result = await apiFetch(`${baseUrl}/players/${normalized}/tournaments${qs}`, fetchOpts2(ctx));
336
- const { total, limit: resLimit, offset: resOffset } = extractPagination(result, { limit: params?.limit, offset: params?.offset });
337
- return {
338
- data: result.data.map((item) => snakeToCamel(item)),
339
- total,
340
- limit: resLimit,
341
- offset: resOffset
342
- };
343
- }
344
- async function getPlayerStats(baseUrl, address, ctx) {
345
- const normalized = normalizeAddress(address);
346
- const result = await apiFetch(
347
- `${baseUrl}/players/${normalized}/stats`,
348
- fetchOpts2(ctx)
349
- );
350
- return snakeToCamel(result.data);
351
- }
352
-
353
319
  // src/api/games.ts
354
- function fetchOpts3(ctx) {
320
+ function fetchOpts2(ctx) {
355
321
  return {
356
322
  retryAttempts: ctx?.retryAttempts,
357
323
  retryDelay: ctx?.retryDelay,
@@ -366,7 +332,7 @@ async function getGameTournaments(baseUrl, gameAddress, params, ctx) {
366
332
  limit: params?.limit,
367
333
  offset: params?.offset
368
334
  });
369
- const result = await apiFetch(`${baseUrl}/games/${normalized}/tournaments${qs}`, fetchOpts3(ctx));
335
+ const result = await apiFetch(`${baseUrl}/games/${normalized}/tournaments${qs}`, fetchOpts2(ctx));
370
336
  const { total, limit: resLimit, offset: resOffset } = extractPagination(result, { limit: params?.limit, offset: params?.offset });
371
337
  return {
372
338
  data: result.data.map((item) => snakeToCamel(item)),
@@ -379,47 +345,30 @@ async function getGameStats(baseUrl, gameAddress, ctx) {
379
345
  const normalized = normalizeAddress(gameAddress);
380
346
  const result = await apiFetch(
381
347
  `${baseUrl}/games/${normalized}/stats`,
382
- fetchOpts3(ctx)
348
+ fetchOpts2(ctx)
383
349
  );
384
350
  return snakeToCamel(result.data);
385
351
  }
386
352
 
387
353
  // src/api/activity.ts
388
- function fetchOpts4(ctx) {
354
+ function fetchOpts3(ctx) {
389
355
  return {
390
356
  retryAttempts: ctx?.retryAttempts,
391
357
  retryDelay: ctx?.retryDelay,
392
358
  timeout: ctx?.timeout
393
359
  };
394
360
  }
395
- async function getActivity(baseUrl, params, ctx) {
396
- const qs = buildQueryString({
397
- event_type: params?.eventType,
398
- tournament_id: params?.tournamentId,
399
- player_address: params?.playerAddress,
400
- limit: params?.limit,
401
- offset: params?.offset
402
- });
403
- const result = await apiFetch(`${baseUrl}/activity${qs}`, fetchOpts4(ctx));
404
- const { total, limit: resLimit, offset: resOffset } = extractPagination(result, { limit: params?.limit, offset: params?.offset });
405
- return {
406
- data: result.data.map((item) => snakeToCamel(item)),
407
- total,
408
- limit: resLimit,
409
- offset: resOffset
410
- };
411
- }
412
361
  async function getActivityStats(baseUrl, ctx) {
413
362
  const result = await apiFetch(
414
363
  `${baseUrl}/activity/stats`,
415
- fetchOpts4(ctx)
364
+ fetchOpts3(ctx)
416
365
  );
417
366
  return snakeToCamel(result.data);
418
367
  }
419
368
  async function getPrizeStats(baseUrl, ctx) {
420
369
  const result = await apiFetch(
421
370
  `${baseUrl}/activity/prize-stats`,
422
- fetchOpts4(ctx)
371
+ fetchOpts3(ctx)
423
372
  );
424
373
  return snakeToCamel(result.data);
425
374
  }
@@ -981,8 +930,6 @@ function parseRegistration(raw, tournamentId) {
981
930
  gameTokenId: starknet.num.toHex(obj.game_token_id),
982
931
  gameAddress: "",
983
932
  // Not in on-chain struct
984
- playerAddress: "",
985
- // Not in on-chain struct
986
933
  entryNumber: Number(obj.entry_id ?? 0),
987
934
  hasSubmitted: Boolean(obj.has_submitted),
988
935
  isBanned: Boolean(obj.is_banned)
@@ -1141,20 +1088,6 @@ async function viewerRegistrations(contract, tournamentId, offset, limit) {
1141
1088
  };
1142
1089
  }, contract.address);
1143
1090
  }
1144
- async function viewerRegistrationsByOwner(contract, tournamentId, owner, offset, limit) {
1145
- return wrapRpcCall(async () => {
1146
- const result = await contract.call("tournament_registrations_by_owner", [tournamentId, owner, offset, limit]);
1147
- const obj = result;
1148
- const entries = obj.entries ?? [];
1149
- const total = Number(obj.total ?? 0);
1150
- return {
1151
- data: entries.map((e) => parseRegistration(e, tournamentId)),
1152
- total,
1153
- limit,
1154
- offset
1155
- };
1156
- }, contract.address);
1157
- }
1158
1091
  async function viewerRegistrationsByTokenIds(contract, tournamentId, tokenIds, offset, limit) {
1159
1092
  return wrapRpcCall(async () => {
1160
1093
  const result = await contract.call("tournament_registrations_by_token_ids", [tournamentId, tokenIds, offset, limit]);
@@ -1200,12 +1133,6 @@ async function viewerRewardClaims(contract, tournamentId, offset, limit) {
1200
1133
  };
1201
1134
  }, contract.address);
1202
1135
  }
1203
- async function viewerPlayerTournaments(contract, playerAddress, offset, limit) {
1204
- return wrapRpcCall(async () => {
1205
- const result = await contract.call("player_tournaments", [playerAddress, offset, limit]);
1206
- return parseFilterResult(result);
1207
- }, contract.address);
1208
- }
1209
1136
 
1210
1137
  // src/rpc/abis/budokanViewer.json
1211
1138
  var budokanViewer_default = [
@@ -4513,9 +4440,6 @@ var BudokanClient = class {
4513
4440
  const contract = await this.getViewerContract();
4514
4441
  const offset = params?.offset ?? 0;
4515
4442
  const limit = params?.limit ?? 20;
4516
- if (params?.playerAddress) {
4517
- return viewerRegistrationsByOwner(contract, tournamentId, params.playerAddress, offset, limit);
4518
- }
4519
4443
  if (params?.gameTokenIds?.length) {
4520
4444
  return viewerRegistrationsByTokenIds(contract, tournamentId, params.gameTokenIds, offset, limit);
4521
4445
  }
@@ -4548,43 +4472,6 @@ var BudokanClient = class {
4548
4472
  this.connectionStatus
4549
4473
  );
4550
4474
  }
4551
- // ---- Player Queries (API-only, no on-chain equivalent) ----
4552
- /**
4553
- * Fetch tournaments that a player has registered for.
4554
- * Supports RPC fallback via viewer contract.
4555
- */
4556
- async getPlayerTournaments(address, params) {
4557
- const rpcFallback = async () => {
4558
- const contract = await this.getViewerContract();
4559
- const offset = params?.offset ?? 0;
4560
- const limit = params?.limit ?? 20;
4561
- const filterResult = await viewerPlayerTournaments(contract, address, offset, limit);
4562
- let data = [];
4563
- if (filterResult.tournamentIds.length > 0) {
4564
- const tournaments = await viewerTournamentsBatch(contract, filterResult.tournamentIds);
4565
- data = tournaments.map((t) => ({
4566
- ...t,
4567
- tournamentId: t.id
4568
- }));
4569
- }
4570
- return { data, total: filterResult.total, limit, offset };
4571
- };
4572
- if (this.resolvedConfig.primarySource === "rpc") {
4573
- return rpcFallback();
4574
- }
4575
- return withFallback(
4576
- () => getPlayerTournaments(this.resolvedConfig.apiBaseUrl, address, params, this.apiCtx),
4577
- rpcFallback,
4578
- this.connectionStatus
4579
- );
4580
- }
4581
- /**
4582
- * Fetch stats for a player.
4583
- * API-only — no RPC fallback available.
4584
- */
4585
- async getPlayerStats(address) {
4586
- return getPlayerStats(this.resolvedConfig.apiBaseUrl, address, this.apiCtx);
4587
- }
4588
4475
  // ---- Game Queries ----
4589
4476
  /**
4590
4477
  * Fetch tournaments for a specific game.
@@ -4683,13 +4570,6 @@ var BudokanClient = class {
4683
4570
  return getTournamentPrizeAggregation(this.resolvedConfig.apiBaseUrl, tournamentId, this.apiCtx);
4684
4571
  }
4685
4572
  // ---- Activity Queries (API-only, activity is indexed) ----
4686
- /**
4687
- * Fetch activity events with optional filtering.
4688
- * API-only — no RPC fallback available.
4689
- */
4690
- async getActivity(params) {
4691
- return getActivity(this.resolvedConfig.apiBaseUrl, params, this.apiCtx);
4692
- }
4693
4573
  /**
4694
4574
  * Fetch platform-wide activity stats.
4695
4575
  * API-only — no RPC fallback available.
@@ -4850,30 +4730,6 @@ function useTournamentCount(phase) {
4850
4730
  }, [fetch2]);
4851
4731
  return { count, loading, error, refetch: fetch2 };
4852
4732
  }
4853
- function usePlayerTournamentCount(address, phase) {
4854
- const client = useBudokanClient();
4855
- const [count, setCount] = react.useState(null);
4856
- const [loading, setLoading] = react.useState(!!address);
4857
- const [error, setError] = react.useState(null);
4858
- useResetOnClient(client, setCount, setError);
4859
- const fetch2 = react.useCallback(async () => {
4860
- if (!address) return;
4861
- setLoading(true);
4862
- setError(null);
4863
- try {
4864
- const result = await client.getPlayerTournaments(address, { phase, limit: 1 });
4865
- setCount(result.total ?? 0);
4866
- } catch (e) {
4867
- setError(e);
4868
- } finally {
4869
- setLoading(false);
4870
- }
4871
- }, [client, address, phase]);
4872
- react.useEffect(() => {
4873
- fetch2();
4874
- }, [fetch2]);
4875
- return { count, loading, error, refetch: fetch2 };
4876
- }
4877
4733
  function useLeaderboard(tournamentId) {
4878
4734
  const client = useBudokanClient();
4879
4735
  const [leaderboard, setLeaderboard] = react.useState(null);
@@ -4923,84 +4779,157 @@ function useRegistrations(tournamentId, params) {
4923
4779
  }, [fetch2]);
4924
4780
  return { registrations, loading, error, refetch: fetch2 };
4925
4781
  }
4926
- function usePlayer(address, params) {
4782
+ var MAX_OWNED_TOKENS = 1e3;
4783
+ var emptyPage = (limit, offset) => ({
4784
+ data: [],
4785
+ total: 0,
4786
+ limit,
4787
+ offset
4788
+ });
4789
+ function useOwnedTournamentIds(owner, contextId) {
4927
4790
  const client = useBudokanClient();
4928
- const [tournaments, setTournaments] = react.useState(null);
4929
- const [stats, setStats] = react.useState(null);
4930
- const [loading, setLoading] = react.useState(!!address);
4931
- const [error, setError] = react.useState(null);
4932
- useResetOnClient(client, setTournaments, setStats, setError);
4933
- const paramsKey = JSON.stringify(params);
4934
- const fetch2 = react.useCallback(async () => {
4935
- if (!address) return;
4936
- setLoading(true);
4937
- setError(null);
4938
- try {
4939
- const [tournamentsResult, statsResult] = await Promise.all([
4940
- client.getPlayerTournaments(address, params),
4941
- client.getPlayerStats(address)
4942
- ]);
4943
- setTournaments(tournamentsResult);
4944
- setStats(statsResult);
4945
- } catch (e) {
4946
- setError(e);
4947
- } finally {
4948
- setLoading(false);
4791
+ const budokanAddress = client.clientConfig.budokanAddress;
4792
+ const enabled = !!owner && !!budokanAddress;
4793
+ const { data, isLoading } = react$1.useTokens(
4794
+ enabled ? {
4795
+ owner,
4796
+ minterAddress: budokanAddress,
4797
+ hasContext: true,
4798
+ ...{},
4799
+ limit: MAX_OWNED_TOKENS
4800
+ } : void 0
4801
+ );
4802
+ const tournamentIds = react.useMemo(() => {
4803
+ if (!enabled) return null;
4804
+ if (!data?.data) return null;
4805
+ const ids = /* @__PURE__ */ new Set();
4806
+ for (const t of data.data) {
4807
+ if (t.contextId) ids.add(String(t.contextId));
4949
4808
  }
4950
- }, [client, address, paramsKey]);
4951
- react.useEffect(() => {
4952
- fetch2();
4953
- }, [fetch2]);
4954
- return { tournaments, stats, loading, error };
4809
+ return [...ids];
4810
+ }, [enabled, data]);
4811
+ return { tournamentIds, loading: isLoading };
4955
4812
  }
4956
- function usePlayerStats(address) {
4957
- const client = useBudokanClient();
4958
- const [stats, setStats] = react.useState(null);
4959
- const [loading, setLoading] = react.useState(!!address);
4960
- const [error, setError] = react.useState(null);
4961
- useResetOnClient(client, setStats, setError);
4962
- const fetch2 = react.useCallback(async () => {
4963
- if (!address) return;
4964
- setLoading(true);
4965
- setError(null);
4966
- try {
4967
- const result = await client.getPlayerStats(address);
4968
- setStats(result);
4969
- } catch (e) {
4970
- setError(e);
4971
- } finally {
4972
- setLoading(false);
4813
+ function useTournamentsByOwner(owner, params) {
4814
+ const { tournamentIds, loading: tokensLoading } = useOwnedTournamentIds(owner);
4815
+ const inner = useTournaments(
4816
+ tournamentIds && tournamentIds.length > 0 ? {
4817
+ tournamentIds,
4818
+ phase: params?.phase,
4819
+ limit: params?.limit,
4820
+ offset: params?.offset,
4821
+ sort: params?.sort,
4822
+ includePrizeSummary: params?.includePrizeSummary
4823
+ } : void 0
4824
+ );
4825
+ if (tournamentIds !== null && tournamentIds.length === 0) {
4826
+ return {
4827
+ tournaments: emptyPage(
4828
+ params?.limit ?? 50,
4829
+ params?.offset ?? 0
4830
+ ),
4831
+ loading: false,
4832
+ error: null,
4833
+ refetch: async () => {
4834
+ }
4835
+ };
4836
+ }
4837
+ return {
4838
+ tournaments: inner.tournaments,
4839
+ loading: tokensLoading || inner.loading,
4840
+ error: inner.error,
4841
+ refetch: inner.refetch
4842
+ };
4843
+ }
4844
+ function useTournamentsByOwnerCount(owner, params) {
4845
+ const { tournamentIds, loading: tokensLoading } = useOwnedTournamentIds(owner);
4846
+ const phaseFilter = params?.phase;
4847
+ const filtered = useTournaments(
4848
+ phaseFilter && tournamentIds && tournamentIds.length > 0 ? { tournamentIds, phase: phaseFilter, limit: 1 } : void 0
4849
+ );
4850
+ if (tournamentIds === null) {
4851
+ return {
4852
+ count: null,
4853
+ loading: tokensLoading,
4854
+ error: null,
4855
+ refetch: async () => {
4856
+ }
4857
+ };
4858
+ }
4859
+ if (tournamentIds.length === 0) {
4860
+ return {
4861
+ count: 0,
4862
+ loading: false,
4863
+ error: null,
4864
+ refetch: async () => {
4865
+ }
4866
+ };
4867
+ }
4868
+ if (!phaseFilter) {
4869
+ return {
4870
+ count: tournamentIds.length,
4871
+ loading: false,
4872
+ error: null,
4873
+ refetch: async () => {
4874
+ }
4875
+ };
4876
+ }
4877
+ return {
4878
+ count: filtered.tournaments?.total ?? null,
4879
+ loading: filtered.loading,
4880
+ error: filtered.error,
4881
+ refetch: async () => {
4973
4882
  }
4974
- }, [client, address]);
4975
- react.useEffect(() => {
4976
- fetch2();
4977
- }, [fetch2]);
4978
- return { stats, loading, error, refetch: fetch2 };
4883
+ };
4979
4884
  }
4980
- function usePlayerTournaments(address, params) {
4885
+ function useRegistrationsByOwner(tournamentId, owner, params) {
4981
4886
  const client = useBudokanClient();
4982
- const [tournaments, setTournaments] = react.useState(null);
4983
- const [loading, setLoading] = react.useState(!!address);
4984
- const [error, setError] = react.useState(null);
4985
- useResetOnClient(client, setTournaments, setError);
4986
- const paramsKey = JSON.stringify(params);
4987
- const fetch2 = react.useCallback(async () => {
4988
- if (!address) return;
4989
- setLoading(true);
4990
- setError(null);
4991
- try {
4992
- const result = await client.getPlayerTournaments(address, params);
4993
- setTournaments(result);
4994
- } catch (e) {
4995
- setError(e);
4996
- } finally {
4997
- setLoading(false);
4887
+ const budokanAddress = client.clientConfig.budokanAddress;
4888
+ const contextId = tournamentId ? Number(tournamentId) : void 0;
4889
+ const enabled = !!owner && !!budokanAddress && tournamentId != null && contextId !== void 0;
4890
+ const { data: tokensResult, isLoading: tokensLoading } = react$1.useTokens(
4891
+ enabled ? {
4892
+ owner,
4893
+ minterAddress: budokanAddress,
4894
+ contextId,
4895
+ limit: MAX_OWNED_TOKENS
4896
+ } : void 0
4897
+ );
4898
+ const ownedGameTokenIds = react.useMemo(() => {
4899
+ if (!enabled) return null;
4900
+ if (!tokensResult?.data) return null;
4901
+ const ids = [];
4902
+ for (const t of tokensResult.data) {
4903
+ if (t.tokenId == null) continue;
4904
+ try {
4905
+ ids.push(BigInt(String(t.tokenId)).toString());
4906
+ } catch {
4907
+ }
4998
4908
  }
4999
- }, [client, address, paramsKey]);
5000
- react.useEffect(() => {
5001
- fetch2();
5002
- }, [fetch2]);
5003
- return { tournaments, loading, error, refetch: fetch2 };
4909
+ return ids;
4910
+ }, [enabled, tokensResult]);
4911
+ const inner = useRegistrations(
4912
+ ownedGameTokenIds && ownedGameTokenIds.length > 0 ? tournamentId : void 0,
4913
+ ownedGameTokenIds && ownedGameTokenIds.length > 0 ? { ...params, gameTokenIds: ownedGameTokenIds } : void 0
4914
+ );
4915
+ if (ownedGameTokenIds !== null && ownedGameTokenIds.length === 0) {
4916
+ return {
4917
+ registrations: emptyPage(
4918
+ params?.limit ?? 50,
4919
+ params?.offset ?? 0
4920
+ ),
4921
+ loading: false,
4922
+ error: null,
4923
+ refetch: async () => {
4924
+ }
4925
+ };
4926
+ }
4927
+ return {
4928
+ registrations: inner.registrations,
4929
+ loading: tokensLoading || inner.loading,
4930
+ error: inner.error,
4931
+ refetch: inner.refetch
4932
+ };
5004
4933
  }
5005
4934
  function useRewardClaims(tournamentId, params) {
5006
4935
  const client = useBudokanClient();
@@ -5220,20 +5149,19 @@ exports.useActivityStats = useActivityStats;
5220
5149
  exports.useBudokanClient = useBudokanClient;
5221
5150
  exports.useConnectionStatus = useConnectionStatus;
5222
5151
  exports.useLeaderboard = useLeaderboard;
5223
- exports.usePlayer = usePlayer;
5224
- exports.usePlayerStats = usePlayerStats;
5225
- exports.usePlayerTournamentCount = usePlayerTournamentCount;
5226
- exports.usePlayerTournaments = usePlayerTournaments;
5227
5152
  exports.usePrizeAggregation = usePrizeAggregation;
5228
5153
  exports.usePrizeStats = usePrizeStats;
5229
5154
  exports.usePrizes = usePrizes;
5230
5155
  exports.useQualifications = useQualifications;
5231
5156
  exports.useRegistrations = useRegistrations;
5157
+ exports.useRegistrationsByOwner = useRegistrationsByOwner;
5232
5158
  exports.useRewardClaims = useRewardClaims;
5233
5159
  exports.useRewardClaimsSummary = useRewardClaimsSummary;
5234
5160
  exports.useSubscription = useSubscription;
5235
5161
  exports.useTournament = useTournament;
5236
5162
  exports.useTournamentCount = useTournamentCount;
5237
5163
  exports.useTournaments = useTournaments;
5164
+ exports.useTournamentsByOwner = useTournamentsByOwner;
5165
+ exports.useTournamentsByOwnerCount = useTournamentsByOwnerCount;
5238
5166
  //# sourceMappingURL=react.cjs.map
5239
5167
  //# sourceMappingURL=react.cjs.map