diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 00000000..3a122545 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,5 @@ +# .prettierrc or .prettierrc.yaml +printWidth: 150 +singleQuote: false +semi: true +trailingComma: es5 \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index dba79a5a..55d96626 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,7 @@ { + "editor.codeActionsOnSave": { + "source.fixAll": true + }, "eslint.workingDirectories": [ { "directory": "web-no-modal-sdk/**/*", diff --git a/single-factor-auth-web/sfa-next-jwt-example/app/evm.ethers.ts b/single-factor-auth-web/sfa-next-jwt-example/app/evm.ethers.ts index 0a691cea..2b37b057 100644 --- a/single-factor-auth-web/sfa-next-jwt-example/app/evm.ethers.ts +++ b/single-factor-auth-web/sfa-next-jwt-example/app/evm.ethers.ts @@ -11,8 +11,8 @@ export default class EthereumRpc { async getAccounts(): Promise { try { // For ethers v5 - // const provider = new ethers.providers.Web3Provider(this.provider as any); - const provider = new ethers.BrowserProvider(this.provider as any); + // const provider = new ethers.providers.Web3Provider(this.provider as IProvider); + const provider = new ethers.BrowserProvider(this.provider as IProvider); // For ethers v5 // const signer = provider.getSigner(); const signer = await provider.getSigner(); @@ -26,8 +26,8 @@ export default class EthereumRpc { async getBalance(): Promise { try { // For ethers v5 - // const provider = new ethers.providers.Web3Provider(this.provider as any); - const provider = new ethers.BrowserProvider(this.provider as any); + // const provider = new ethers.providers.Web3Provider(this.provider as IProvider); + const provider = new ethers.BrowserProvider(this.provider as IProvider); // For ethers v5 // const signer = provider.getSigner(); const signer = await provider.getSigner(); @@ -50,8 +50,8 @@ export default class EthereumRpc { async signMessage(): Promise { try { // For ethers v5 - // const provider = new ethers.providers.Web3Provider(this.provider as any); - const provider = new ethers.BrowserProvider(this.provider as any); + // const provider = new ethers.providers.Web3Provider(this.provider as IProvider); + const provider = new ethers.BrowserProvider(this.provider as IProvider); // For ethers v5 // const signer = provider.getSigner(); const signer = await provider.getSigner(); @@ -68,8 +68,8 @@ export default class EthereumRpc { async signAndSendTransaction(): Promise { try { // For ethers v5 - // const provider = new ethers.providers.Web3Provider(this.provider as any); - const provider = new ethers.BrowserProvider(this.provider as any); + // const provider = new ethers.providers.Web3Provider(this.provider as IProvider); + const provider = new ethers.BrowserProvider(this.provider as IProvider); // For ethers v5 // const signer = provider.getSigner(); const signer = await provider.getSigner(); diff --git a/single-factor-auth-web/sfa-next-jwt-example/app/evm.web3.ts b/single-factor-auth-web/sfa-next-jwt-example/app/evm.web3.ts index edf06b69..919280e4 100644 --- a/single-factor-auth-web/sfa-next-jwt-example/app/evm.web3.ts +++ b/single-factor-auth-web/sfa-next-jwt-example/app/evm.web3.ts @@ -10,7 +10,7 @@ export default class EthereumRpc { async getAccounts(): Promise { try { - const web3 = new Web3(this.provider as any); + const web3 = new Web3(this.provider as IProvider); const accounts = await web3.eth.getAccounts(); return accounts; } catch (error: unknown) { @@ -20,7 +20,7 @@ export default class EthereumRpc { async getBalance(): Promise { try { - const web3 = new Web3(this.provider as any); + const web3 = new Web3(this.provider as IProvider); const accounts = await web3.eth.getAccounts(); const balance = await web3.eth.getBalance(accounts[0]); return balance.toString(); @@ -31,7 +31,7 @@ export default class EthereumRpc { async signMessage(): Promise { try { - const web3 = new Web3(this.provider as any); + const web3 = new Web3(this.provider as IProvider); const accounts = await web3.eth.getAccounts(); const message = "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"; (web3.currentProvider as any)?.send( @@ -54,7 +54,7 @@ export default class EthereumRpc { async signAndSendTransaction(): Promise { try { - const web3 = new Web3(this.provider as any); + const web3 = new Web3(this.provider as IProvider); const accounts = await web3.eth.getAccounts(); const txRes = await web3.eth.sendTransaction({ diff --git a/single-factor-auth-web/sfa-next-jwt-example/app/page.tsx b/single-factor-auth-web/sfa-next-jwt-example/app/page.tsx index 9e991ebb..687bec38 100644 --- a/single-factor-auth-web/sfa-next-jwt-example/app/page.tsx +++ b/single-factor-auth-web/sfa-next-jwt-example/app/page.tsx @@ -18,13 +18,14 @@ const verifier = "w3a-jwt-for-sfa-web"; const clientId = "BEglQSgt4cUWcj6SKRdu5QkOXTsePmMcusG5EAoyjyOYKlVRjIF1iCNnMOTfpzCiunHRrMui8TIwQPXdkQ8Yxuk"; // get from https://dashboard.web3auth.io const chainConfig = { + chainId: "0x1", + displayName: "Ethereum Mainnet", chainNamespace: CHAIN_NAMESPACES.EIP155, - chainId: "0x5", - rpcTarget: "https://rpc.ankr.com/eth_goerli", - displayName: "Goerli Testnet", - blockExplorer: "https://goerli.etherscan.io", - ticker: "ETH", tickerName: "Ethereum", + ticker: "ETH", + decimals: 18, + rpcTarget: "https://rpc.ankr.com/eth", + blockExplorer: "https://etherscan.io", }; // Initialising Web3Auth Single Factor Auth SDK @@ -173,6 +174,43 @@ function App() { uiConsole(result); }; + const authenticateUser = async () => { + try { + const userCredential = await web3authSfa.authenticateUser(); + uiConsole(userCredential); + } catch (err) { + uiConsole(err); + } + }; + + const addChain = async () => { + try { + const newChain = { + chainId: "0x5", + displayName: "Goerli", + chainNamespace: CHAIN_NAMESPACES.EIP155, + tickerName: "Goerli", + ticker: "ETH", + decimals: 18, + rpcTarget: "https://rpc.ankr.com/eth_goerli", + blockExplorer: "https://goerli.etherscan.io", + }; + await web3authSfa.addChain(newChain); + uiConsole("Chain added successfully"); + } catch (err) { + uiConsole(err); + } + }; + + const switchChain = async () => { + try { + await web3authSfa.switchChain({ chainId: "0x5" }); + uiConsole("Chain switched successfully"); + } catch (err) { + uiConsole(err); + } + }; + const loginView = ( <>
@@ -181,11 +219,31 @@ function App() { Get User Info
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
-
@@ -285,17 +278,21 @@ function App() { const logoutView = ( <>

Email:

- { - setEmail(e.target.value) - localStorage.setItem('email_for_web3auth_sfa_demo', e.target.value); - }} /> + { + setEmail(e.target.value); + localStorage.setItem("email_for_web3auth_sfa_demo", e.target.value); + }} + />

- + ); return ( @@ -307,13 +304,7 @@ function App() { SFA React Example - {isLoading ? ( - - ): ( -
- {isLoggedIn ? loginView : logoutView} -
- )} + {isLoading ? :
{isLoggedIn ? loginView : logoutView}
}