Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Fixes frontend according to new contract changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yauheni committed Aug 29, 2023
1 parent d33f001 commit 73eb8c4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions frontend/src/features/session/components/radar/Radar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {
};

function Radar({ currentEvents, currentRound, roundsCount, isWinner, userRank, reward }: Props) {
console.log(roundsCount);
const getPlayers = () =>
currentEvents?.map(({ participant, deadRound }, index) => {
const playerNumber = index + 1;
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/features/session/components/session/Session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Session({ session, turns, rankings, userId }: Props) {
const lastPage = () => setRoundIndex(roundsCount - 1);

const getEvents = (): Event[] =>
turns[roundIndex].map((participantInfo) => {
turns?.[roundIndex]?.map((participantInfo) => {
const isAlive = Object.keys(participantInfo[1])[0] === 'Alive';

return {
Expand All @@ -49,7 +49,7 @@ function Session({ session, turns, rankings, userId }: Props) {
});

const getFeedItems = () =>
getEvents().map(({ participant, halt, payload, lastAltitude, fuelLeft, deadRound }, index) => (
getEvents()?.map(({ participant, halt, payload, lastAltitude, fuelLeft, deadRound }, index) => (
<li key={participant} className={styles.item} style={{ '--color': PLAYER_COLORS[index] } as CSSProperties}>
<h3 className={styles.heading}>{participant}</h3>
<div className={styles.bodyItem}>
Expand Down Expand Up @@ -120,9 +120,9 @@ function Session({ session, turns, rankings, userId }: Props) {
currentEvents={getEvents()}
currentRound={roundIndex}
roundsCount={roundsCount}
isWinner={userId === sortRanks()[0][0]}
reward={(rankings.find((rank) => rank[0] === userId) as Rank)[1]}
userRank={sortRanks().findIndex((rank) => rank[0] === userId) + 1}
isWinner={userId === sortRanks()?.[0]?.[0]}
reward={(rankings?.find((rank) => rank[0] === userId) as Rank)?.[1]}
userRank={sortRanks()?.findIndex((rank) => rank[0] === userId) || 0 + 1}
/>
</div>
);
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/features/session/components/start/Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Start({ participants, session, isUserAdmin, userAddress }: Props) {
const setCurrentContractAddress = useSetAtom(CURRENT_CONTRACT_ADDRESS_ATOM);
const setIsContractAddressInitialized = useSetAtom(IS_CONTRACT_ADDRESS_INITIALIZED_ATOM);
const { altitude, weather, fuelPrice, reward, sessionId } = session;
const playersCount = participants?.length ? participants.length : 1;
const playersCount = participants?.length ? participants.length + 1 : 1;
const isRegistered = decodedAddress ? !!participants.some((participant) => participant[0] === decodedAddress) : false;

const containerClassName = clsx(styles.container, decodedAddress ? styles.smallMargin : styles.largeMargin);
Expand All @@ -49,7 +49,6 @@ function Start({ participants, session, isUserAdmin, userAddress }: Props) {
>('registration');

const meta = useEscrowMetadata();

const getDecodedPayload = (payload: Vec<u8>) => {
if (meta?.types.handle.output) {
return meta.createType(meta.types.handle.output, payload).toHuman();
Expand All @@ -75,7 +74,7 @@ function Start({ participants, session, isUserAdmin, userAddress }: Props) {

if (isOwner && isEscrowProgram) {
const reply = getDecodedReply(payload);

// console.log(reply);
if (reply?.Err) {
if (reply.Err === 'NotEnoughParticipants' || reply.Err === 'MaximumPlayersReached') {
setRegistrationStatus(reply.Err);
Expand All @@ -101,7 +100,7 @@ function Start({ participants, session, isUserAdmin, userAddress }: Props) {
}, [api, decodedAddress, meta]);

useEffect(() => {
if (registrationStatus === 'NotEnoughParticipants' && participants.length > 1) {
if (registrationStatus === 'NotEnoughParticipants' && participants.length) {
setRegistrationStatus('registration');
}
}, [participants, registrationStatus]);
Expand Down Expand Up @@ -140,7 +139,7 @@ function Start({ participants, session, isUserAdmin, userAddress }: Props) {

<footer>
{isRegistered && !isUserAdmin && <SuccessfullyRegisteredInfo />}
{isRegistered &&
{!participants.length &&
isUserAdmin &&
registrationStatus === 'NotEnoughParticipants' &&
participants.length < 2 && (
Expand All @@ -158,7 +157,8 @@ function Start({ participants, session, isUserAdmin, userAddress }: Props) {
{!isRegistered && registrationStatus === 'error' && !isUserAdmin && (
<Warning title="Error" text="Please try again later or choose another contract address." />
)}
{((isUserAdmin && registrationStatus !== 'NotEnoughParticipants') || (!isUserAdmin && !isRegistered && registrationStatus === 'registration')) && (
{((isUserAdmin && registrationStatus !== 'NotEnoughParticipants') ||
(!isUserAdmin && !isRegistered && registrationStatus === 'registration')) && (
<Form
weather={weather}
defaultDeposit={withoutCommas('0')}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/session/components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Table({ data, userId }: Props) {
));

const getBody = () =>
data.map(({ participant, deadRound, fuelLeft, lastAltitude, payload, halt }, index) => (
data?.map(({ participant, deadRound, fuelLeft, lastAltitude, payload, halt }, index) => (
<Fragment key={participant}>
<div
className={cx(styles.bodyCell, styles.firstColumn)}
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ function Home() {
const { sessionId, altitude, weather, fuelPrice, reward } = session || {};

const isUserAdmin = admin === account?.decodedAddress;
const doesSessionExist = !!isSessionEnded;
const isStateComing = !!state;

console.log(state);
return (
<>
{!isContractAddressInitialized && (
{(!isContractAddressInitialized || (!Number(sessionId) && isSessionEnded)) && (
<Welcome>
{account ? (
<EnterContractAddress
doesSessionExist={doesSessionExist}
doesSessionExist={!isSessionEnded}
isUserAdmin={isUserAdmin}
isStateComing={isStateComing}
/>
Expand Down

0 comments on commit 73eb8c4

Please sign in to comment.