mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
* incorporating configuration panes from #1078 * standardizing player hero subcomponents & removing `owner` var from `useProfileField` 🚪 * switching box type, ambiguating overly-specific names, & massaging heights 📱 * reordering profile details sections, updating deployment environment, & conditionally wrapping the hero elements 🎬 * fixing render of color disposition selector 🕍 * self code review changes: removed some `;`s 🎋 * getting yarn typecheck && yarn lint to pass post rebase 🏇🏾 * handling "missing <div> in <button>" error with mounted check & setting HTTP return codes for OpenSea API endpoint 🕺 * `ProfileWizard` extends `Wizard`, roles display better on mobile, & pronouns use `ProfileWizardPane` 🍊 * properly encapsulating ETH address regex 🚲 * adding some tasks 🏥 * fixed skills layou * handling default values? ❔ * corrections for revision comments from @dan13ram (UI bugs to follow) 🌋 * cleaning up memberships & explorer type 🧫 * refactoring player roles configuration and display to use `WizardPane` 🔮 * bunches of mobile fixes & repairing the display of deserialized skills 📟 * removing redirect in static props & formatting memberships display for responsiveness 🪆 * improving comprehensability of `/me` & more mobile tweaking 🍦 * various spacing fixes & a “try again” button for connecting 🫕 * maybe fixed issue with saving images for fields with default values 🇩🇿 * switched roles selection to a bounded `SimpleGrid` to fix sizing weirdness 🧰 * fix: removed verify on brightId button * fix: clean up username page * formatting & fixing skills issues 🥩 * reformatting NFT display 🚂 * adding `/join` 🚉 * style: peth's suggestions * added mainnet required message * style: slight tweak of megamenu item positions * chore(release): 0.2.0 Co-authored-by: tenfinney <scott@1box.onmicrosoft.com> Co-authored-by: dan13ram <dan13ram@gmail.com> Co-authored-by: vidvidvid <weetopol@gmail.com>
92 lines
2.4 KiB
TypeScript
92 lines
2.4 KiB
TypeScript
import { Optional } from '@metafam/utils';
|
|
import { CONFIG } from 'config';
|
|
import { Player } from 'graphql/autogen/types';
|
|
import { useEffect, useMemo } from 'react';
|
|
|
|
const BRIGHTID_CONTEXT = 'MetaGame';
|
|
const DEEPLINK_ENDPOINT = `brightid://link-verification/${CONFIG.brightIdNodeURL}/${BRIGHTID_CONTEXT}`;
|
|
const UNIVERSAL_LINK_ENDPOINT = `${CONFIG.brightIdAppURL}/link-verification/${CONFIG.brightIdNodeURL}/${CONFIG.brightIdNodeURL}/${BRIGHTID_CONTEXT}`;
|
|
const VERIFICATION_ENDPOINT = `${CONFIG.brightIdAppURL}/node/v5/verifications/${BRIGHTID_CONTEXT}`;
|
|
const POLL_INTERVAL = 5000;
|
|
|
|
type BrightIdVerificationStatus =
|
|
| {
|
|
unique: boolean;
|
|
app?: string;
|
|
context?: string;
|
|
contextIds: Array<string>;
|
|
}
|
|
| null
|
|
| undefined;
|
|
|
|
const isStatusVerified = (
|
|
status: BrightIdVerificationStatus,
|
|
contextId: string,
|
|
): boolean =>
|
|
status?.unique === true || status?.contextIds.includes(contextId) === true;
|
|
|
|
export const useBrightIdStatus = ({
|
|
player,
|
|
}: {
|
|
player?: Player;
|
|
}): Optional<{
|
|
verified: boolean;
|
|
deeplink: string;
|
|
universalLink: string;
|
|
}> =>
|
|
useMemo(() => {
|
|
if (player) {
|
|
const contextId = player.id;
|
|
const verified = isStatusVerified(player.brightid_status, contextId);
|
|
const deeplink = `${DEEPLINK_ENDPOINT}/${contextId}`;
|
|
const universalLink = `${UNIVERSAL_LINK_ENDPOINT}/${contextId}`;
|
|
return { verified, deeplink, universalLink };
|
|
}
|
|
return undefined;
|
|
}, [player]);
|
|
|
|
const fetchVerificationData = async (
|
|
contextId: string,
|
|
): Promise<BrightIdVerificationStatus> => {
|
|
try {
|
|
const response = await fetch(`${VERIFICATION_ENDPOINT}/${contextId}`);
|
|
if (!response.ok) return null;
|
|
const responseData = await response.json();
|
|
return responseData.data;
|
|
} catch (err) {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
export const useBrightIdUpdated = ({
|
|
player,
|
|
poll,
|
|
}: {
|
|
player: Player;
|
|
poll: boolean;
|
|
}): void => {
|
|
const contextId = player?.id;
|
|
|
|
useEffect(() => {
|
|
if (!contextId || !poll) return () => undefined;
|
|
|
|
let isSubscribed = true;
|
|
|
|
const update = () => {
|
|
fetchVerificationData(contextId).then((status) => {
|
|
const isVerified = isStatusVerified(status, contextId);
|
|
if (isSubscribed && isVerified) {
|
|
window.location.reload();
|
|
}
|
|
});
|
|
};
|
|
|
|
const interval = setInterval(update, POLL_INTERVAL);
|
|
|
|
return () => {
|
|
isSubscribed = false;
|
|
clearInterval(interval);
|
|
};
|
|
}, [contextId, poll]);
|
|
};
|