Skip to content

Commit

Permalink
fix(app): uses VCs to set verifiedProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
gdixon committed Sep 6, 2022
1 parent 8979179 commit 3dc037b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/components/PlatformCards/GitcoinPlatform.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --- Methods
import React, { useContext, useEffect, useState } from "react";
import React, { useContext, useEffect, useMemo, useState } from "react";

// --- Datadog
import { datadogLogs } from "@datadog/browser-logs";
Expand Down Expand Up @@ -53,10 +53,13 @@ export default function GithubPlatform(): JSX.Element {
const [canSubmit, setCanSubmit] = useState(false);

// find all providerIds
const providerIds =
STAMP_PROVIDERS[platformId]?.reduce((all, stamp) => {
return all.concat(stamp.providers?.map((provider) => provider.name as PROVIDER_ID));
}, [] as PROVIDER_ID[]) || [];
const providerIds = useMemo(
() =>
STAMP_PROVIDERS["Twitter"]?.reduce((all, stamp) => {
return all.concat(stamp.providers?.map((provider) => provider.name as PROVIDER_ID));
}, [] as PROVIDER_ID[]) || [],
[]
);

// SelectedProviders will be passed in to the sidebar to be filled there...
const [verifiedProviders, setVerifiedProviders] = useState<PROVIDER_ID[]>(
Expand Down Expand Up @@ -158,12 +161,13 @@ export default function GithubPlatform(): JSX.Element {
// Add all the stamps to the passport at once
await handleAddStamps(vcs as Stamp[]);
datadogLogs.logger.info("Successfully saved Stamp", { platform: platformId });
const verifiedProviders = providerIds.filter(
(providerId) => typeof allProvidersState[providerId]?.stamp?.credential !== "undefined"
// grab all providers who are verified from the verify response
const actualVerifiedProviders = providerIds.filter((providerId) =>
!!vcs.find((vc: Stamp | undefined) => vc?.credential?.credentialSubject?.provider === providerId)
);
// update the verified and selected providers
setVerifiedProviders([...verifiedProviders]);
setSelectedProviders([...verifiedProviders]);
// both verified and selected should look the same after save
setVerifiedProviders([...actualVerifiedProviders]);
setSelectedProviders([...actualVerifiedProviders]);
// reset can submit state
setCanSubmit(false);
// Custom Success Toast
Expand Down

0 comments on commit 3dc037b

Please sign in to comment.