Skip to content

Commit

Permalink
Improve wallet.ts connectWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Mar 27, 2023
1 parent 3871ba5 commit 24e666c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apps/web/src/composables/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useEthers from '@/composables/ethers'
import useWalletConnect from '@/composables/walletConnect'
import useSolana from '@/composables/solana'
import useUsers from '@/composables/users'
import { Account, ProviderString } from '@casimir/types'
import { Account, ProviderString, User } from '@casimir/types'
import { TransactionInit } from '@/interfaces/TransactionInit'
import { MessageInit } from '@/interfaces/MessageInit'
import { Currency } from '@casimir/types'
Expand Down Expand Up @@ -91,9 +91,11 @@ export default function useWallet() {
if (session.value) {
const user = await getUser()
setUser(user)
return user
}
} catch (error) {
console.log('Error in getUserAccount in wallet.ts :>> ', error)
return null
}
}

Expand All @@ -111,15 +113,14 @@ export default function useWallet() {
const connectedAddress = await getConnectedAddressFromProvider(provider, currency)
const connectedCurrency = await detectCurrencyInProvider(provider) as Currency
const loginResponse = await loginWithWallet(provider, connectedAddress, connectedCurrency)
// TODO: Also handle case where user is not logged in / errors
if (!loginResponse?.error) {
// STEP 2
await getUserAccount() // This is querying the API for the user's account
const user = await getUserAccount() // Queries the API for the user's account
setSelectedProvider(provider)
setSelectedAddress(connectedAddress)
setSelectedCurrency(connectedCurrency)
loggedIn.value = true
primaryAddress.value = user.value?.address as string
primaryAddress.value = user?.Address
}
loadingUserWallets.value = false
} else { // Add account
Expand All @@ -137,7 +138,7 @@ export default function useWallet() {
console.log('user.value after connecting wallet :>> ', user.value)
return user.value
} catch (error) {
console.error(error)
console.error('There was an error in connectWallet :>> ', error)
}
}

Expand Down

0 comments on commit 24e666c

Please sign in to comment.