Skip to content

Commit

Permalink
Apply Prettier format
Browse files Browse the repository at this point in the history
  • Loading branch information
germartinez committed Oct 9, 2024
1 parent 6d6aee4 commit 5e66440
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 68 deletions.
24 changes: 12 additions & 12 deletions src/components/Dynamic.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import dynamicLogo from '@/assets/dynamic_logo.png'
import { DynamicContextProvider, useDynamicContext, useIsLoggedIn } from '@dynamic-labs/sdk-react-core'
import { EthereumWalletConnectors, isEthereumWallet } from '@dynamic-labs/ethereum'
import {
EthereumWalletConnectors,
isEthereumWallet
} from '@dynamic-labs/ethereum'
import {
DynamicContextProvider,
useDynamicContext,
useIsLoggedIn
} from '@dynamic-labs/sdk-react-core'
import Image from 'next/image'
import { useEffect, useState } from 'react'
import { WalletClient } from 'viem'
Expand All @@ -17,9 +24,8 @@ function DynamicApp() {
useEffect(() => {
const init = async () => {
if (isLoggedIn && primaryWallet && isEthereumWallet(primaryWallet)) {

const client = await primaryWallet.getWalletClient()

setProvider(client)
setSignerAddress(primaryWallet.address)
}
Expand All @@ -37,13 +43,7 @@ function DynamicApp() {
<button onClick={() => setShowAuthFlow(true)}>Connect</button>
)

const loggedInView = (
<>
<button onClick={disconnect}>
Disconnect
</button>
</>
)
const loggedInView = <button onClick={disconnect}>Disconnect</button>

return (
<div className="card">
Expand All @@ -69,7 +69,7 @@ export default function DynamicComponent() {
</div>
)
}

return (
<DynamicContextProvider
settings={{
Expand Down
26 changes: 8 additions & 18 deletions src/components/Magic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ export default function MagicComponent() {

useEffect(() => {
if (!API_KEY) return

const magicInstance = new Magic(API_KEY, {
network: {
rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
chainId: 11155111,
},
chainId: 11155111
}
})
setMagic(magicInstance)
}, [])

const login = async () => {
try {
if (!magic) return

await magic.wallet.connectWithUI()
const metadata = await magic.user.getInfo()
const signer = metadata.publicAddress
const client = createWalletClient({
chain: sepolia,
transport: custom(magic.rpcProvider)
})

setProvider(client)
setSigner(signer)
} catch (error) {
Expand All @@ -51,19 +51,9 @@ export default function MagicComponent() {
setSigner(null)
}

const unloggedInView = (
<button onClick={login}>
Connect
</button>
)
const unloggedInView = <button onClick={login}>Connect</button>

const loggedInView = (
<>
<button onClick={logout}>
Disconnect
</button>
</>
)
const loggedInView = <button onClick={logout}>Disconnect</button>

return (
<div className="card">
Expand Down
26 changes: 8 additions & 18 deletions src/components/Privy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ function PrivyApp() {
useEffect(() => {
const init = async () => {
if (!APP_ID) return
if (ready && authenticated && readyWallets && wallets.length > 0 ) {

if (ready && authenticated && readyWallets && wallets.length > 0) {
const ethereumProvider = await wallets[0].getEthereumProvider()
const client = createWalletClient({
chain: sepolia,
transport: custom(ethereumProvider)
})

setProvider(client)
setSigner(wallets[0].address)
}
}
init()
}, [ready, authenticated, readyWallets, wallets])

const connect = async () => {
try {
login()
Expand All @@ -47,19 +47,9 @@ function PrivyApp() {
setSigner(null)
}

const unloggedInView = (
<button onClick={connect}>
Connect
</button>
)
const unloggedInView = <button onClick={connect}>Connect</button>

const loggedInView = (
<>
<button onClick={disconnect}>
Disconnect
</button>
</>
)
const loggedInView = <button onClick={disconnect}>Disconnect</button>

return (
<div className="card">
Expand All @@ -85,12 +75,12 @@ export default function PrivyComponent() {
</div>
)
}

return (
<PrivyProvider
appId={APP_ID}
config={{
embeddedWallets: {
embeddedWallets: {
createOnLogin: 'users-without-wallets' // defaults to 'off'
}
}}
Expand Down
32 changes: 12 additions & 20 deletions src/components/Web3Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig }
})

const web3auth = CLIENT_ID && new Web3Auth({
clientId: CLIENT_ID,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
privateKeyProvider
})
const web3auth =
CLIENT_ID &&
new Web3Auth({
clientId: CLIENT_ID,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
privateKeyProvider
})

export default function Web3AuthComponent() {
const [provider, setProvider] = useState<WalletClient | null>(null)
Expand All @@ -39,7 +41,7 @@ export default function Web3AuthComponent() {
const init = async () => {
try {
if (!CLIENT_ID || !web3auth) return

await web3auth.initModal()
const client = createWalletClient({
chain: sepolia,
Expand All @@ -56,7 +58,7 @@ export default function Web3AuthComponent() {
}
init()
}, [])

const login = async () => {
try {
if (!web3auth) return
Expand All @@ -78,26 +80,16 @@ export default function Web3AuthComponent() {

const logout = async () => {
if (!web3auth) return

await web3auth.logout()

setProvider(null)
setSigner(null)
}

const unloggedInView = (
<button onClick={login}>
Connect
</button>
)
const unloggedInView = <button onClick={login}>Connect</button>

const loggedInView = (
<>
<button onClick={logout}>
Disconnect
</button>
</>
)
const loggedInView = <button onClick={logout}>Disconnect</button>

return (
<div className="card">
Expand Down

0 comments on commit 5e66440

Please sign in to comment.