Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dysbulic committed Jun 11, 2024
2 parents 62a1f89 + ac005d1 commit c433442
Show file tree
Hide file tree
Showing 31 changed files with 145 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gcp-deploy-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

steps:
- name: Cancel Existing Runs
uses: styfle/cancel-workflow-action@0.10.0
uses: styfle/cancel-workflow-action@0.12.0
with:
access_token: ${{github.token}}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gcp-deploy-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

steps:
- name: Cancel Existing Runs
uses: styfle/cancel-workflow-action@0.10.0
uses: styfle/cancel-workflow-action@0.12.0
with:
access_token: ${{github.token}}

Expand Down
2 changes: 2 additions & 0 deletions docker/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ARG GCAL_CALENDAR_ID
ARG GCAL_PRIVATE_KEY
ARG GCAL_CLIENT_EMAIL
ARG GCAL_PROJECT_NUMBER
ARG ALCHEMY_API_KEY
ARG WEB3_STORAGE_DID
ARG WEB3_STORAGE_KEY
ARG WEB3_STORAGE_PROOF
Expand All @@ -72,6 +73,7 @@ ENV NEXT_PUBLIC_GOOGLE_ANALYTICS_ID $GOOGLE_ANALYTICS_ID
ENV NEXT_PUBLIC_USERBACK_TOKEN $USERBACK_TOKEN
ENV NEXT_PUBLIC_CERAMIC_URL $CERAMIC_URL
ENV NEXT_PUBLIC_GCAL_CALENDAR_ID $GCAL_CALENDAR_ID
ENV NEXT_PUBLIC_ALCHEMY_API_KEY $ALCHEMY_API_KEY
ENV NEXT_PUBLIC_WEB3_STORAGE_DID $WEB3_STORAGE_DID
ENV NEXT_PUBLIC_WEB3_STORAGE_KEY $WEB3_STORAGE_KEY
ENV NEXT_PUBLIC_WEB3_STORAGE_PROOF $WEB3_STORAGE_PROOF
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"cors": "2.8.5",
"discord.js": "13.6.0",
"dotenv": "16.0.0",
"ethers": "^6.11.1",
"ethers": "5.7.2",
"express": "^4.18.2",
"express-graphql": "0.12.0",
"graphql": "16.5.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/handlers/actions/player/syncBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const setBalances = async ({
uniqueDrops[executionDate] ??= {};
uniqueDrops[executionDate][to] ??= 0;
if (tokenAddress === guildTokenAddress) {
uniqueDrops[executionDate][to] += Number(ethers.formatEther(value));
uniqueDrops[executionDate][to] += Number(
ethers.utils.formatEther(value),
);
}
});
});
Expand Down
6 changes: 5 additions & 1 deletion packages/backend/src/handlers/auth-webhook/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { did, Maybe } from '@metafam/utils';
import { ethers } from 'ethers';
import { Request, Response } from 'express';

import { mainnetProvider } from '../../lib/ethereum.js';
Expand Down Expand Up @@ -30,7 +31,10 @@ export const authHandler = async (
res.json(unauthorizedVariables);
return;
}
const claim = await did.verifyToken(token, mainnetProvider);
const claim = await did.verifyToken(
token,
mainnetProvider as unknown as ethers.providers.Web3Provider,
);
if (!claim) {
throw new Error('Invalid token');
}
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/lib/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import ERC20_ABI from './abis/ERC20.json' assert { type: 'json' };

const { infuraId } = CONFIG;

export const mainnetProvider = new ethers.InfuraProvider(1, infuraId);
export const polygonProvider = new ethers.InfuraProvider(137, infuraId);
export const mainnetProvider = new ethers.providers.InfuraProvider(1, infuraId);
export const polygonProvider = new ethers.providers.InfuraProvider(
137,
infuraId,
);

export const getERC20Contract = (
contractAddress: string,
provider: ethers.Provider = mainnetProvider,
provider: ethers.providers.Provider = mainnetProvider,
): ethers.Contract => new ethers.Contract(contractAddress, ERC20_ABI, provider);
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@datamodels/identity-profile-basic": "^0.2.0",
"bignumber.js": "^9.1.0",
"cids": "^1.1.9",
"ethers": "^6.11.1",
"ethers": "5.7.2",
"imgix-core-js": "2.3.2",
"js-base64": "3.7.2",
"node-fetch": "3.2.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/did/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserProvider, Provider } from 'ethers';
import { ethers } from 'ethers';
import { Base64 } from 'js-base64';
import { v4 as uuidv4 } from 'uuid';

Expand All @@ -18,7 +18,7 @@ type Claim = {
};

export async function createToken(
provider: BrowserProvider,
provider: ethers.providers.Web3Provider,
userAddress: string,
): Promise<string> {
const iat = +new Date();
Expand All @@ -40,7 +40,7 @@ export async function createToken(

export async function verifyToken(
token: string,
provider: Provider,
provider: ethers.providers.Web3Provider,
connectedAddress?: string,
): Promise<Maybe<Claim>> {
const rawToken = Base64.decode(token);
Expand Down
20 changes: 10 additions & 10 deletions packages/utils/src/ethereumHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BrowserProvider, Contract, ethers, Provider } from 'ethers';
import { Contract, ethers } from 'ethers';

export async function getSignature(
provider: BrowserProvider,
provider: ethers.providers.Web3Provider,
msg: string,
): Promise<string> {
const signer = await provider.getSigner();
Expand All @@ -19,7 +19,7 @@ enum WalletType {

async function getWalletType(
address: string,
provider: Provider,
provider: ethers.providers.Web3Provider,
): Promise<WalletType> {
const code = await new Promise((resolve, reject) => {
const seconds = 45;
Expand All @@ -44,24 +44,24 @@ export async function verifySignature(
address: string,
message: string,
signature: string,
provider: Provider,
provider: ethers.providers.Web3Provider,
): Promise<boolean> {
const walletType = await getWalletType(address, provider);

if (walletType === WalletType.EOA) {
const recoveredAddress = ethers.verifyMessage(message, signature);
const recoveredAddress = ethers.utils.verifyMessage(message, signature);
return address === recoveredAddress;
}

// Smart wallet
const msgBytes = ethers.toUtf8Bytes(message);
const hexMsg = ethers.hexlify(msgBytes);
const hexArray = ethers.getBytes(hexMsg);
const hashMsg = ethers.hashMessage(hexArray);
const msgBytes = ethers.utils.toUtf8Bytes(message);
const hexMsg = ethers.utils.hexlify(msgBytes);
const hexArray = ethers.utils.arrayify(hexMsg);
const hashMsg = ethers.utils.hashMessage(hexArray);

const contract = new Contract(address, smartWalletABI, provider);
try {
return await contract.isValidSignature(hashMsg, signature);
return contract.isValidSignature(hashMsg, signature);
} catch (error) {
throw new Error(`Unsupported Smart Wallet: ${(error as Error).message}`);
}
Expand Down
Binary file modified packages/web/assets/academy/submit-playbook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/web/assets/academy/submit-playbook.webp
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/web/components/Guild/GuildForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SelectOption } from '@metafam/ds/src/MultiSelect';
import FileOpenIcon from 'assets/file-open-icon.svg';
import { Field, FieldDescription } from 'components/Forms/Field';
import { MetaLink } from 'components/Link';
import { isAddress } from 'ethers';
import { ethers } from 'ethers';
import {
DiscordRole,
GuildDaoInput,
Expand Down Expand Up @@ -59,7 +59,7 @@ const validations = {
},
daoAddress: {
required: true,
validate: (address: string) => isAddress(address),
validate: (address: string) => ethers.utils.isAddress(address),
},
daoNetwork: {
required: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/Guild/UnverifiedGuildForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@metafam/ds';
import FileOpenIcon from 'assets/file-open-icon.svg';
import { Field, FieldDescription } from 'components/Forms/Field';
import { isAddress } from 'ethers';
import { ethers } from 'ethers';
import {
AddUnverifiedGuildMutation,
AddUnverifiedGuildMutationVariables,
Expand Down Expand Up @@ -54,7 +54,7 @@ const validations = {
},
daoAddress: {
required: true,
validate: (address: string) => isAddress(address),
validate: (address: string) => ethers.utils.isAddress(address),
},
daoNetwork: {
required: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Patron/PatronRank.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const PatronRank: React.FC<Props> = ({ index, patron, pSeedPrice }) => {

const displayBalance = useMemo(() => {
const pSeedAmount = parseFloat(
ethers.formatUnits(patron.pSeedBalance, Constants.PSEED_DECIMALS),
ethers.utils.formatUnits(patron.pSeedBalance, Constants.PSEED_DECIMALS),
);
const pSeedBalance = `${Math.floor(pSeedAmount).toLocaleString()} pSEED`;
return pSeedPrice == null
Expand Down
6 changes: 3 additions & 3 deletions packages/web/components/Player/PlayerSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { FaTimes } from 'react-icons/fa';
import { BoxMetadata, BoxType, BoxTypes, createBoxKey } from 'utils/boxTypes';

import { PlayerDework } from './Section/PlayerDework';
import { PlayerEAS } from './Section/PlayerEAS';
// import { PlayerEAS } from './Section/PlayerEAS';
import { PlayerLinks } from './Section/PlayerLinks';

type Props = {
Expand Down Expand Up @@ -59,8 +59,8 @@ const PlayerSectionInner: React.FC<
return <PlayerAchievements {...{ player, isOwnProfile, editing }} />;
case BoxTypes.PLAYER_COMPLETED_QUESTS:
return <PlayerCompletedQuests {...{ player, isOwnProfile, editing }} />;
case BoxTypes.PLAYER_ATTESTATIONS:
return <PlayerEAS {...{ player, isOwnProfile, editing }} />
// case BoxTypes.PLAYER_ATTESTATIONS:
// return <PlayerEAS {...{ player, isOwnProfile, editing }} />
case BoxTypes.EMBEDDED_URL: {
const { url } = metadata ?? {};
return url ? <EmbeddedUrl {...{ url, editing }} /> : null;
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/QuestChain/UploadProof.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export const UploadProof: React.FC<{
}
onSubmit();
}}
{...{ status: isSubmitting ? 'Submitting...' : null }}
{...{ status: isSubmitting ? 'Submitting' : null }}
/>
)}
</Stack>
Expand Down
39 changes: 21 additions & 18 deletions packages/web/contexts/ComposeDBContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EthereumWebAuth, getAccountId } from '@didtools/pkh-ethereum';
import { composeDBDefinition, Maybe } from '@metafam/utils';
import { CONFIG } from 'config';
import { DIDSession } from 'did-session';
import { BrowserProvider } from 'ethers';
import { ethers } from 'ethers';
import { cacheDIDSession, getCachedDIDSession } from 'lib/auth';
import { CeramicError } from 'lib/errors';
import { useWeb3 } from 'lib/hooks/useWeb3';
Expand Down Expand Up @@ -45,24 +45,27 @@ export const ComposeDBContextProvider: React.FC<PropsWithChildren> = ({
setAuthenticated(false);
}, []);

const createSession = useCallback(async (prov: BrowserProvider) => {
const addr = await (await prov.getSigner()).getAddress();
const createSession = useCallback(
async (prov: ethers.providers.Web3Provider) => {
const addr = await (await prov.getSigner()).getAddress();

// use did:pkh
let session = await getCachedDIDSession();
if (!session || (session.hasSession && session.isExpired)) {
const accountId = await getAccountId(prov.provider, addr.toLowerCase());
const authMethod = await EthereumWebAuth.getAuthMethod(
prov.provider,
accountId,
);
session = await DIDSession.authorize(authMethod, {
resources: composeDBClient.resources,
});
cacheDIDSession(session);
}
composeDBClient?.setDID(session.did);
}, []);
// use did:pkh
let session = await getCachedDIDSession();
if (!session || (session.hasSession && session.isExpired)) {
const accountId = await getAccountId(prov.provider, addr.toLowerCase());
const authMethod = await EthereumWebAuth.getAuthMethod(
prov.provider,
accountId,
);
session = await DIDSession.authorize(authMethod, {
resources: composeDBClient.resources,
});
cacheDIDSession(session);
}
composeDBClient?.setDID(session.did);
},
[],
);

const connect = useCallback(async () => {
if (provider == null || connecting) return;
Expand Down
14 changes: 7 additions & 7 deletions packages/web/contexts/Web3Context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { did, Maybe } from '@metafam/utils';
import { Client as W3SClient } from '@web3-storage/w3up-client';
import { BrowserProvider, JsonRpcProvider } from 'ethers';
import { ethers } from 'ethers';
import {
clearDIDSessionCache,
clearToken,
Expand All @@ -22,15 +22,15 @@ import { errorHandler } from 'utils/errorHandler';
import { useAccount, useDisconnect } from 'wagmi';

export type Web3ContextType = {
provider: Maybe<BrowserProvider>;
provider: Maybe<ethers.providers.Web3Provider>;
address: Maybe<string>;
chainId: Maybe<string>;
authToken: Maybe<string>;
disconnect: () => void;
connecting: boolean;
connected: boolean;
w3storage: Maybe<W3SClient>;
updateWeb3State: (prov: BrowserProvider) => Promise<void>;
updateWeb3State: (prov: ethers.providers.Web3Provider) => Promise<void>;
};

export const Web3Context = createContext<Web3ContextType>({
Expand All @@ -46,7 +46,7 @@ export const Web3Context = createContext<Web3ContextType>({
});

export async function getExistingAuth(
ethersProvider: BrowserProvider,
ethersProvider: ethers.providers.Web3Provider,
connectedAddress: string,
): Promise<Maybe<string>> {
const token = getTokenFromStore();
Expand All @@ -63,7 +63,7 @@ export async function getExistingAuth(
}

export async function authenticateWallet(
ethersProvider: BrowserProvider,
ethersProvider: ethers.providers.Web3Provider,
addr: string,
): Promise<string> {
const token = await did.createToken(ethersProvider, addr);
Expand All @@ -76,7 +76,7 @@ type Web3ContextProviderOptions = PropsWithChildren<{
}>;

type Web3State = {
provider: Maybe<BrowserProvider>;
provider: Maybe<ethers.providers.Web3Provider>;
address: Maybe<string>;
chainId: Maybe<string>;
authToken: Maybe<string>;
Expand Down Expand Up @@ -125,7 +125,7 @@ export const Web3ContextProvider: React.FC<Web3ContextProviderOptions> = ({
}, [resetUrqlClient, disconnectWagmi]);

const updateWeb3State = useCallback(
async (web3Provider: BrowserProvider) => {
async (web3Provider: ethers.providers.Web3Provider) => {
const network = chain?.id;
if (!web3Provider || !userAddress || !network) return;
let token = await getExistingAuth(web3Provider, userAddress);
Expand Down
Loading

0 comments on commit c433442

Please sign in to comment.