Skip to content

Commit

Permalink
Merge pull request #493 from consensusnetworks/update/wallet-connect
Browse files Browse the repository at this point in the history
Update/wallet connect
  • Loading branch information
ccali11 authored Dec 20, 2023
2 parents 24795e6 + 7518c8e commit 19bf2e9
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 103 deletions.
16 changes: 11 additions & 5 deletions apps/mvp/src/components/ConnectWalletsFlow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useLedger from "@/composables/ledger"
import useTrezor from "@/composables/trezor"
import useUser from "@/composables/user"
import useWallets from "@/composables/wallets"
import useWalletConnect from "@/composables/walletConnectV2"
import useWalletConnect from "@/composables/walletConnect"
// import useWallets from '@/composables/wallets'
type UserAuthFlowState =
Expand Down Expand Up @@ -40,7 +40,7 @@ const { getEthersLedgerAddresses } = useLedger()
const { getEthersTrezorAddresses } = useTrezor()
const { user } = useUser()
const { detectActiveNetwork, switchEthersNetwork } = useWallets()
const { connectWalletConnectV2 } = useWalletConnect()
const { connectWalletConnect, walletConnectSelectedAccount } = useWalletConnect()
// const { installedWallets, detectInstalledWalletProviders } = useWallets()
// eslint-disable-next-line no-undef
Expand Down Expand Up @@ -164,7 +164,7 @@ async function selectProvider(provider: ProviderString): Promise<void> {
if (provider === "WalletConnect") {
// TODO: @@cali1 - pass in the network id dynamically
walletProviderAddresses.value = await connectWalletConnectV2(requiredNetwork) as CryptoAddress[]
walletProviderAddresses.value = await connectWalletConnect(requiredNetwork) as CryptoAddress[]
} else if (browserProvidersList.includes(provider)) {
walletProviderAddresses.value = await getEthersAddressesWithBalances(provider) as CryptoAddress[]
} else if (provider === "Ledger") {
Expand Down Expand Up @@ -226,6 +226,12 @@ onUnmounted(() => {
flowState.value = "select_provider"
}
})
watch(walletConnectSelectedAccount, () => {
if (selectedProvider.value === "WalletConnect") {
walletProviderAddresses.value = walletConnectSelectedAccount.value as CryptoAddress[]
}
})
</script>

<template>
Expand Down Expand Up @@ -374,7 +380,7 @@ onUnmounted(() => {
@click="
selectedProvider === 'Ledger' || selectedProvider === 'Trezor' ?
selectAddress(trimAndLowercaseAddress(act.address), pathIndex) :
selectAddress(trimAndLowercaseAddress(act.address), undefined)
selectAddress(act.address, undefined)
"
>
<div>
Expand Down Expand Up @@ -678,4 +684,4 @@ onUnmounted(() => {
letter-spacing: -0.01em;
color: #667085;
}
</style>@/composables/eventBus
</style>@/composables/eventBus@/composables/walletConnect
19 changes: 7 additions & 12 deletions apps/mvp/src/composables/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import useEthers from "@/composables/ethers"
import useLedger from "@/composables/ledger"
import useTrezor from "@/composables/trezor"
import useUser from "@/composables/user"
import useWalletConnect from "@/composables/walletConnectV2"
import useWalletConnect from "@/composables/walletConnect"
import useWallets from "@/composables/wallets"
import {
Account,
Expand All @@ -20,7 +20,7 @@ const { browserProvidersList, loginWithEthers } = useEthers()
const { loginWithLedger } = useLedger()
const { loginWithTrezor } = useTrezor()
const { setUser, user } = useUser()
const { disconnectWalletConnect, loginWithWalletConnectV2, initializeWalletConnect, uninitializeWalletConnect } = useWalletConnect()
const { disconnectWalletConnect, loginWithWalletConnect, initializeWalletConnect } = useWalletConnect()
const { detectActiveWalletAddress } = useWallets()

const initializedAuthComposable = ref(false)
Expand Down Expand Up @@ -132,9 +132,8 @@ export default function useAuth() {
if (addressExistsOnUser) return "Address already exists on this account"

// Check if it exists as a primary address of a different user
const {
data: { sameAddress, walletProvider },
} = await checkIfPrimaryUserExists(provider as ProviderString, address)
const { data: { sameAddress } } =
await checkIfPrimaryUserExists(provider as ProviderString, address)
// If yes, ask user if they want to add it as a secondary to this account or if they want to log in with that account
if (sameAddress) {
return "Address already exists as a primary address on another account"
Expand Down Expand Up @@ -174,6 +173,7 @@ export default function useAuth() {
const browserWallet = browserProvidersList.includes(provider as ProviderString)

if (provider === "WalletConnect") {
console.log("got to wallet connect login")
await loginWithProvider(loginCredentials as LoginCredentials)
await getUser()
return "Successfully logged in"
Expand Down Expand Up @@ -265,7 +265,7 @@ export default function useAuth() {
} else if (provider === "Trezor") {
await loginWithTrezor(loginCredentials)
} else if (provider === "WalletConnect") {
await loginWithWalletConnectV2(loginCredentials)
await loginWithWalletConnect(loginCredentials)
} else {
console.log("Sign up not yet supported for this wallet provider")
}
Expand Down Expand Up @@ -308,12 +308,7 @@ export default function useAuth() {
}
}
})

onUnmounted(() => {
initializedAuthComposable.value = false
uninitializeWalletConnect()
})


// TODO: Re-enable once we have a way to remove accounts in UI
// async function removeConnectedAccount() {
// if (!user?.value?.address) {
Expand Down
6 changes: 3 additions & 3 deletions apps/mvp/src/composables/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import useLedger from "@/composables/ledger"
import useTrezor from "@/composables/trezor"
import useUser from "@/composables/user"
import useWallets from "@/composables/wallets"
import useWalletConnectV2 from "@/composables/walletConnectV2"
import useWalletConnect from "@/composables/walletConnect"
import { CasimirManager, CasimirRegistry, CasimirViews } from "@casimir/ethereum/build/@types"

let baseManager: CasimirManager
Expand All @@ -35,7 +35,7 @@ const { getEthersLedgerSigner } = useLedger()
const { getEthersTrezorSigner } = useTrezor()
const { user } = useUser()
const { detectActiveNetwork, switchEthersNetwork } = useWallets()
const { getWalletConnectSignerV2 } = useWalletConnectV2()
const { getWalletConnectSigner } = useWalletConnect()
const loadingInitializeOperators = ref(false)
const loadingInitializeOperatorsError = ref(false)

Expand Down Expand Up @@ -210,7 +210,7 @@ export default function useOperators() {
if (browserProvidersList.includes(walletProvider)) {
signer = getEthersBrowserSigner(walletProvider)
} else if (walletProvider === "WalletConnect") {
await getWalletConnectSignerV2()
await getWalletConnectSigner()
} else if (walletProvider === "Ledger") {
getEthersLedgerSigner()
} else if (walletProvider === "Trezor") {
Expand Down
13 changes: 8 additions & 5 deletions apps/mvp/src/composables/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useLedger from "@/composables/ledger"
import useTrezor from "@/composables/trezor"
import useUser from "@/composables/user"
import useWallets from "@/composables/wallets"
import useWalletConnectV2 from "./walletConnectV2"
import useWalletConnect from "./walletConnect"
import { CasimirManager } from "@casimir/ethereum/build/@types"
import { StakeDetails } from "@casimir/types"

Expand All @@ -17,7 +17,7 @@ const { getEthersLedgerSigner } = useLedger()
const { getEthersTrezorSigner } = useTrezor()
const { user } = useUser()
const { detectActiveNetwork, switchEthersNetwork } = useWallets()
const { getWalletConnectSignerV2 } = useWalletConnectV2()
const { getWalletConnectSigner } = useWalletConnect()

const stakingComposableInitialized = ref(false)
const awaitingStakeOrWithdrawConfirmation = ref(false)
Expand Down Expand Up @@ -50,7 +50,9 @@ export default function useStaking() {
async function deposit({ amount, walletProvider, type, pathIndex }: { amount: string, walletProvider: ProviderString, type: "default" | "eigen", pathIndex: number | undefined}) {
stakeWithdrawError.value = ""
try {
// This is currently handling the connectWalletConnect if no current session
const activeNetwork = await detectActiveNetwork(walletProvider)
console.log("activeNetwork :>> ", activeNetwork)
if (activeNetwork !== 5) {
await switchEthersNetwork(walletProvider, "0x5")
return window.location.reload()
Expand All @@ -60,7 +62,7 @@ export default function useStaking() {
if (browserProvidersList.includes(walletProvider)) {
signer = getEthersBrowserSigner(walletProvider)
} else if (walletProvider === "WalletConnect") {
signer = await getWalletConnectSignerV2()
signer = await getWalletConnectSigner()
} else if (walletProvider === "Ledger") {
signer = getEthersLedgerSigner(pathIndex)
} else if (walletProvider === "Trezor") {
Expand Down Expand Up @@ -166,7 +168,7 @@ export default function useStaking() {
if (browserProvidersList.includes(walletProvider)) {
signer = getEthersBrowserSigner(walletProvider)
} else if (walletProvider === "WalletConnect") {
await getWalletConnectSignerV2()
await getWalletConnectSigner()
} else if (walletProvider === "Ledger") {
getEthersLedgerSigner()
} else if (walletProvider === "Trezor") {
Expand All @@ -184,6 +186,7 @@ export default function useStaking() {
async function withdraw({ amount, walletProvider, type }: { amount: string, walletProvider: ProviderString, type: "default" | "eigen" }) {
try {
stakeWithdrawError.value = ""
// This is currently handling the connectWalletConnect if no current session
const activeNetwork = await detectActiveNetwork(walletProvider)
if (activeNetwork !== 5) {
await switchEthersNetwork(walletProvider, "0x5")
Expand All @@ -194,7 +197,7 @@ export default function useStaking() {
if (browserProvidersList.includes(walletProvider)) {
signer = getEthersBrowserSigner(walletProvider)
} else if (walletProvider === "WalletConnect") {
await getWalletConnectSignerV2()
await getWalletConnectSigner()
} else if (walletProvider === "Ledger") {
getEthersLedgerSigner()
} else if (walletProvider === "Trezor") {
Expand Down
Loading

0 comments on commit 19bf2e9

Please sign in to comment.