Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game E2E flow fixes #95

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/sdk/src/GameSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class GamesSDK {
await this.api.saveSessionTX(txHash, [ethAccount.address, cereAccount.address]);
}

private async startSession() {
async startSession() {
this.session = await this.api.startSession();
this.sessionEvents = [];

Expand Down Expand Up @@ -281,7 +281,7 @@ export class GamesSDK {

async showConnectWallet({ onConnect, onComplete, score }: ShowConnectWalletOptions = {}) {
const connectWallet = document.createElement('cere-connect-wallet');
const { open, ...modal } = UI.createFullscreenModal(connectWallet, { hasClose: true });
const { open, ...modal } = UI.createFullscreenModal(connectWallet);

connectWallet.update({
score,
Expand Down
20 changes: 4 additions & 16 deletions packages/ui/src/components/ProgressiveImg/ProgressiveImg.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ImgHTMLAttributes, useEffect, useState } from 'react';
import { ImgHTMLAttributes } from 'react';
import styled from '@emotion/styled';

import { Spinner } from '../Spinner';
import { Stack } from '../Stack';

export type ProgressiveImgProps = Partial<ImgHTMLAttributes<HTMLImageElement>> & {
src?: string;
isLoadingProp: boolean;
mazhutoanton marked this conversation as resolved.
Show resolved Hide resolved
};

const StyledImage = styled.img({
Expand All @@ -23,23 +24,10 @@ const StyledStack = styled(Stack)({
height: '100%',
});

export const ProgressiveImg = ({ src, ...props }: ProgressiveImgProps) => {
const [isLoading, setLoading] = useState(false);

useEffect(() => {
if (src) {
setLoading(true);
const img = new Image();
img.src = src;
img.onload = () => {
setLoading(false);
};
}
}, [src]);

export const ProgressiveImg = ({ src, isLoadingProp, ...props }: ProgressiveImgProps) => {
return (
<StyledStack align="center">
{isLoading ? <Spinner size="25" /> : <StyledImage src={src} alt={props.alt || ''} className="image" />}
{isLoadingProp ? <Spinner size="25" /> : <StyledImage src={src} alt={props.alt || ''} className="image" />}
</StyledStack>
);
};
2 changes: 1 addition & 1 deletion packages/ui/src/widgets/Preloader/Preloader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const Preloader = ({ ready = false, onStartClick }: PreloaderProps) => {
{loading ? (
<Spinner size="25" />
) : (
preloader.url && <ProgressiveImg src={preloader.url} alt="Preloader image" />
preloader.url && <ProgressiveImg src={preloader.url} isLoadingProp={loading} alt="Preloader image" />
)}
</ImageBlock>

Expand Down