Skip to content

Commit

Permalink
Revert ethers scroll updates (#2651)
Browse files Browse the repository at this point in the history
* Revert "feat: adding debug statements for review (#2643)"

This reverts commit dbf7b72.

* Revert "2614 scroll endpoints (#2624)"

This reverts commit 5451968.
  • Loading branch information
digitalmnt committed Jun 28, 2024
1 parent dbf7b72 commit 5a6aba0
Show file tree
Hide file tree
Showing 46 changed files with 9,481 additions and 6,468 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.9.0
node-version: 20.8.1
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.9.0
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/iam-cd-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.9.0
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/iam-promote-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.9.0
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.9.0
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/iam-promote-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.9.0
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.9.0
node-version: 20.8
cache: "yarn"
- name: Install Packages
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.9.0
node-version: 20
cache: "yarn"

- name: Install Packages
Expand Down
2 changes: 0 additions & 2 deletions app/__tests__/components/SyncToChainButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ const mockGetSigner = jest.fn().mockImplementation(() => {

// Mock the ethers.BrowserProvider class
jest.mock("ethers", () => {
const ethers = jest.requireActual<typeof import("ethers")>("ethers");
return {
...ethers,
ethers: {
BrowserProvider: jest.fn().mockImplementation(() => {
return { getSigner: mockGetSigner };
Expand Down
26 changes: 7 additions & 19 deletions app/context/datastoreConnectionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import { createContext, useContext, useEffect, useState, useMemo, useCallback }
import { datadogRum } from "@datadog/browser-rum";
import { useWalletStore } from "./walletStore";
import { DoneToastContent } from "../components/DoneToastContent";
import { EthereumWebAuth } from "@didtools/pkh-ethereum";
import { EthereumAuthProvider } from "@self.id/web";
import { EthereumWebAuth, getAccountId } from "@didtools/pkh-ethereum";
import { ComposeClient } from "@composedb/client";
import { DIDSession } from "did-session";
import { DID } from "dids";
import axios from "axios";
import { AccountId } from "caip";
import { MAX_VALID_DID_SESSION_AGE } from "@gitcoin/passport-identity";

import { CERAMIC_CACHE_ENDPOINT } from "../config/stamp_config";
import { useToast } from "@chakra-ui/react";
import { Eip1193Provider } from "ethers";
import { createSignedPayload } from "../utils/helpers";
import { ComposeDatabase } from "@gitcoin/passport-database-client";
import { datadogLogs } from "@datadog/browser-logs";
import { AuthMethod } from "@didtools/cacao";

const BUFFER_TIME_BEFORE_EXPIRATION = 60 * 60 * 1000;

Expand Down Expand Up @@ -130,19 +133,15 @@ export const useDatastoreConnection = () => {
let dbCacheTokenKey = "";

try {
console.log("debug - 1")
const accountId = new AccountId({
// We always use chain id 1 for now for all sessions, to avoid users
// switching networks and not see their stamps any more
chainId: "eip155:1",
address,
});
console.log("debug - 2")
// Unfortunate workaround due to dependency issues
const authMethod = (await EthereumWebAuth.getAuthMethod(provider, accountId)) as any;
const authMethod = await EthereumWebAuth.getAuthMethod(provider, accountId);
// Sessions will be serialized and stored in localhost
// The sessions are bound to an ETH address, this is why we use the address in the session key
console.log("debug - 3")
sessionKey = `didsession-${address}`;
dbCacheTokenKey = `dbcache-token-${address}`;
// const sessionStr = window.localStorage.getItem(sessionKey);
Expand Down Expand Up @@ -171,42 +170,31 @@ export const useDatastoreConnection = () => {
// // window.localStorage.setItem(sessionKey, session.serialize());
// }

console.log("debug - 4")

// Extensions which inject the Buffer library break the
// did-session library, so we need to remove it
if (globalThis.Buffer) {
console.log("debug - 5")
datadogLogs.logger.warn("Buffer library is injected, setting to undefined", {
buffer: `${globalThis.Buffer}`,
});
globalThis.Buffer = undefined as any;
console.log("debug - 6")
console.log(
"Warning: Buffer library is injected! This will be overwritten in order to avoid conflicts with did-session."
);
} else {
console.log("Buffer library is not injected` (this is good)");
console.log("Buffer library is not injected (this is good)");
}
console.log("debug - 7")
let session: DIDSession = await DIDSession.get(accountId, authMethod, { resources: ["ceramic://*"] });
console.log("debug - 8")

if (session) {
console.log("debug - 9")
await loadDbAccessToken(address, session.did);
console.log("debug - 10")
setDid(session.did);
console.log("debug - 11")

// session.isExpired looks like a static variable so this looks like a bug,
// but isExpired is a getter, so it's actually checking the current status
// whenever checkSessionIsValid is called
setCheckSessionIsValid(() => () => !session.isExpired);
console.log("debug - 12")
}
} catch (error) {
console.error("debug - 1", error)
await handleConnectionError(sessionKey, dbCacheTokenKey);
toast({
duration: 6000,
Expand Down
2 changes: 1 addition & 1 deletion app/context/walletStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { onboard } from "../utils/onboard";

// --- Utils & configs
import { create } from "zustand";
import { WalletState } from "@web3-onboard/core";
import { WalletState } from "@web3-onboard/core/dist/types";
import { Eip1193Provider } from "ethers";

const getPreviouslyUsedWalletLabel = () => window.localStorage.getItem("previouslyUsedWalletLabel") || "";
Expand Down
14 changes: 5 additions & 9 deletions app/hooks/useOnChainData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { PROVIDER_ID } from "@gitcoin/passport-types";
import { decodeProviderInformation, decodeScoreAttestation, getAttestationData } from "../utils/onChainStamps";
import { FeatureFlags } from "../config/feature_flags";
import { UseQueryResult, useQueries, useQueryClient } from "@tanstack/react-query";
import { Eip1193Provider } from "ethers";

const ENABLED_CHAIN_IDS = chains
.filter(({ attestationProvider }) => attestationProvider?.status === "enabled")
Expand Down Expand Up @@ -62,13 +61,11 @@ type GetOnChainDataForChainResult = SingleChainData & { chainId: string };
const getOnChainDataForChain = async ({
address,
chainId,
provider,
}: {
address: string;
chainId: string;
provider: Eip1193Provider;
}): Promise<GetOnChainDataForChainResult> => {
const passportAttestationData = await getAttestationData(address, chainId as keyof typeof onchainInfo, provider);
const passportAttestationData = await getAttestationData(address, chainId as keyof typeof onchainInfo);
let providers: OnChainProviderType[] = [];
let score = 0;
let expirationDate: Date | undefined;
Expand All @@ -82,8 +79,8 @@ const getOnChainDataForChain = async ({
.map((providerInfo, index) => ({
providerName: providerInfo.providerName,
credentialHash: `v0.0.0:${Buffer.from(hashes[index].slice(2), "hex").toString("base64")}`,
expirationDate: new Date(Number(expirationDates[index]) * 1000),
issuanceDate: new Date(Number(issuanceDates[index]) * 1000),
expirationDate: new Date(expirationDates[index].toNumber() * 1000),
issuanceDate: new Date(issuanceDates[index].toNumber() * 1000),
}));

({ score, expirationDate } = decodeScoreAttestation(passportAttestationData.score));
Expand All @@ -98,7 +95,6 @@ const getOnChainDataForChain = async ({
};

const useOnChainDataQuery = (address?: string) => {
const provider = useWalletStore((state) => state.provider);
// Combines results of all queries into a single object
const combine = useCallback((results: UseQueryResult<GetOnChainDataForChainResult>[]) => {
const isPending = results.some((result) => result.isPending);
Expand Down Expand Up @@ -126,9 +122,9 @@ const useOnChainDataQuery = (address?: string) => {

return useQueries({
queries: ENABLED_CHAIN_IDS.map((chainId) => ({
enabled: FeatureFlags.FF_CHAIN_SYNC && Boolean(address) && Boolean(provider),
enabled: FeatureFlags.FF_CHAIN_SYNC && Boolean(address),
queryKey: [ALL_CHAIN_DATA_QUERY_KEY, address, chainId],
queryFn: () => getOnChainDataForChain({ address: address!, chainId, provider: provider! }),
queryFn: () => getOnChainDataForChain({ address: address!, chainId }),
})),
combine,
});
Expand Down
9 changes: 5 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"@didtools/pkh-ethereum": "^0.5.0",
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@ethereum-attestation-service/eas-sdk": "^2.3.0",
"@ethereum-attestation-service/eas-sdk": "^0.29.1",
"@ethersproject/providers": "^5.6.4",
"@gitcoin/passport-database-client": "^1.0.0",
"@gitcoin/passport-identity": "^1.0.0",
"@gitcoin/passport-platforms": "^1.0.0",
Expand All @@ -31,13 +32,13 @@
"@popperjs/core": "^2.11.7",
"@self.id/framework": "^0.4.0",
"@tanstack/react-query": "^5.40.0",
"@web3-onboard/core": "2.22.2",
"@web3-onboard/core": "2.21.2",
"@web3-onboard/injected-wallets": "2.10.7",
"@web3-onboard/react": "2.9.2",
"@web3-onboard/react": "2.8.13",
"@web3-onboard/walletconnect": "2.4.7",
"@web3-onboard/walletlink": "2.1.3",
"broadcast-channel": "^4.11.0",
"did-session": "^3.1.0",
"did-session": "^3.0.2",
"dids": "^5.0.2",
"dompurify": "^3.0.11",
"ethers": "^6.3.0",
Expand Down
10 changes: 5 additions & 5 deletions app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
"incremental": true,
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"./*.tsx",
"jest.config.ts",
"jest.setup.ts"
"jest.setup.ts",
],
"exclude": ["node_modules"],
"ts-node": {
"esm": true,
"compilerOptions": {
"module": "nodenext"
}
}
"module": "nodenext",
},
},
}
28 changes: 15 additions & 13 deletions app/utils/onChainStamps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Contract, JsonRpcProvider, formatUnits, Signer, BrowserProvider, Eip1193Provider } from "ethers";
import { Contract, JsonRpcProvider, formatUnits } from "ethers";
import { JsonRpcProvider as V5JsonRpcProvider } from "@ethersproject/providers";
import { BigNumber } from "@ethersproject/bignumber";
import axios from "axios";
import onchainInfo from "../../deployments/onchainInfo.json";
Expand Down Expand Up @@ -26,17 +27,16 @@ const SCORE_MAX_AGE_MILLISECONDS = 1000 * 60 * 60 * 24 * 90; // 90 days

export async function getAttestationData(
address: string,
chainId: keyof typeof onchainInfo,
provider: Eip1193Provider
chainId: keyof typeof onchainInfo
): Promise<AttestationData | undefined> {
try {
const activeChainRpc = chains.find((chain) => chain.id === chainId)?.rpcUrl;

if (!activeChainRpc) {
throw new Error(`No rpcUrl found for chainId ${chainId}`);
}

const ethersProvider = new BrowserProvider(provider, "any");
const signer = await ethersProvider.getSigner();
const ethersProvider = new JsonRpcProvider(activeChainRpc);

const resolverAddress = onchainInfo[chainId].GitcoinResolver.address;
const resolverAbi = GitcoinResolverAbi[chainId];
Expand All @@ -50,7 +50,9 @@ export async function getAttestationData(

const eas = new EAS(onchainInfo[chainId].EAS.address);

eas.connect(signer);
// needed for ethers v5 eas dependency
const ethersV5Provider = new V5JsonRpcProvider(activeChainRpc);
eas.connect(ethersV5Provider);

return {
passport: await eas.getAttestation(passportUid),
Expand All @@ -65,8 +67,8 @@ export async function getAttestationData(
export async function decodeProviderInformation(attestation: Attestation): Promise<{
onChainProviderInfo: DecodedProviderInfo[];
hashes: string[];
issuanceDates: bigint[];
expirationDates: bigint[];
issuanceDates: BigNumber[];
expirationDates: BigNumber[];
}> {
if (attestation.data === "0x") {
return {
Expand Down Expand Up @@ -94,9 +96,9 @@ export async function decodeProviderInformation(attestation: Attestation): Promi
providerNumber: number;
};

const providers = decodedData.find((data) => data.name === "providers")?.value.value as bigint[];
const issuanceDates = decodedData.find((data) => data.name === "issuanceDates")?.value.value as bigint[];
const expirationDates = decodedData.find((data) => data.name === "expirationDates")?.value.value as bigint[];
const providers = decodedData.find((data) => data.name === "providers")?.value.value as BigNumber[];
const issuanceDates = decodedData.find((data) => data.name === "issuanceDates")?.value.value as BigNumber[];
const expirationDates = decodedData.find((data) => data.name === "expirationDates")?.value.value as BigNumber[];
const hashes = decodedData.find((data) => data.name === "hashes")?.value.value as string[];

const onChainProviderInfo: DecodedProviderInfo[] = providerBitMapInfo.data
Expand Down Expand Up @@ -125,8 +127,8 @@ export function decodeScoreAttestation(attestation: Attestation): DecodedScoreAt
const schemaEncoder = new SchemaEncoder("uint256 score,uint32 scorer_id,uint8 score_decimals");
const decodedData = schemaEncoder.decodeData(attestation.data);

const score_as_integer = decodedData.find(({ name }) => name === "score")?.value.value as bigint;
const score_decimals = decodedData.find(({ name }) => name === "score_decimals")?.value.value as bigint;
const score_as_integer = (decodedData.find(({ name }) => name === "score")?.value.value as BigNumber)._hex;
const score_decimals = decodedData.find(({ name }) => name === "score_decimals")?.value.value as number;

const score = parseFloat(formatUnits(score_as_integer, score_decimals));
const issuanceDate = new Date(BigNumber.from(attestation.time).mul(1000).toNumber()) || undefined;
Expand Down
Loading

0 comments on commit 5a6aba0

Please sign in to comment.