diff --git a/packages/sdk/src/GameSdk.ts b/packages/sdk/src/GameSdk.ts index 4dfc79a8..faa7ec72 100644 --- a/packages/sdk/src/GameSdk.ts +++ b/packages/sdk/src/GameSdk.ts @@ -21,7 +21,7 @@ import { Reporting, ReportingOptions } from './Reporting'; type AsyncResult = Promise | T; type ShowLeaderboardOptions = { - onPlayAgain?: () => AsyncResult; + onPlayAgain?: (close: () => void) => AsyncResult; onBeforeLoad?: () => AsyncResult; withTopWidget?: boolean; onShowSignUp?: () => void; @@ -233,6 +233,15 @@ export class GamesSDK { await onStart?.(); modal.close(); }, + navigateLeaderBoardWidget: () => { + modal.close(); + this.showLeaderboard({ + onPlayAgain: async (close?: () => void) => { + await onStart?.(); + close?.(); + }, + }); + }, }); open(); @@ -252,6 +261,9 @@ export class GamesSDK { ]); this.ui.wallet.isNewUser = isNewUser; + if (this.ui.wallet.address) { + localStorage.setItem('userAddress', this.ui.wallet.address); + } await onConnect?.(accounts, isNewUser); @@ -319,7 +331,7 @@ export class GamesSDK { const { email } = await this.wallet.getUserInfo(); this.analytics.trackEvent(ANALYTICS_EVENTS.clickPlayAgain, { userEmail: email }); await this.payForSession(); - await onPlayAgain?.(); + await onPlayAgain?.(modal.close); } else { const { open } = this.showInsertCoin(); open(); diff --git a/packages/ui/src/widgets/Preloader/Preloader.tsx b/packages/ui/src/widgets/Preloader/Preloader.tsx index 9b702af9..12c01269 100644 --- a/packages/ui/src/widgets/Preloader/Preloader.tsx +++ b/packages/ui/src/widgets/Preloader/Preloader.tsx @@ -1,7 +1,7 @@ import styled from '@emotion/styled'; import { Button, ProgressiveImg, Stack, Typography, Steps } from '../../components'; -import { useAsyncCallback, useConfigContext, useGameInfo, useMediaQuery } from '../../hooks'; +import { useAsyncCallback, useConfigContext, useGameInfo, useMediaQuery, useWalletContext } from '../../hooks'; const ImageBlock = styled.div( { @@ -57,13 +57,19 @@ const StartButton = styled(Button)( export type PreloaderProps = { ready?: boolean; onStartClick?: () => Promise | void; + navigateLeaderBoardWidget?: () => void; }; -export const Preloader = ({ ready = false, onStartClick }: PreloaderProps) => { +export const Preloader = ({ ready = false, onStartClick, navigateLeaderBoardWidget }: PreloaderProps) => { const isLandscape = useMediaQuery('(max-height: 440px)'); const [handleStartClick, isBusy] = useAsyncCallback(onStartClick); const { loading, preloader } = useGameInfo(); const { sdkUrl: cdnUrl } = useConfigContext(); + const { address } = useWalletContext(); + + if (address || localStorage.getItem('userAddress')) { + navigateLeaderBoardWidget?.(); + } return (