Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TECH-292 - Show the credential when presented #87

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/civic_sign_frontend_demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function App() {
const [principal, setPrincipal] = useState<Principal | undefined>(undefined);
const [urlCode, setUrlCode] = useState<string | null>(null);
const [selectedGatekeeperNetwork, setSelectedGatekeeperNetwork] = useState<GatekeeperNetwork>(config.gatekeeperNetworks[0]);
const [credentialCheckResponse, setCredentialCheckResponse] = useState<CredentialCheckResponse | undefined>(undefined);

// Assume we have an array of available gatekeeperNetworks
const gatekeeperNetworks = useMemo(() => config.gatekeeperNetworks, []);
Expand Down Expand Up @@ -38,24 +39,40 @@ function App() {
}, []);

const handleCredentialCheck = useCallback(async (credential?: CredentialCheckResponse, error?: Error) => {
console.log('handleCredentialCheck', credential, error);
if (error) {
console.error('Error checking credential:', error);
return;
}
console.log('Credential check response:', credential);
setCredentialCheckResponse(credential);
}, []);

const handleGatekeeperNetworkChange = useCallback((event: React.ChangeEvent<HTMLSelectElement>) => {
const selectedNetwork = gatekeeperNetworks.find((network) => network.name === event.target.value);
console.log('Selected network:', selectedNetwork);
setSelectedGatekeeperNetwork(selectedNetwork || gatekeeperNetworks[0]);
setCredentialCheckResponse(undefined);
}, []);

return (
<main className="min-h-screen bg-gray-100 flex flex-col items-center justify-center p-4">
<div className="bg-white rounded-lg shadow-lg p-8 max-w-md w-full">
<div className="bg-white rounded-lg shadow-lg p-20 max-w-2xl w-full">
<img src="/logo2.svg" alt="DFINITY logo" className="mx-auto mb-8 w-32" />

{principal ? (
<div className="flex flex-col items-center justify-center">
<h1 className="text-2xl font-bold text-center mb-4">Welcome to the ICP Relying Canister</h1>
<p className="text-center mb-6">Logged in as <span className="font-mono bg-gray-100 p-1 rounded">{principal?.toText()}</span></p>
{credentialCheckResponse && (
<div className="mb-6 w-full">
<p className="text-sm text-gray-600 mb-2">Response:</p>
<div className="bg-gray-100 rounded-md p-4 overflow-x-auto">
<pre className="text-sm">
<code>{JSON.stringify(credentialCheckResponse.credential, null, 2)}</code>
</pre>
</div>
</div>
)}
<ICPCredentialCheckButton
principal={principal}
gatekeeperNetwork={selectedGatekeeperNetwork.address}
Expand Down Expand Up @@ -104,6 +121,7 @@ function App() {
</div>
)}
</div>

</main>
);
}
Expand Down