@provable-games/budokan-sdk 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/dist/{client-CYj1Iw_w.d.cts → client-ugXv3NlV.d.cts} +8 -2
- package/dist/{client-CYj1Iw_w.d.ts → client-ugXv3NlV.d.ts} +8 -2
- package/dist/index.cjs +54 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +54 -7
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +66 -16
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +13 -4
- package/dist/react.d.ts +13 -4
- package/dist/react.js +66 -16
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.cjs
CHANGED
|
@@ -249,6 +249,10 @@ async function getTournamentLeaderboard(baseUrl, tournamentId, ctx) {
|
|
|
249
249
|
}
|
|
250
250
|
async function getTournamentRegistrations(baseUrl, tournamentId, params, ctx) {
|
|
251
251
|
const qs = buildQueryString({
|
|
252
|
+
player_address: params?.playerAddress,
|
|
253
|
+
game_token_ids: params?.gameTokenIds?.length ? params.gameTokenIds.join(",") : void 0,
|
|
254
|
+
has_submitted: params?.hasSubmitted,
|
|
255
|
+
is_banned: params?.isBanned,
|
|
252
256
|
limit: params?.limit,
|
|
253
257
|
offset: params?.offset
|
|
254
258
|
});
|
|
@@ -1112,7 +1116,9 @@ async function viewerTournamentsByPhase(contract, phase, offset, limit) {
|
|
|
1112
1116
|
async function viewerTournamentDetail(contract, tournamentId) {
|
|
1113
1117
|
return wrapRpcCall(async () => {
|
|
1114
1118
|
const result = await contract.call("tournament_detail", [tournamentId]);
|
|
1115
|
-
|
|
1119
|
+
const tournament = parseTournamentFullState(result);
|
|
1120
|
+
if (!tournament.gameAddress || tournament.gameAddress === "0x0") return null;
|
|
1121
|
+
return tournament;
|
|
1116
1122
|
}, contract.address);
|
|
1117
1123
|
}
|
|
1118
1124
|
async function viewerTournamentsBatch(contract, tournamentIds) {
|
|
@@ -1135,6 +1141,34 @@ async function viewerRegistrations(contract, tournamentId, offset, limit) {
|
|
|
1135
1141
|
};
|
|
1136
1142
|
}, contract.address);
|
|
1137
1143
|
}
|
|
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
|
+
async function viewerRegistrationsByTokenIds(contract, tournamentId, tokenIds, offset, limit) {
|
|
1159
|
+
return wrapRpcCall(async () => {
|
|
1160
|
+
const result = await contract.call("tournament_registrations_by_token_ids", [tournamentId, tokenIds, offset, limit]);
|
|
1161
|
+
const obj = result;
|
|
1162
|
+
const entries = obj.entries ?? [];
|
|
1163
|
+
const total = Number(obj.total ?? 0);
|
|
1164
|
+
return {
|
|
1165
|
+
data: entries.map((e) => parseRegistration(e, tournamentId)),
|
|
1166
|
+
total,
|
|
1167
|
+
limit,
|
|
1168
|
+
offset
|
|
1169
|
+
};
|
|
1170
|
+
}, contract.address);
|
|
1171
|
+
}
|
|
1138
1172
|
async function viewerLeaderboard(contract, tournamentId, offset, limit) {
|
|
1139
1173
|
return wrapRpcCall(async () => {
|
|
1140
1174
|
const result = await contract.call("leaderboard", [tournamentId, offset, limit]);
|
|
@@ -2521,11 +2555,16 @@ var BudokanClient = class {
|
|
|
2521
2555
|
if (this.resolvedConfig.primarySource === "rpc") {
|
|
2522
2556
|
return rpcFallback();
|
|
2523
2557
|
}
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2558
|
+
try {
|
|
2559
|
+
return await getTournament(this.resolvedConfig.apiBaseUrl, tournamentId, this.apiCtx);
|
|
2560
|
+
} catch {
|
|
2561
|
+
try {
|
|
2562
|
+
this.connectionStatus.markApiUnavailable();
|
|
2563
|
+
return await rpcFallback();
|
|
2564
|
+
} catch {
|
|
2565
|
+
return null;
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2529
2568
|
}
|
|
2530
2569
|
/**
|
|
2531
2570
|
* Fetch the leaderboard for a tournament.
|
|
@@ -2548,13 +2587,21 @@ var BudokanClient = class {
|
|
|
2548
2587
|
/**
|
|
2549
2588
|
* Fetch registrations for a tournament.
|
|
2550
2589
|
* Supports RPC fallback when API is unavailable.
|
|
2551
|
-
* Note: In RPC mode, `playerAddress` and `gameAddress` fields will be empty strings
|
|
2590
|
+
* Note: In RPC mode, `playerAddress` and `gameAddress` fields will be empty strings,
|
|
2591
|
+
* and filter params (`playerAddress`, `gameTokenIds`, `hasSubmitted`, `isBanned`)
|
|
2592
|
+
* are applied via on-chain viewer functions where supported.
|
|
2552
2593
|
*/
|
|
2553
2594
|
async getTournamentRegistrations(tournamentId, params) {
|
|
2554
2595
|
const rpcFallback = async () => {
|
|
2555
2596
|
const contract = await this.getViewerContract();
|
|
2556
2597
|
const offset = params?.offset ?? 0;
|
|
2557
2598
|
const limit = params?.limit ?? 20;
|
|
2599
|
+
if (params?.playerAddress) {
|
|
2600
|
+
return viewerRegistrationsByOwner(contract, tournamentId, params.playerAddress, offset, limit);
|
|
2601
|
+
}
|
|
2602
|
+
if (params?.gameTokenIds?.length) {
|
|
2603
|
+
return viewerRegistrationsByTokenIds(contract, tournamentId, params.gameTokenIds, offset, limit);
|
|
2604
|
+
}
|
|
2558
2605
|
return viewerRegistrations(contract, tournamentId, offset, limit);
|
|
2559
2606
|
};
|
|
2560
2607
|
if (this.resolvedConfig.primarySource === "rpc") {
|
|
@@ -2959,20 +3006,21 @@ function useRegistrations(tournamentId, params) {
|
|
|
2959
3006
|
}, [fetch2]);
|
|
2960
3007
|
return { registrations, loading, error, refetch: fetch2 };
|
|
2961
3008
|
}
|
|
2962
|
-
function usePlayer(address) {
|
|
3009
|
+
function usePlayer(address, params) {
|
|
2963
3010
|
const client = useBudokanClient();
|
|
2964
3011
|
const [tournaments, setTournaments] = react.useState(null);
|
|
2965
3012
|
const [stats, setStats] = react.useState(null);
|
|
2966
3013
|
const [loading, setLoading] = react.useState(!!address);
|
|
2967
3014
|
const [error, setError] = react.useState(null);
|
|
2968
3015
|
useResetOnClient(client, setTournaments, setStats, setError);
|
|
3016
|
+
const paramsKey = JSON.stringify(params);
|
|
2969
3017
|
const fetch2 = react.useCallback(async () => {
|
|
2970
3018
|
if (!address) return;
|
|
2971
3019
|
setLoading(true);
|
|
2972
3020
|
setError(null);
|
|
2973
3021
|
try {
|
|
2974
3022
|
const [tournamentsResult, statsResult] = await Promise.all([
|
|
2975
|
-
client.getPlayerTournaments(address),
|
|
3023
|
+
client.getPlayerTournaments(address, params),
|
|
2976
3024
|
client.getPlayerStats(address)
|
|
2977
3025
|
]);
|
|
2978
3026
|
setTournaments(tournamentsResult);
|
|
@@ -2982,7 +3030,7 @@ function usePlayer(address) {
|
|
|
2982
3030
|
} finally {
|
|
2983
3031
|
setLoading(false);
|
|
2984
3032
|
}
|
|
2985
|
-
}, [client, address]);
|
|
3033
|
+
}, [client, address, paramsKey]);
|
|
2986
3034
|
react.useEffect(() => {
|
|
2987
3035
|
fetch2();
|
|
2988
3036
|
}, [fetch2]);
|
|
@@ -3037,25 +3085,26 @@ function usePlayerTournaments(address, params) {
|
|
|
3037
3085
|
}, [fetch2]);
|
|
3038
3086
|
return { tournaments, loading, error, refetch: fetch2 };
|
|
3039
3087
|
}
|
|
3040
|
-
function useRewardClaims(tournamentId) {
|
|
3088
|
+
function useRewardClaims(tournamentId, params) {
|
|
3041
3089
|
const client = useBudokanClient();
|
|
3042
3090
|
const [rewardClaims, setRewardClaims] = react.useState(null);
|
|
3043
3091
|
const [loading, setLoading] = react.useState(!!tournamentId);
|
|
3044
3092
|
const [error, setError] = react.useState(null);
|
|
3045
3093
|
useResetOnClient(client, setRewardClaims, setError);
|
|
3094
|
+
const paramsKey = JSON.stringify(params);
|
|
3046
3095
|
const fetch2 = react.useCallback(async () => {
|
|
3047
3096
|
if (!tournamentId) return;
|
|
3048
3097
|
setLoading(true);
|
|
3049
3098
|
setError(null);
|
|
3050
3099
|
try {
|
|
3051
|
-
const result = await client.getTournamentRewardClaims(tournamentId);
|
|
3100
|
+
const result = await client.getTournamentRewardClaims(tournamentId, params);
|
|
3052
3101
|
setRewardClaims(result);
|
|
3053
3102
|
} catch (e) {
|
|
3054
3103
|
setError(e);
|
|
3055
3104
|
} finally {
|
|
3056
3105
|
setLoading(false);
|
|
3057
3106
|
}
|
|
3058
|
-
}, [client, tournamentId]);
|
|
3107
|
+
}, [client, tournamentId, paramsKey]);
|
|
3059
3108
|
react.useEffect(() => {
|
|
3060
3109
|
fetch2();
|
|
3061
3110
|
}, [fetch2]);
|
|
@@ -3156,25 +3205,26 @@ function usePrizeAggregation(tournamentId) {
|
|
|
3156
3205
|
}, [fetch2]);
|
|
3157
3206
|
return { prizeAggregation, loading, error, refetch: fetch2 };
|
|
3158
3207
|
}
|
|
3159
|
-
function useQualifications(tournamentId) {
|
|
3208
|
+
function useQualifications(tournamentId, params) {
|
|
3160
3209
|
const client = useBudokanClient();
|
|
3161
3210
|
const [qualifications, setQualifications] = react.useState(null);
|
|
3162
3211
|
const [loading, setLoading] = react.useState(!!tournamentId);
|
|
3163
3212
|
const [error, setError] = react.useState(null);
|
|
3164
3213
|
useResetOnClient(client, setQualifications, setError);
|
|
3214
|
+
const paramsKey = JSON.stringify(params);
|
|
3165
3215
|
const fetch2 = react.useCallback(async () => {
|
|
3166
3216
|
if (!tournamentId) return;
|
|
3167
3217
|
setLoading(true);
|
|
3168
3218
|
setError(null);
|
|
3169
3219
|
try {
|
|
3170
|
-
const result = await client.getTournamentQualifications(tournamentId);
|
|
3220
|
+
const result = await client.getTournamentQualifications(tournamentId, params);
|
|
3171
3221
|
setQualifications(result);
|
|
3172
3222
|
} catch (e) {
|
|
3173
3223
|
setError(e);
|
|
3174
3224
|
} finally {
|
|
3175
3225
|
setLoading(false);
|
|
3176
3226
|
}
|
|
3177
|
-
}, [client, tournamentId]);
|
|
3227
|
+
}, [client, tournamentId, paramsKey]);
|
|
3178
3228
|
react.useEffect(() => {
|
|
3179
3229
|
fetch2();
|
|
3180
3230
|
}, [fetch2]);
|