Skip to content

Commit

Permalink
working on relative paths & saving to Ceramic 🧇
Browse files Browse the repository at this point in the history
  • Loading branch information
dysbulic committed Jul 25, 2024
1 parent ace7ab6 commit 18addfd
Show file tree
Hide file tree
Showing 32 changed files with 613 additions and 206 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"scripts": {
"pass": "echo ¡Passing‼️",
"update-schema": "env-cmd -x rover graph introspect http://localhost:8080/v1/graphql --header \"x-hasura-admin-secret:\\$HASURA_GRAPHQL_ADMIN_SECRET\" --output schema.graphql",
"docker:start": "docker-compose up -d",
"docker:build": "docker-compose up --build -d",
"docker:stop": "docker-compose down",
"docker:clean": "docker-compose down -v",
"docker:start": "docker compose up -d",
"docker:build": "docker compose up --build -d",
"docker:stop": "docker compose down",
"docker:clean": "docker compose down -v",
"docker:dev": "DOCKER_BUILDKIT=1 docker compose up --build",
"docker:debug": "docker compose --progress=plain up --build",
"build": "lerna run --concurrency 1 --stream build",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Maybe } from '@metafam/utils';
import Bottleneck from 'bottleneck';

import { updatePlayerFromComposeDB } from './updatePlayerFromComposeDB.js';
import { updatePlayerFromComposeDB } from '#handlers/actions/composeDB/updatePlayerFromComposeDB';

let count = 0;

Expand Down
5 changes: 2 additions & 3 deletions packages/backend/src/handlers/actions/composeDB/routes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import express from 'express';

import { asyncHandlerWrapper } from '#lib/apiHelpers';

import linkProfileNode from './linkProfileNode/handler.js';
import updateSingleProfileHandler from './updateSingleProfile/handler.js';
import linkProfileNode from '#handlers/actions/composeDB/linkProfileNode/handler';
import updateSingleProfileHandler from '#handlers/actions/composeDB/updateSingleProfile/handler';

export const routes = express.Router();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from 'express';

import { queueRecache } from '../cacheHelper.js';
import { queueRecache } from '#handlers/actions/composeDB/cacheHelper';

export default async (req: Request, res: Response): Promise<void> => {
const role = req.body.session_variables['x-hasura-role'];
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/handlers/actions/guild/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import express from 'express';

import { asyncHandlerWrapper } from '#lib/apiHelpers';

import { handleOAuthCallback } from './discord/oauthHandler.js';
import { saveGuildHandler } from './saveGuildHandler.js';
import { saveGuildLayoutHandler } from './saveGuildLayoutHandler.js';
import { handleOAuthCallback } from '#handlers/actions/guild/discord/oauthHandler';
import { saveGuildHandler } from '#handlers/actions/guild/saveGuildHandler';
import { saveGuildLayoutHandler } from '#handlers/actions/guild/saveGuildLayoutHandler';

export const guildRoutes = express.Router();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Request, Response } from 'express';
import {
Guild_Set_Input,
GuildLayoutInfoInput,
} from '../../../lib/autogen/hasura-sdk.js';
import { client } from '../../../lib/hasuraClient.js';
} from '#lib/autogen/hasura-sdk';
import { client } from '#lib/hasuraClient';

export const saveGuildLayoutHandler = async (
req: Request,
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/handlers/actions/guild/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
GuildFragment,
GuildStatus_Enum,
SyncGuildMembersMutation,
} from '../../../lib/autogen/hasura-sdk.js';
import { client } from '../../../lib/hasuraClient.js';
import { GuildRow, toGuild, TriggerPayload } from '../../triggers/types.js';
} from '#lib/autogen/hasura-sdk';
import { client } from '#lib/hasuraClient';
import { GuildRow, toGuild, TriggerPayload } from '#handlers/triggers/types';

export const syncDiscordGuildMembers = async (
payload: TriggerPayload<GuildRow>,
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/handlers/auth-webhook/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Request, Response } from 'express';
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'

import { getOrCreatePlayerId } from './users.js';
import { getOrCreatePlayerId } from '#handlers/auth-webhook/users';

const unauthorizedVariables = {
'X-Hasura-Role': 'public',
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/handlers/auth-webhook/users.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Bottleneck from 'bottleneck';

import { client } from '#lib/hasuraClient';

import { cacheProfile } from '../actions/composeDB/cacheHelper.js';
import { cacheProfile } from '#handlers/actions/composeDB/cacheHelper';

async function createPlayer(ethAddress: string, limiter: Bottleneck) {
const { insert_profile: insert } = await client.CreatePlayerFromETH({
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Bottleneck from 'bottleneck';
import cors from 'cors';
import express, { Express, RequestHandler } from 'express';

import { CONFIG } from './config.js';
import { router } from './handlers/routes.js';
import { errorMiddleware } from './lib/apiHelpers.js';
import { CONFIG } from '#config';
import { router } from '#handlers/routes';
import { errorMiddleware } from '#lib/apiHelpers';

const app: Express = express();

Expand Down
3 changes: 2 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@composedb/types": "^0.7.1",
"@types/uuid": "^10.0.0",
"key-did-provider-ed25519": "^2.0.1",
"key-did-resolver": "^2.1.3"
"key-did-resolver": "^2.1.3",
"typescript": "^5.5.3"
}
}
3 changes: 1 addition & 2 deletions packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"rootDir": "src/",
"outDir": "dist/",
"tsBuildInfoFile": "dist/.tsbuildinfo",
"composite": true
"tsBuildInfoFile": "dist/.tsbuildinfo"
},
"include": ["src/**/*", "src/**/*.json"]
}
39 changes: 5 additions & 34 deletions packages/web/components/ConnectedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,17 @@ import { useAccount } from 'wagmi';
import { Player } from '#graphql/autogen/hasura-sdk';
import { getPlayer } from '#graphql/getPlayer';
import { useMounted, useUser } from '#lib/hooks';
import { errorHandler } from '#utils/errorHandler';

type PlayerPageType = React.FC<{ player: Maybe<Player> }>;

export const ConnectedPage: React.FC<{
page: PlayerPageType;
label?: string;
}> = ({ page: Page, label = 'this page' }) => {
const { address, isConnected, isConnecting } = useAccount();
const [player, setPlayer] = useState<Maybe<Player>>(null);
const { user, fetching, error } = useUser();
const { isConnected, isConnecting } = useAccount();
const { user: player } = useUser()
const mounted = useMounted();

useEffect(() => {
if (!address) return;
function getPeople() {
if (address) {
return getPlayer(address);
}
throw new Error('No address');
}
getPeople().then(setPlayer);
}, [address]);

if (!mounted || (!isConnecting && !isConnected)) {
return (
<Flex textAlign="center" mt="25vh" align="center" justifyContent="center">
Expand All @@ -41,37 +28,21 @@ export const ConnectedPage: React.FC<{
);
}

if (isConnecting || fetching) {
if (isConnecting) {
return (
<Center h="100vh">
<Stack align="center">
<Text fontSize="xl">
{isConnecting ? 'Connecting…' : 'Fetching User…'}
</Text>
<Text fontSize="xl">Connecting…</Text>
<Spinner thickness="0.25rem" color="whiteAlpha" size="xl" />
</Stack>
</Center>
);
}

if (address && player) {
if (player) {
return <Page {...{ player }} />;
}

if (error) {
errorHandler(error);
return (
<Center h="100vh">
<Stack align="center">
<Text>
Error Loading User: <q>{error.message}</q>
</Text>
<ConnectKitButton />
</Stack>
</Center>
);
}

return (
<Text textAlign="center" mt="25vh">
Not sure how we got here… Something is decidedly amiss. Please{' '}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/EditProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export const EditProfileModal: React.FC<EditProfileModalProps> = ({
}
};

if (chainId !== '0xa') {
if (chainId !== 10) {
return (
<Modal {...{ isOpen, onClose }}>
<ModalOverlay />
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/EditableGridLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export const EditableGridLayout: React.FC<Props> = ({
borderRadius="lg"
transition="boxShadow 0.2s 0.3s ease"
id={key}
{...{ key }}
key={key}
>
{type === BoxTypes.ADD_NEW_BOX ? (
<AddBoxSection
Expand Down
9 changes: 6 additions & 3 deletions packages/web/components/MegaMenu/MegaMenuHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
getPlayerURL,
getPlayerUsername,
} from 'utils/playerHelpers';
import { useAccount } from 'wagmi';

import LogoImage from '#assets/new_logo_svg.svg';
import SearchIcon from '#assets/search-icon.svg';
Expand All @@ -62,6 +63,8 @@ import { useMounted, useUser, useWeb3 } from '#lib/hooks';
import { useProfileImageOnload } from '#lib/hooks/useProfileImageOnload';
import { menuIcons } from '#utils/menuIcons';
import { MenuSectionLinks } from '#utils/menuLinks';
import { authenticateWallet } from '#contexts/Web3Context';
import { useViemClients } from '#lib/hooks/useEthersProvider';

type LogoProps = {
link: string;
Expand Down Expand Up @@ -610,12 +613,12 @@ export const MegaMenuHeader: React.FC = () => {
w="15%"
>
<ConnectKitButton.Custom>
{({ isConnected, isConnecting, show }) =>
{({ isConnected, isConnecting, show }) => (
isConnected ? (
!!user ? (
<DesktopPlayerStats player={user} />
) : (
<Text>Missing User</Text>
<Button onClick={show}>Missing User Record</Button>
)
) : (
<Button
Expand All @@ -631,7 +634,7 @@ export const MegaMenuHeader: React.FC = () => {
Connect Wallet
</Button>
)
}
)}
</ConnectKitButton.Custom>
</Box>
</Flex>
Expand Down
15 changes: 7 additions & 8 deletions packages/web/components/Patron/PatronRank.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Props = {
pSeedPrice: Maybe<number>;
};

export const PatronRank: React.FC<Props> = ({ index, patron, pSeedPrice }) => {
export const PatronRank: React.FC<Props> = ({ index, patron, pSeedPrice: price }) => {
const player = patron as Player;

const patronRank = useMemo(
Expand All @@ -22,15 +22,14 @@ export const PatronRank: React.FC<Props> = ({ index, patron, pSeedPrice }) => {
);

const displayBalance = useMemo(() => {
const pSeedAmount = patron.pSeedBalance
console.debug({ pSeedAmount });
const pSeedBalance = `${Math.floor(pSeedAmount).toLocaleString()} pSEED`;
return pSeedPrice == null
? pSeedBalance
: `$${(pSeedAmount * pSeedPrice).toLocaleString(undefined, {
const { pSeedBalance: balance } = patron
const display = `${Math.floor(balance).toLocaleString()} pSEED`;
return price == null
? display
: `$${(balance * price).toLocaleString(undefined, {
maximumFractionDigits: 0,
})}`;
}, [patron, pSeedPrice]);
}, [patron, price]);

return (
<Flex
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Player/PlayerStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const PlayerStart: React.FC = () => {
}, [connected, user, fetching]);

const canRedirect = useMemo(
() => connected && !fetching && chainId === '0xa',
() => connected && !fetching && chainId === 10,
[connected, fetching, chainId],
);

Expand Down
20 changes: 13 additions & 7 deletions packages/web/components/Player/Profile/ComposeDBPromptModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useComputeComposeDBImageMetadata } from '#lib/hooks/ceramic/useComputeC
import { useSaveToComposeDB } from '#lib/hooks/ceramic/useSaveToComposeDB';
import { errorHandler } from '#utils/errorHandler';
import { hasuraToComposeDBProfile } from '#utils/playerHelpers';
import { useEthersProvider } from '#lib/hooks/useEthersProvider';

export type ComposeDBPromptModalProps = {
player: Player;
Expand All @@ -43,7 +44,10 @@ export const ComposeDBPromptModal: React.FC<ComposeDBPromptModalProps> = ({
onClose,
handleMigrationCompleted,
}) => {
const toast = useToast();
const toast = useToast({
isClosable: true,
duration: 12000,
});
const [status, setStatus] = useState(initialStatus);
const { chainId } = useWeb3();

Expand Down Expand Up @@ -83,8 +87,14 @@ export const ComposeDBPromptModal: React.FC<ComposeDBPromptModalProps> = ({
}
}, [saveStatus]);

const provider = useEthersProvider()
const onClick = useCallback(async () => {
if (!player.profile) {
toast({
title: 'ComposeDB Migration Failed',
description: `Your player record has no profile.`,
status: 'error',
});
return;
}
try {
Expand All @@ -98,20 +108,16 @@ export const ComposeDBPromptModal: React.FC<ComposeDBPromptModalProps> = ({
handleMigrationCompleted(streamID);
onClose();
toast({
title: 'ComposeDB migration complete',
title: 'ComposeDB Migration Complete',
description: `Your profile streamID is ${streamID}`,
status: 'success',
isClosable: true,
duration: 12000,
});
} catch (err) {
const heading = err instanceof CeramicError ? 'Ceramic Error' : 'Error';
toast({
title: heading,
description: (err as Error).message,
status: 'error',
isClosable: true,
duration: 12000,
});
errorHandler(err as Error);
setStatus(initialStatus);
Expand Down Expand Up @@ -201,7 +207,7 @@ export const ComposeDBPromptModal: React.FC<ComposeDBPromptModalProps> = ({
</Center>
</ModalBody>
<ModalFooter justifyContent="center">
{chainId === '0xa' ? (
{chainId === 10 ? (
<MetaButton disabled={!areImagesLoaded} {...{ onClick }}>
{status}
</MetaButton>
Expand Down
6 changes: 3 additions & 3 deletions packages/web/components/QuestChain/MintNFTTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const MintNFTTile: React.FC<MintNFTTileProps> = ({
const contract = useQuestChainContract(questChain.address);
const onMint = useCallback(async () => {
try {
if (!chainId || questChain.chainId !== chainId) {
throw new Error(`Wrong chain id: "${chainId}".`);
if (!chainId || Number(questChain.chainId) !== chainId) {
throw new Error(`Wrong chain id: "${chainId}" when wanting "${questChain.chainId}".`);
}
if (!address) {
throw new Error('No client address found.');
Expand Down Expand Up @@ -86,7 +86,7 @@ export const MintNFTTile: React.FC<MintNFTTileProps> = ({
duration: null,
});
await helpers.waitUntilSubgraphIndexed(
chainId,
`0x${chainId.toString(16)}`,
Number(receipt.blockNumber),
);
addToast({
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Setup/SetupHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const SetupHeader: React.FC = () => {
);

const { connected, chainId } = useWeb3();
if (!connected || chainId !== '0xa') return null;
if (!connected || chainId !== 10) return null;

return (
<Grid templateColumns={templateColumns.join(' ')} gap={[1, 4]} w="full">
Expand Down
Loading

0 comments on commit 18addfd

Please sign in to comment.