Skip to content

Commit

Permalink
[EXC-27] lint prettier for examples (#2017)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-yangy authored Jul 26, 2024
1 parent 4d78c78 commit 9631c63
Show file tree
Hide file tree
Showing 30 changed files with 248 additions and 277 deletions.
55 changes: 0 additions & 55 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"rollup.config.*",
"node_modules/",
"dist/",
"examples/",
"**sample-app**/",
"**playground**/"
],
Expand All @@ -16,60 +15,6 @@
"tsconfigRootDir": "."
},
"rules": {
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": ["camelCase"]
},
{
"selector": "objectLiteralProperty",
"format": ["camelCase"]
},
{
"selector": "variable",
"format": ["camelCase", "UPPER_CASE"]
},
{
"selector": "variable",
"types": ["function"],
"format": ["camelCase"]
},
{
"selector": "function",
"format": ["camelCase"]
},
{
"selector": "parameter",
"format": ["camelCase"],
"leadingUnderscore": "allow"
},
{
"selector": "class",
"format": ["PascalCase"]
},
{
"selector": "enum",
"format": ["PascalCase"]
},
{
"selector": "enumMember",
"format": ["UPPER_CASE"]
},
{
"selector": "memberLike",
"modifiers": ["private"],
"format": ["camelCase", "UPPER_CASE"]
},
{
"selector": "typeLike",
"format": ["PascalCase"]
},
{
"selector": "typeProperty",
"format": ["camelCase"]
}
],
"import/prefer-default-export": ["off"],
"no-plusplus": ["off"],
"max-classes-per-file": ["off"],
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "identity",
"name": "identity-with-nextjs",
"version": "0.1.0",
"private": true,
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { PassportProvider } from "@/context/passport";
import { ReactNode } from "react";
import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import { PassportProvider } from '@/context/passport';
import { ReactNode } from 'react';
import './globals.css';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
title: "Passport Identity example",
title: 'Passport Identity example',
};

export default function RootLayout({
children,
}: Readonly<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function Page() {
const { push } = useRouter();

useEffect(() => {
push('/');
push('/');
}, [push]);
return <p />;
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
'use client';

import { usePassport } from "@/context/passport";
import { usePassport } from '@/context/passport';

export default function Home() {
const {
Expand All @@ -22,54 +22,63 @@ export default function Home() {
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={login}
type="button"
>
Login
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={loginWithoutWallet}
type="button"
>
Login Without Wallet
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={loginWithEthersjs}
type="button"
>
Login With Ethers.js
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={logout}
type="button"
>
Logout in Redirect mode
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={logoutSilent}
type="button"
>
Logout in Silent mode
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={getIdToken}
type="button"
>
Get ID Token
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={getAccessToken}
type="button"
>
Get Access Token
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={getLinkedAddresses}
type="button"
>
Get Linked Addresses
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={getUserInfo}
type="button"
>
Get User Info
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';

import { usePassport } from "@/context/passport";
import { useEffect } from "react";
import { usePassport } from '@/context/passport';
import { useEffect } from 'react';

export default function Redirect() {
const { passportInstance } = usePassport();

useEffect(() => {
if(passportInstance) {
if (passportInstance) {
// #doc passport-login-callback
passportInstance.loginCallback();
// #enddoc passport-login-callback
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
'use client';

import { useEffect } from "react";
import { usePassport } from "@/context/passport";
import { useEffect } from 'react';
import { usePassport } from '@/context/passport';

export default function Page() {
const { passportSilentInstance } = usePassport();
Expand All @@ -10,7 +10,7 @@ export default function Page() {
if (passportSilentInstance) {
const passport = passportSilentInstance;
// #doc passport-silent-logout-callback
passport.logoutSilentCallback("http://localhost:3000");
passport.logoutSilentCallback('http://localhost:3000');
// #enddoc passport-silent-logout-callback
}
}, [passportSilentInstance]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use client";
'use client';

import { createContext, ReactNode, useCallback, useContext } from "react";
import { config, passport } from "@imtbl/sdk";
import { ethers } from "ethers";
import {
createContext, ReactNode, useCallback, useContext,
} from 'react';
import { config, passport } from '@imtbl/sdk';
import { ethers } from 'ethers';

type PassportContextType = {
passportInstance?: passport.Passport;
Expand All @@ -20,19 +22,19 @@ type PassportContextType = {

const PassportContext = createContext<PassportContextType>({});

export const PassportProvider = ({ children }: { children: ReactNode }) => {
export function PassportProvider({ children }: { children: ReactNode }) {
// #doc passport-instance
const passportInstance = new passport.Passport({
baseConfig: {
environment: config.Environment.SANDBOX, // or config.Environment.SANDBOX
publishableKey:
process.env.NEXT_PUBLIC_PUBLISHABLE_KEY || "<YOUR_PUBLISHABLE_KEY>", // replace with your publishable API key from Hub
process.env.NEXT_PUBLIC_PUBLISHABLE_KEY || '<YOUR_PUBLISHABLE_KEY>', // replace with your publishable API key from Hub
},
clientId: process.env.NEXT_PUBLIC_CLIENT_ID || "<YOUR_CLIENT_ID>", // replace with your client ID from Hub
redirectUri: "http://localhost:3000/redirect", // replace with one of your redirect URIs from Hub
logoutRedirectUri: "http://localhost:3000/logout", // replace with one of your logout URIs from Hub
audience: "platform_api",
scope: "openid offline_access email transact",
clientId: process.env.NEXT_PUBLIC_CLIENT_ID || '<YOUR_CLIENT_ID>', // replace with your client ID from Hub
redirectUri: 'http://localhost:3000/redirect', // replace with one of your redirect URIs from Hub
logoutRedirectUri: 'http://localhost:3000/logout', // replace with one of your logout URIs from Hub
audience: 'platform_api',
scope: 'openid offline_access email transact',
});
// #enddoc passport-instance

Expand All @@ -41,24 +43,24 @@ export const PassportProvider = ({ children }: { children: ReactNode }) => {
baseConfig: {
environment: config.Environment.SANDBOX, // or config.Environment.SANDBOX
publishableKey:
process.env.NEXT_PUBLIC_PUBLISHABLE_KEY || "<YOUR_PUBLISHABLE_KEY>", // replace with your publishable API key from Hub
process.env.NEXT_PUBLIC_PUBLISHABLE_KEY || '<YOUR_PUBLISHABLE_KEY>', // replace with your publishable API key from Hub
},
clientId: process.env.NEXT_PUBLIC_CLIENT_ID || "<YOUR_CLIENT_ID>", // replace with your client ID from Hub
redirectUri: "http://localhost:3000/redirect", // replace with one of your redirect URIs from Hub
logoutRedirectUri: "http://localhost:3000/silent-logout", // replace with one of your logout URIs from Hub
logoutMode: "silent",
audience: "platform_api",
scope: "openid offline_access email transact",
clientId: process.env.NEXT_PUBLIC_CLIENT_ID || '<YOUR_CLIENT_ID>', // replace with your client ID from Hub
redirectUri: 'http://localhost:3000/redirect', // replace with one of your redirect URIs from Hub
logoutRedirectUri: 'http://localhost:3000/silent-logout', // replace with one of your logout URIs from Hub
logoutMode: 'silent',
audience: 'platform_api',
scope: 'openid offline_access email transact',
});
//#enddoc passport-silent-instance
// #enddoc passport-silent-instance

const login = useCallback(async () => {
if (!passportInstance) return;
// #doc passport-evm-login
const provider = passportInstance.connectEvm();
const accounts = await provider.request({ method: "eth_requestAccounts" });
const accounts = await provider.request({ method: 'eth_requestAccounts' });
// #enddoc passport-evm-login
window.alert("accounts: " + accounts);
window.alert(`accounts: ${accounts}`);
}, [passportInstance]);

const logout = useCallback(async () => {
Expand All @@ -80,7 +82,7 @@ export const PassportProvider = ({ children }: { children: ReactNode }) => {
// #doc passport-login-without-wallet
const profile: passport.UserProfile | null = await passportInstance.login();
// #enddoc passport-login-without-wallet
window.alert("profile: " + JSON.stringify(profile));
window.alert(`profile: ${JSON.stringify(profile)}`);
}, [passportInstance]);

const loginWithEthersjs = useCallback(async () => {
Expand All @@ -90,13 +92,13 @@ export const PassportProvider = ({ children }: { children: ReactNode }) => {

const web3Provider = new ethers.providers.Web3Provider(passportProvider);

const accounts = await web3Provider.send("eth_requestAccounts", []);
const accounts = await web3Provider.send('eth_requestAccounts', []);
// #enddoc passport-login-with-ethersjs

const signer = web3Provider.getSigner();

window.alert(
"accounts: " + accounts + " signer: " + JSON.stringify(signer)
`accounts: ${accounts} signer: ${JSON.stringify(signer)}`,
);
}, [passportInstance]);

Expand All @@ -105,31 +107,31 @@ export const PassportProvider = ({ children }: { children: ReactNode }) => {
// #doc passport-get-id-token
const idToken = await passportInstance.getIdToken();
// #enddoc passport-get-id-token
window.alert("idToken: " + idToken);
window.alert(`idToken: ${idToken}`);
}, [passportInstance]);

const getAccessToken = useCallback(async () => {
if (!passportInstance) return;
// #doc passport-get-access-token
const accessToken = await passportInstance.getAccessToken();
// #enddoc passport-get-access-token
window.alert("accessToken: " + accessToken);
window.alert(`accessToken: ${accessToken}`);
}, [passportInstance]);

const getLinkedAddresses = useCallback(async () => {
if (!passportInstance) return;
// #doc passport-get-linked-addresses
const linkedAddresses = await passportInstance.getLinkedAddresses();
// #enddoc passport-get-linked-addresses
window.alert("linkedAddresses: " + linkedAddresses);
window.alert(`linkedAddresses: ${linkedAddresses}`);
}, [passportInstance]);

const getUserInfo = useCallback(async () => {
if (!passportInstance) return;
// #doc passport-get-user-info
const userProfile = await passportInstance.getUserInfo();
// #enddoc passport-get-user-info
window.alert("userProfile: " + JSON.stringify(userProfile));
window.alert(`userProfile: ${JSON.stringify(userProfile)}`);
}, [passportInstance]);

return (
Expand All @@ -151,6 +153,6 @@ export const PassportProvider = ({ children }: { children: ReactNode }) => {
{children}
</PassportContext.Provider>
);
};
}

export const usePassport = () => useContext(PassportContext);
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9631c63

Please sign in to comment.