@provable-games/budokan-sdk 0.1.21 → 0.1.22

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
@@ -1114,6 +1114,84 @@ async function viewerPrizes(contract, tournamentId) {
1114
1114
  return result.map(parsePrize);
1115
1115
  }, contract.address);
1116
1116
  }
1117
+ function translateCairoRewardType(rewardType) {
1118
+ if (!rewardType || typeof rewardType !== "object") {
1119
+ throw new Error(`Unexpected RewardType payload: ${JSON.stringify(rewardType)}`);
1120
+ }
1121
+ const rt = rewardType;
1122
+ const outer = typeof rt.activeVariant === "function" ? rt.activeVariant() : null;
1123
+ const innerBag = typeof rt.activeVariant === "function" ? rt.variant : rt;
1124
+ if (outer === "Prize" || innerBag.Prize !== void 0) {
1125
+ const prize = innerBag.Prize;
1126
+ const subVariant = typeof prize?.activeVariant === "function" ? prize.activeVariant() : null;
1127
+ const subBag = typeof prize?.activeVariant === "function" ? prize.variant : prize;
1128
+ if (subVariant === "Single" || subBag?.Single !== void 0) {
1129
+ return {
1130
+ claimKind: "prize_single",
1131
+ prizeId: BigInt(subBag.Single).toString(),
1132
+ payoutIndex: null,
1133
+ position: null,
1134
+ refundTokenId: null
1135
+ };
1136
+ }
1137
+ if (subVariant === "Distributed" || subBag?.Distributed !== void 0) {
1138
+ const distributed = subBag.Distributed;
1139
+ const prizeId = distributed?.["0"] ?? distributed?.[0];
1140
+ const payoutIndex = distributed?.["1"] ?? distributed?.[1];
1141
+ return {
1142
+ claimKind: "prize_distributed",
1143
+ prizeId: BigInt(prizeId).toString(),
1144
+ payoutIndex: Number(payoutIndex),
1145
+ position: null,
1146
+ refundTokenId: null
1147
+ };
1148
+ }
1149
+ }
1150
+ if (outer === "EntryFee" || innerBag.EntryFee !== void 0) {
1151
+ const entryFee = innerBag.EntryFee;
1152
+ const subVariant = typeof entryFee?.activeVariant === "function" ? entryFee.activeVariant() : null;
1153
+ const subBag = typeof entryFee?.activeVariant === "function" ? entryFee.variant : entryFee;
1154
+ if (subVariant === "Position" || subBag?.Position !== void 0) {
1155
+ return {
1156
+ claimKind: "entry_fee_position",
1157
+ prizeId: null,
1158
+ payoutIndex: null,
1159
+ position: Number(subBag.Position),
1160
+ refundTokenId: null
1161
+ };
1162
+ }
1163
+ if (subVariant === "TournamentCreator" || subBag?.TournamentCreator !== void 0) {
1164
+ return {
1165
+ claimKind: "entry_fee_tournament_creator",
1166
+ prizeId: null,
1167
+ payoutIndex: null,
1168
+ position: null,
1169
+ refundTokenId: null
1170
+ };
1171
+ }
1172
+ if (subVariant === "GameCreator" || subBag?.GameCreator !== void 0) {
1173
+ return {
1174
+ claimKind: "entry_fee_game_creator",
1175
+ prizeId: null,
1176
+ payoutIndex: null,
1177
+ position: null,
1178
+ refundTokenId: null
1179
+ };
1180
+ }
1181
+ if (subVariant === "Refund" || subBag?.Refund !== void 0) {
1182
+ return {
1183
+ claimKind: "entry_fee_refund",
1184
+ prizeId: null,
1185
+ payoutIndex: null,
1186
+ position: null,
1187
+ refundTokenId: `0x${BigInt(subBag.Refund).toString(16)}`
1188
+ };
1189
+ }
1190
+ }
1191
+ throw new Error(
1192
+ `Unrecognised on-chain RewardType variant: ${JSON.stringify(rewardType)}`
1193
+ );
1194
+ }
1117
1195
  async function viewerRewardClaims(contract, tournamentId, offset, limit) {
1118
1196
  return wrapRpcCall(async () => {
1119
1197
  const result = await contract.call("tournament_reward_claims", [tournamentId, offset, limit]);
@@ -1121,7 +1199,7 @@ async function viewerRewardClaims(contract, tournamentId, offset, limit) {
1121
1199
  const claims = obj.claims?.map((raw) => {
1122
1200
  const claim = raw;
1123
1201
  return {
1124
- rewardType: claim.reward_type,
1202
+ ...translateCairoRewardType(claim.reward_type),
1125
1203
  claimed: Boolean(claim.claimed)
1126
1204
  };
1127
1205
  }) ?? [];
@@ -4518,8 +4596,7 @@ var BudokanClient = class {
4518
4596
  const result = await viewerRewardClaims(contract, tournamentId, offset, limit);
4519
4597
  const data = result.claims.map((c) => ({
4520
4598
  tournamentId,
4521
- rewardType: c.rewardType,
4522
- claimed: c.claimed
4599
+ ...c
4523
4600
  }));
4524
4601
  return { data, total: result.total, limit, offset };
4525
4602
  };