Skip to content

Commit

Permalink
Re-enable login method for different providers and fix loader
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Oct 3, 2023
1 parent 34b260a commit 50e7d49
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
29 changes: 14 additions & 15 deletions apps/web/src/composables/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import * as Session from 'supertokens-web-js/recipe/session'
import { onMounted, onUnmounted, readonly, ref } from 'vue'
import useEnvironment from '@/composables/environment'
import useEthers from '@/composables/ethers'
// import useLedger from '@/composables/ledger'
// import useTrezor from '@/composables/trezor'
import useLedger from '@/composables/ledger'
import useTrezor from '@/composables/trezor'
import useUser from '@/composables/user'
// import useWalletConnect from '@/composables/walletConnectV2'
import useWalletConnect from '@/composables/walletConnectV2'
import { Account, ApiResponse, LoginCredentials, ProviderString, UserAuthState } from '@casimir/types'

const { usersUrl } = useEnvironment()
const { ethersProviderList, detectActiveWalletAddress, loginWithEthers } = useEthers()
// const { loginWithLedger } = useLedger()
// const { loginWithTrezor } = useTrezor()
const { loginWithLedger } = useLedger()
const { loginWithTrezor } = useTrezor()
const { setUser, user } = useUser()
// const { loginWithWalletConnectV2, initializeWalletConnect, uninitializeWalletConnect } = useWalletConnect()
const { loginWithWalletConnectV2, /* initializeWalletConnect, uninitializeWalletConnect */ } = useWalletConnect()

const initializedAuthComposable = ref(false)
const loadingSessionLogin = ref(false)
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function useAuth() {
}
}

async function newLogin(loginCredentials: LoginCredentials): Promise<UserAuthState> {
async function login(loginCredentials: LoginCredentials): Promise<UserAuthState> {
const { address, provider } = loginCredentials
try {
if (user.value) {
Expand Down Expand Up @@ -139,7 +139,7 @@ export default function useAuth() {
const { data: { sameAddress, walletProvider } } = await checkIfPrimaryUserExists(provider as ProviderString, address)
console.log('sameAddress :>> ', sameAddress)
if (sameAddress) {
await login(loginCredentials as LoginCredentials)
await loginWithProvider(loginCredentials as LoginCredentials)
return 'Successfully logged in'
}

Expand All @@ -158,7 +158,7 @@ export default function useAuth() {
// Then check if address is the same as the one that is active in their wallet
const activeAddress = await detectActiveWalletAddress(provider as ProviderString)
if (activeAddress === address) {
await login({ provider: provider as ProviderString, address, currency: 'ETH' })
await loginWithProvider({ provider: provider as ProviderString, address, currency: 'ETH' })
return 'Successfully logged in'
} else {
alert(`The account you selected is not the same as the one that is active in your ${provider} wallet. Please open your browser extension and select the account that you want to log in with.`)
Expand All @@ -177,17 +177,17 @@ export default function useAuth() {
* @param currency
* @returns
*/
async function login(loginCredentials: LoginCredentials, pathIndex?: number) {
async function loginWithProvider(loginCredentials: LoginCredentials, pathIndex?: number) {
const { provider } = loginCredentials
try {
if (ethersProviderList.includes(provider)) {
await loginWithEthers(loginCredentials)
} else if (provider === 'Ledger') {
// await loginWithLedger(loginCredentials, JSON.stringify(pathIndex))
await loginWithLedger(loginCredentials, JSON.stringify(pathIndex))
} else if (provider === 'Trezor') {
// await loginWithTrezor(loginCredentials, JSON.stringify(pathIndex))
await loginWithTrezor(loginCredentials, JSON.stringify(pathIndex))
} else if (provider === 'WalletConnect'){
// await loginWithWalletConnectV2(loginCredentials)
await loginWithWalletConnectV2(loginCredentials)
} else {
console.log('Sign up not yet supported for this wallet provider')
}
Expand Down Expand Up @@ -215,7 +215,6 @@ export default function useAuth() {

onMounted(async () => {
if (!initializedAuthComposable.value) {
console.log('initializing auth composable')
initializedAuthComposable.value = true
// Loader
try {
Expand Down Expand Up @@ -281,7 +280,7 @@ export default function useAuth() {
loadingSessionLoginError: readonly(loadingSessionLoginError),
loadingSessionLogout: readonly(loadingSessionLogout),
loadingSessionLogoutError: readonly(loadingSessionLogoutError),
newLogin,
login,
logout
}
}
11 changes: 6 additions & 5 deletions apps/web/src/layouts/default-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import useLedger from '@/composables/ledger'
import useTrezor from '@/composables/trezor'
import useWalletConnect from '@/composables/walletConnectV2'
const { newLogin, logout } = useAuth()
const { login, logout } = useAuth()
const { ethersProviderList, getEthersAddressesWithBalances } = useEthers()
const { screenWidth } = useScreenDimensions()
const { convertString, trimAndLowercaseAddress } = useFormat()
Expand Down Expand Up @@ -55,10 +55,11 @@ function checkIfAddressIsUsed (account: CryptoAddress): boolean {
async function selectAddress(address: string) {
address = trimAndLowercaseAddress(address)
const loginCredentials = { provider: selectedProvider.value as ProviderString, address, currency: 'ETH' }
const response = await newLogin(loginCredentials as LoginCredentials)
// if (response) {
// userAuthState.value = response
// }
const response = await login(loginCredentials as LoginCredentials)
if (response) {
userAuthState.value = response
console.log('userAuthState.value :>> ', userAuthState.value)
}
}
/**
Expand Down
10 changes: 9 additions & 1 deletion apps/web/src/pages/overview/Overview.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
import { ref, onMounted, watch } from 'vue'
import Staking from './components/Staking.vue'
import StakingAvg from './components/StakingAvg.vue'
import BreakdownChart from './components/BreakdownChart.vue'
Expand All @@ -17,6 +17,14 @@ const { loadingInitializeOperators } = useOperators()
const showSkeleton = ref(true)
onMounted(() => {
setTimeout(() => {
if(loadingSessionLogin || loadingInitializeBreakdownMetrics || loadingInitializeAnalytics || loadingInitializeOperators){
showSkeleton.value = false
}
}, 500)
})
watch([loadingSessionLogin, loadingInitializeBreakdownMetrics, loadingInitializeAnalytics, loadingInitializeOperators], () =>{
setTimeout(() => {
if(loadingSessionLogin || loadingInitializeBreakdownMetrics || loadingInitializeAnalytics || loadingInitializeOperators){
Expand Down

0 comments on commit 50e7d49

Please sign in to comment.