|
| 1 | +import React, { useCallback } from 'react' |
| 2 | +import { |
| 3 | + QuestDetailsWrapper, |
| 4 | + claimedRewardToastState, |
| 5 | + useGetUserPlayStreak |
| 6 | +} from '@hyperplay/quests-ui' |
| 7 | +import { Reward, Quest } from '@hyperplay/utils' |
| 8 | +import useAuthSession from 'frontend/hooks/useAuthSession' |
| 9 | +import authState from 'frontend/state/authState' |
| 10 | +import { useFlags } from 'launchdarkly-react-client-sdk' |
| 11 | +import { useTranslation } from 'react-i18next' |
| 12 | +import { useAccount } from 'wagmi' |
| 13 | +import { useSyncPlayStreakWithExternalSource } from 'frontend/hooks/useSyncPlayStreakWithExternalSource' |
| 14 | +import extensionState from 'frontend/state/ExtensionState' |
| 15 | + |
| 16 | +/** |
| 17 | + * Don't delete this comment block since it's used for translation parsing for keys that are on the quests-ui library. |
| 18 | + * As a heads up, everytime you add a new key on any library, you need to add it as a block comment anywhere in the code as well. |
| 19 | + * |
| 20 | + * t("quest.noG7ConnectionClaim", "You need to have a Game7 account linked to {{email}} to claim your rewards.") |
| 21 | + * t("quest.noG7ConnectionSync", "You need to have a Game7 account linked to {{email}} to resync your tasks.") |
| 22 | + * t("quest.notEnoughGas", "Insufficient wallet balance to claim your reward due to gas fees. Try a different wallet or replenish this one before retrying.") |
| 23 | + * t("quest.playstreak.syncSuccess", "Progress synced") |
| 24 | + * t("quest.claim", "Claim") |
| 25 | + * t('quest.notSignedIn.title', 'Not signed in') |
| 26 | + * t('quest.notSignedIn.message', 'You need to be signed in to claim your reward.') |
| 27 | + * t('quest.notEligible.title', 'Not eligible yet') |
| 28 | + * t('quest.notEligible.message', 'You have not completed the required play streak days and can not claim your reward at this time.') |
| 29 | + * t('quest.playstreak.sync', 'Sync Progress') |
| 30 | + * t('quest.noG7ConnectionSync.title', 'No G7 account linked') |
| 31 | + * t('quest.noG7ConnectionSync.message', 'You need to have a Game7 account linked to {{email}} to claim your rewards.') |
| 32 | + * t('quest.notEnoughBalance.title', 'Low balance') |
| 33 | + * t('quest.notEnoughGas.message', 'Insufficient wallet balance to claim your reward due to gas fees. Try a different wallet or replenish this one before retrying.') |
| 34 | + * t('quest.claimFailed', 'Claim failed') |
| 35 | + * t('quest.claimFailedMessage', 'Please try once more. If it still doesn\'t work, create a Discord support ticket.') |
| 36 | + * t('quest.createDiscordTicket', 'Create Discord Ticket') |
| 37 | + * t('quest.reward', 'Rewards') |
| 38 | + * t('quest.associatedGames', 'Associated games') |
| 39 | + * t('quest.linkAccount', 'Link your Steam account to check eligibility.') |
| 40 | + * t('quest.needMoreAchievements', 'You need to have completed {{percent}}% of the achievements in one of these games.') |
| 41 | + * t('quest.claim', 'Claim') |
| 42 | + * t('quest.signIn', 'Sign in') |
| 43 | + * t('quest.connectSteamAccount', 'Connect Steam account') |
| 44 | + * t('quest.type.reputation', 'Reputation') |
| 45 | + * t('quest.type.playstreak', 'Play Streak') |
| 46 | + * t('quest.sync', 'Sync') |
| 47 | + * t('quest.playstreak.streakProgress', 'Streak Progress') |
| 48 | + * t('quest.playstreak.days', 'days') |
| 49 | + * t('quest.playstreak.playToStart', 'Play this game to start your streak!') |
| 50 | + * t('quest.playstreak.playEachDay', 'Play each day so your streak won\'t reset!') |
| 51 | + * t('quest.playstreak.streakCompleted', 'Streak completed! Claim your rewards now.') |
| 52 | + * t('quest.playstreak.now', 'Now') |
| 53 | + * t('quest.playstreak.dayResets', 'Day resets:') |
| 54 | + * t('quest.playstreak.progressTowardsStreak', 'progress towards today\'s streak.') |
| 55 | + * t('quest.points', 'Points') |
| 56 | + * t('quest.claimWarning.body', '<bold>IMPORTANT:</bold> Please ensure that you are allocating enough gas on the {{networkName}} network for the transaction to be successfully confirmed <bold>within 7 days.</bold>') |
| 57 | + * t('quest.claimWarning.body2', 'Otherwise, the Quest Reward <bold>will expire and will no longer be claimable.</bold>') |
| 58 | + * t('quest.claimWarning.cancel', 'Cancel') |
| 59 | + * t('quest.claimWarning.confirm', 'Confirm') |
| 60 | + */ |
| 61 | + |
| 62 | +export default function QuestDetails({ |
| 63 | + questId, |
| 64 | + className, |
| 65 | + isQuestsPage, |
| 66 | + onPlayClick |
| 67 | +}: { |
| 68 | + questId: number | null |
| 69 | + className?: string |
| 70 | + isQuestsPage?: boolean |
| 71 | + onPlayClick?: (quest: Quest) => void |
| 72 | +}) { |
| 73 | + const { address } = useAccount() |
| 74 | + const { isSignedIn, data } = useAuthSession() |
| 75 | + const { t } = useTranslation() |
| 76 | + const flags = useFlags() |
| 77 | + const sessionEmail = data?.linkedAccounts.get('email') |
| 78 | + const { invalidateQuery } = useGetUserPlayStreak( |
| 79 | + questId, |
| 80 | + window.api.getUserPlayStreak |
| 81 | + ) |
| 82 | + |
| 83 | + const getPendingExternalSync = useCallback(async () => { |
| 84 | + if (!address || !questId || !isSignedIn) return false |
| 85 | + return window.api.checkPendingSync({ |
| 86 | + questId, |
| 87 | + wallet: address |
| 88 | + }) |
| 89 | + }, [address, questId, isSignedIn]) |
| 90 | + |
| 91 | + const { syncPlayStreakWithExternalSource } = |
| 92 | + useSyncPlayStreakWithExternalSource({ |
| 93 | + refreshPlayStreak: invalidateQuery |
| 94 | + }) |
| 95 | + |
| 96 | + return ( |
| 97 | + <QuestDetailsWrapper |
| 98 | + // @ts-expect-error - see: https://github.com/qmhc/vite-plugin-dts/issues/330 |
| 99 | + onRewardClaimed={(reward) => |
| 100 | + claimedRewardToastState.showClaimedReward(reward) |
| 101 | + } |
| 102 | + onShowMetaMaskPopup={async () => { |
| 103 | + const currentProvider = await window.api.getConnectedProvider() |
| 104 | + if (currentProvider === 'MetaMaskExtension') { |
| 105 | + extensionState.showPopup() |
| 106 | + } |
| 107 | + }} |
| 108 | + onPlayClick={onPlayClick} |
| 109 | + getPendingExternalSync={getPendingExternalSync} |
| 110 | + syncPlayStreakWithExternalSource={syncPlayStreakWithExternalSource} |
| 111 | + tOverride={t} |
| 112 | + sessionEmail={sessionEmail} |
| 113 | + className={className} |
| 114 | + checkG7ConnectionStatus={window.api.checkG7ConnectionStatus} |
| 115 | + logInfo={window.api.logInfo} |
| 116 | + logError={window.api.logError} |
| 117 | + flags={{ |
| 118 | + rewardTypeClaimEnabled: { |
| 119 | + ERC20: flags.erc20RewardsClaim, |
| 120 | + ERC721: flags.erc721RewardsClaim, |
| 121 | + ERC1155: flags.erc1155RewardsClaim, |
| 122 | + POINTS: flags.pointsRewardsClaim, |
| 123 | + 'EXTERNAL-TASKS': flags.externalTasksRewardsClaim |
| 124 | + }, |
| 125 | + questsOverlayClaimCtaEnabled: flags.questsOverlayClaimCtaEnabled |
| 126 | + }} |
| 127 | + trackEvent={window.api.trackEvent} |
| 128 | + signInWithSteamAccount={() => window.api.signInWithProvider('steam')} |
| 129 | + openDiscordLink={window.api.openDiscordLink} |
| 130 | + selectedQuestId={questId} |
| 131 | + getQuest={window.api.getQuest} |
| 132 | + getUserPlayStreak={window.api.getUserPlayStreak} |
| 133 | + getSteamGameMetadata={window.api.getSteamGameMetadata} |
| 134 | + claimPoints={async (reward: Reward) => |
| 135 | + window.api.claimQuestPointsReward(reward.id.toString()) |
| 136 | + } |
| 137 | + completeExternalTask={async (reward: Reward) => |
| 138 | + window.api.completeExternalTask(reward.id.toString()) |
| 139 | + } |
| 140 | + getQuestRewardSignature={window.api.getQuestRewardSignature} |
| 141 | + confirmRewardClaim={window.api.confirmRewardClaim} |
| 142 | + getExternalTaskCredits={window.api.getExternalTaskCredits} |
| 143 | + syncPlaySession={window.api.syncPlaySession} |
| 144 | + getDepositContracts={window.api.getDepositContracts} |
| 145 | + openSignInModal={authState.openSignInModal} |
| 146 | + resyncExternalTask={async (rewardId: string) => { |
| 147 | + window.api.resyncExternalTask(rewardId) |
| 148 | + }} |
| 149 | + isSignedIn={isSignedIn} |
| 150 | + isQuestsPage={isQuestsPage} |
| 151 | + key={'questDetailsLoading'} |
| 152 | + /> |
| 153 | + ) |
| 154 | +} |
0 commit comments