Skip to content

Commit

Permalink
Yd/signless battleship corrections (#320)
Browse files Browse the repository at this point in the history
Co-authored-by: Yauheni <[email protected]>
  • Loading branch information
YauheniDraichykau and Yauheni authored Apr 8, 2024
1 parent 6dadad4 commit e1f851f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,34 @@ export default function GameProcess() {
}
}, [gameState]);

const onClickCellFinally = () => {
setDisabledCell(false);
};

const onClickCell = async (indexCell: number) => {
const gasLimit = 120000000000;

if (!gasless.isLoading) {
setDisabledCell(true);

checkBalance(gasLimit, () =>
message({
payload: { Turn: { step: indexCell } },
onInBlock: (messageId) => {
if (messageId) {
setDisabledCell(false);
}
},
gasLimit,
voucherId: gasless.voucherId,
onSuccess: () => {
setPending(false);
},
onError: () => {
setDisabledCell(false);
},
}),
checkBalance(
gasLimit,
() =>
message({
payload: { Turn: { step: indexCell } },
onInBlock: (messageId) => {
if (messageId) {
onClickCellFinally();
}
},
gasLimit,
voucherId: gasless.voucherId,
onSuccess: () => {
setPending(false);
},
onError: onClickCellFinally,
}),
onClickCellFinally,
);
}
};
Expand Down Expand Up @@ -164,7 +169,7 @@ export default function GameProcess() {
sizeBlock={86}
onClickCell={onClickCell}
shipStatusArray={enemiesShips}
isDisabledCell={isDisabledCell || gasless.isLoading}
isDisabledCell={isDisabledCell || gasless.isLoading || gameState.gameOver}
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function MapEnemy({ sizeBlock = 64, shipStatusArray, onClickCell,
};

const handleCellClick = (cellIndex: number) => {
if (!isDisabledCell) {
if (!isDisabledCell && !['Boom', 'BoomShip', 'DeadShip'].includes(shipStatusArray[cellIndex])) {
onClickCell(cellIndex);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { useEzTransactions } from '../../context';

type Props = {
disabled?: boolean;
disabledTurnOn?: boolean;
};

function EzGaslessTransactions({ disabled, disabledTurnOn }: Props) {
function EzGaslessTransactions({ disabled }: Props) {
const { signless } = useEzTransactions();

return <GaslessTransactions disabled={signless.isSessionActive || disabled} disabledTurnOn={disabledTurnOn} />;
return <GaslessTransactions disabled={signless.isSessionActive || disabled} />;
}

export { EzGaslessTransactions };
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import { ChangeEvent } from 'react';
type Props = {
type: 'button' | 'switcher';
disabled?: boolean;
disabledTurnOn?: boolean;
message?: string;
};

function EnableGaslessSession({ type, disabled, disabledTurnOn, message }: Props) {
function EnableGaslessSession({ type, disabled, message }: Props) {
const { account } = useAccount();
const { isAvailable, isLoading, isEnabled, setIsEnabled } = useGaslessTransactions();

const handleSwitchChange = ({ target }: ChangeEvent<HTMLInputElement>) => setIsEnabled(target.checked);

const handleEnableButtonClick = () => setIsEnabled(true);
const handleDisableButtonClick = () => setIsEnabled(false);
console.log('disabledTurnOn', disabledTurnOn);

return account ? (
<>
{type === 'button' && (
Expand All @@ -40,7 +39,7 @@ function EnableGaslessSession({ type, disabled, disabledTurnOn, message }: Props
icon={GaslessSVG}
color="transparent"
text="Enable gasless transactions"
disabled={disabled || !isAvailable || isLoading || disabledTurnOn}
disabled={disabled || !isAvailable || isLoading}
className={styles.enableButton}
onClick={handleEnableButtonClick}
/>
Expand All @@ -54,7 +53,7 @@ function EnableGaslessSession({ type, disabled, disabledTurnOn, message }: Props
<Checkbox
label=""
type="switch"
disabled={disabled || !isAvailable || isLoading || disabledTurnOn}
disabled={disabled || !isAvailable || isLoading}
checked={isEnabled}
onChange={handleSwitchChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { ReactComponent as GaslessSVG } from '../../assets/icons/gas-station-lin

type Props = {
disabled?: boolean;
disabledTurnOn?: boolean;
};

function GaslessTransactions({ disabled, disabledTurnOn }: Props) {
function GaslessTransactions({ disabled }: Props) {
const { account } = useAccount();
const { isEnabled, isActive } = useGaslessTransactions();

Expand All @@ -27,7 +26,7 @@ function GaslessTransactions({ disabled, disabledTurnOn }: Props) {
</div>
)}

{!isEnabled && <EnableGaslessSession type="button" disabled={disabled} disabledTurnOn={disabledTurnOn} />}
{!isEnabled && <EnableGaslessSession type="button" disabled={disabled} />}
</div>
) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function useCreateSession(programId: HexString, metadata: ProgramMetadata | unde
if (!isExpired) {
const declineExtrinsic = api.voucher.call(voucher.id, { DeclineVoucher: null });

await sendTransaction(declineExtrinsic, pair, ['VoucherDeclined'], { ...options, onError });
await sendTransaction(declineExtrinsic, pair, ['VoucherDeclined']);
}

if (isOwner) {
Expand Down

0 comments on commit e1f851f

Please sign in to comment.