Skip to content

Commit

Permalink
feat(platforms): creating new provider error handling using twitter a…
Browse files Browse the repository at this point in the history
…s pilot, upgrading twitter sdk (#1563)

* feat(platforms): creating new provider error handling using twitter as pilot, upgrading twitter sdk

* feat(platforms): updates tests to account for api change

* feat(platforms): adds test for ApiRequestError

* feat(platforms): adds ApiResponseError and ApiPartialResponseError tests

* refactor(iam): run platforms in parallel, providers in series. updated error handling

* feat(app): added details link and modal to verify toasts

* feat(platforms): added logging for unhandled errors

* feat(platforms): adds tests for updated verify function

---------

Co-authored-by: Aminah Burch <[email protected]>
  • Loading branch information
lucianHymer and aminah-io authored Aug 10, 2023
1 parent 6ddfcb3 commit 5d74cda
Show file tree
Hide file tree
Showing 34 changed files with 786 additions and 1,486 deletions.
1 change: 0 additions & 1 deletion app/.env-example.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ NEXT_PUBLIC_PASSPORT_GOOGLE_CLIENT_ID=MY-APP-ID.apps.googleusercontent.com
NEXT_PUBLIC_PASSPORT_GOOGLE_CALLBACK=http://localhost:3000/

NEXT_PUBLIC_PASSPORT_TWITTER_CLIENT_ID=ABC123456789
NEXT_PUBLIC_PASSPORT_TWITTER_CALLBACK=http://127.0.0.1:3000/
NEXT_PUBLIC_PASSPORT_FACEBOOK_APP_ID=123456789
NEXT_PUBLIC_PASSPORT_GITHUB_CLIENT_ID=12345678
NEXT_PUBLIC_PASSPORT_GITHUB_CALLBACK=http://localhost:3000/
Expand Down
51 changes: 36 additions & 15 deletions app/components/GenericPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DoneToastContent } from "./DoneToastContent";
import { useToast } from "@chakra-ui/react";
import { GenericBanner } from "./GenericBanner";
import { LoadButton } from "./LoadButton";
import { JsonOutputModal } from "./JsonOutputModal";

// --- Context
import { CeramicContext } from "../context/ceramicContext";
Expand Down Expand Up @@ -70,6 +71,8 @@ export const GenericPlatform = ({ platFormGroupSpec, platform, onClose }: Generi
const [canSubmit, setCanSubmit] = useState(false);
const [showNoStampModal, setShowNoStampModal] = useState(false);
const [submitted, setSubmitted] = useState(false);
const [verificationResponse, setVerificationResponse] = useState<CredentialResponseBody[]>([]);
const [payloadModalIsOpen, setPayloadModalIsOpen] = useState(false);

// --- Chakra functions
const toast = useToast();
Expand Down Expand Up @@ -195,23 +198,25 @@ export const GenericPlatform = ({ platFormGroupSpec, platform, onClose }: Generi
return;
}

const verifyCredentialsResponse = await fetchVerifiableCredential(
iamUrl,
{
type: platform.platformId,
types: selectedProviders,
version: "0.0.0",
address: address || "",
proofs: providerPayload,
},
signer as { signMessage: (message: string) => Promise<string> }
);

const verifiedCredentials =
selectedProviders.length > 0
? (
await fetchVerifiableCredential(
iamUrl,
{
type: platform.platformId,
types: selectedProviders,
version: "0.0.0",
address: address || "",
proofs: providerPayload,
},
signer as { signMessage: (message: string) => Promise<string> }
)
).credentials?.filter((cred: any) => !cred.error) || []
? verifyCredentialsResponse.credentials?.filter((cred: any) => !cred.error) || []
: [];

setVerificationResponse(verifyCredentialsResponse.credentials || []);

const stampPatches: StampPatch[] = platformProviderIds.map((provider: PROVIDER_ID) => {
const cred = verifiedCredentials.find((cred: any) => cred.record?.type === provider);
if (cred) return { provider, credential: cred.credential as VerifiableCredential };
Expand Down Expand Up @@ -261,8 +266,17 @@ export const GenericPlatform = ({ platFormGroupSpec, platform, onClose }: Generi
updatedMinusInitial
);

const bodyWithDetailsLink = (
<>
{body}
<a className="cursor-pointer underline" onClick={() => setPayloadModalIsOpen(true)}>
See Details
</a>
</>
);

// Display done toast
doneToast(title, body, icon, platformId);
doneToast(title, bodyWithDetailsLink, icon, platformId);

setLoading(false);
} catch (e) {
Expand All @@ -280,7 +294,7 @@ export const GenericPlatform = ({ platFormGroupSpec, platform, onClose }: Generi
};

// --- Done Toast Helper
const doneToast = (title: string, body: string, icon: string, platformId: PLATFORM_ID) => {
const doneToast = (title: string, body: string | JSX.Element, icon: string, platformId: PLATFORM_ID) => {
toast({
duration: 9000,
isClosable: true,
Expand Down Expand Up @@ -426,6 +440,13 @@ export const GenericPlatform = ({ platFormGroupSpec, platform, onClose }: Generi
</div>
}
/>
<JsonOutputModal
isOpen={payloadModalIsOpen}
onClose={() => setPayloadModalIsOpen(false)}
title="Verification Response"
subheading="To preserve your privacy, error information is not stored; please share with Gitcoin support at your discretion."
jsonOutput={verificationResponse}
/>
<NoStampModal isOpen={showNoStampModal} onClose={() => setShowNoStampModal(false)} />
</>
);
Expand Down
1 change: 1 addition & 0 deletions app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
reactStrictMode: true,
webpack: function (config, options) {
config.experiments = { asyncWebAssembly: true };
config.resolve.fallback = { fs: false };
return config;
},
};
3 changes: 2 additions & 1 deletion iam/.env-example.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ GOOGLE_CALLBACK=http://localhost:3000/

TWITTER_CLIENT_ID=MY-APP-ID-TWITTER
TWITTER_CLIENT_SECRET=MY_APP_SECRET
TWITTER_CALLBACK=http://127.0.0.1:3000/
FACEBOOK_APP_ID=MY_APP_ID
FACEBOOK_APP_SECRET=MY_APP_SECRET
BRIGHTID_PRIVATE_KEY=BRIGHTID_PRIVATE_KEY
Expand All @@ -25,6 +26,7 @@ COINBASE_CLIENT_SECRET=MY_COINBASE_CLIENT_SECRET
COINBASE_CALLBACK=http://localhost:3000/

CURRENT_ENV=development
EXIT_ON_UNHANDLED_ERROR=true

# For server to use a consistent public key, provide a valid Ed25519 key here:
# IAM_JWK='{"kty":"OKP","crv":"Ed25519","x":"yourIamKeyValues","d":"yourIamKeyValues"}'
Expand Down Expand Up @@ -56,7 +58,6 @@ PASSPORT_STAMP_METADATA_PATH=http://localhost:3000/stampMetadata.json
# Use this environment variable to enable/disable testnets on on-chain-based stamp evaluation.
INCLUDE_TESTNETS=false
ZKSYNC_ERA_MAINNET_ENDPOINT=zksync_mainnet_endpoint
FF_NEW_TWITTER_STAMPS=on

CGRANTS_API_TOKEN=abc
CGRANTS_API_URL=http://localhost:8002/cgrants
2 changes: 1 addition & 1 deletion iam/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ describe("POST /verify", function () {
.expect(403)
.expect("Content-Type", /json/);

expect((response.body as ErrorResponseBody).error).toEqual("Unable to verify proofs");
expect((response.body as ErrorResponseBody).error).toEqual("Proof is not valid");
});

it("handles exception if verify credential throws", async () => {
Expand Down
2 changes: 1 addition & 1 deletion iam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"google-auth-library": "^7.14.1",
"luxon": "^2.4.0",
"tslint": "^6.1.3",
"twitter-api-sdk": "1.0.6",
"twitter-api-v2": "^1.15.1",
"typescript": "~4.6.3",
"uuid": "^8.3.2"
},
Expand Down
Loading

0 comments on commit 5d74cda

Please sign in to comment.