Skip to content

Commit

Permalink
Merge pull request #53 from JetonDAO/show-down-bugs
Browse files Browse the repository at this point in the history
fix show down bugs
  • Loading branch information
farzaamam authored Oct 14, 2024
2 parents f238a85 + 7c8734a commit 34a1e68
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
8 changes: 6 additions & 2 deletions apps/web/src/app/games/[id]/components/PlayerActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ export default function PlayerActions() {
const [queuedAction, setQueuedAction] = useState<PlacingBettingActions | null>(null);
const [isActionQueued, setIsActionQueued] = useState(false);
const { account } = useWallet();
const [address, setInAppAddress] = useState<string>();
const mainPlayer = useMemo(() => {
const [address, _] = finalAddress(account?.address || "");
return players?.find((player) => player?.id === address);
}, [players, account]);
}, [players, address]);
const isPlayerTurn = awaitingBetFrom?.id === mainPlayer?.id;
const actions: PlacingBettingActions[] = [
PlacingBettingActions.FOLD,
PlacingBettingActions.CHECK_CALL,
PlacingBettingActions.RAISE,
];

useEffect(() => {
setInAppAddress(finalAddress(account?.address || ""));
}, [account]);

useEffect(() => {
if (isPlayerTurn && queuedAction) {
console.log(`Player turn, executing queued action: ${queuedAction}`);
Expand Down
5 changes: 4 additions & 1 deletion packages/ts-sdk/src/Jeton/Jeton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@ export class Jeton extends EventEmitter<GameEventMap> {
if (!this.gameState) throw new Error(" must exist");
const players = this.gameState.players;
const eventData: ShowDownEvent = {};
const privateCards = hexStringToUint8Array(data.privateCards);
const publicCards = hexStringToUint8Array(data.privateCards);
console.log("show down results", privateCards, publicCards, data.winningAmounts);
for (const [index, player] of players.entries()) {
eventData[player.id] = {
player,
winAmount: data.winningAmounts[index]!,
cards: [data.privateCards[index * 2]!, data.privateCards[index * 2 + 1]!],
cards: [privateCards[index * 2]!, privateCards[index * 2 + 1]!],
};
}
this.emit(GameEventTypes.SHOW_DOWN, eventData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export class AptosOnChainDataSource
console.log("publishing", OnChainEventTypes.SHOW_DOWN);
const data = (event as ShowDownEvent).data;
this.emit(OnChainEventTypes.SHOW_DOWN, {
publicCards: data.public_cards.map((p) => Number(p)),
privateCards: data.private_cards.map((p) => Number(p)),
publicCards: data.public_cards,
privateCards: data.private_cards,
winningAmounts: data.winning_amounts.map((a) => Number(a)),
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-sdk/src/OnChainDataSource/onChainEvents.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export type OnChainPlayerPlacedBetData = {
};

export type OnChainShowDownData = {
privateCards: number[];
publicCards: number[];
privateCards: string;
publicCards: string;
winningAmounts: number[];
};

Expand Down
2 changes: 1 addition & 1 deletion packages/ts-sdk/src/contracts/contractInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface GeneralEvent extends BaseEvent {
}

export interface ShowDownEvent extends BaseEvent {
data: { private_cards: number[]; public_cards: number[]; winning_amounts: number[] };
data: { private_cards: string; public_cards: string; winning_amounts: number[] };
indexed_type: typeof contractShowDownEventType;
transaction_block_height: number;
}
Expand Down

0 comments on commit 34a1e68

Please sign in to comment.