Skip to content

Commit

Permalink
Stash working changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Oct 2, 2023
1 parent 276992d commit 63326e9
Show file tree
Hide file tree
Showing 6 changed files with 498 additions and 1,308 deletions.
22 changes: 11 additions & 11 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, SignInWithEthereumCredentials } from '@casimir/types'

const { domain, origin, usersUrl } = useEnvironment()
const { ethersProviderList, 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 @@ -97,7 +97,7 @@ export default function useAuth() {
const response = await fetch(`${usersUrl}/user`, requestOptions)
const { user: retrievedUser, error } = await response.json()
if (error) throw new Error(error)
user.value = retrievedUser
await setUser(retrievedUser)
} catch (error: any) {
throw new Error('Error getting user from API route')
}
Expand All @@ -116,11 +116,11 @@ export default function useAuth() {
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 All @@ -135,7 +135,7 @@ export default function useAuth() {
try {
loadingSessionLogout.value = true
await Session.signOut()
user.value = undefined
await setUser(undefined)
loadingSessionLogout.value = false
} catch (error) {
loadingSessionLogoutError.value = true
Expand Down
4 changes: 1 addition & 3 deletions apps/web/src/composables/breakdownMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import useEnvironment from '@/composables/environment'
import useFormat from '@/composables/format'
import usePrice from '@/composables/price'

const { ethereumUrl, manager } = useEnvironment()
const { manager, provider } = useEnvironment()
const { formatNumber } = useFormat()
const { getCurrentPrice } = usePrice()

const provider = new ethers.providers.JsonRpcProvider(ethereumUrl)

const loadingInitializeBreakdownMetrics = ref(false)
const loadingInitializeBreakdownMetricsError = ref(false)

Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/composables/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ interface ethereumWindow extends Window {
declare const window: ethereumWindow

const { createSiweMessage, signInWithEthereum } = useAuth()
const { ethereumUrl } = useEnvironment()
const provider = new ethers.providers.JsonRpcProvider(ethereumUrl)
const { ethereumUrl, provider } = useEnvironment()

export default function useEthers() {
const ethersProviderList = ['BraveWallet', 'CoinbaseWallet', 'MetaMask', 'OkxWallet', 'TrustWallet']
Expand Down
21 changes: 10 additions & 11 deletions apps/web/src/composables/user.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { onMounted, onUnmounted, readonly, ref } from 'vue'
import { UserWithAccountsAndOperators } from '@casimir/types'
import { Account, UserWithAccountsAndOperators } from '@casimir/types'
import useEnvironment from '@/composables/environment'
import { ethers } from 'ethers'

// Test address: 0xd557a5745d4560B24D36A68b52351ffF9c86A212
const { ethereumUrl, usersUrl } = useEnvironment()
const { provider, usersUrl } = useEnvironment()

const initializeComposable = ref(false)
const user = ref<UserWithAccountsAndOperators | undefined>(undefined)
const provider = new ethers.providers.JsonRpcProvider(ethereumUrl)

export default function useUser() {
// TODO: Move back to ethers composable
Expand All @@ -17,15 +16,15 @@ export default function useUser() {
return parseFloat(ethers.utils.formatEther(balance))
}

onMounted(async () => {
if (!initializeComposable.value) {
initializeComposable.value = true
}
})
// onMounted(async () => {
// if (!initializeComposable.value) {
// initializeComposable.value = true
// }
// })

onUnmounted(() => {
initializeComposable.value = false
})
// onUnmounted(() => {
// initializeComposable.value = false
// })

async function setUser(newUserValue: UserWithAccountsAndOperators | undefined) {
user.value = newUserValue
Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/layouts/default-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import useLedger from '@/composables/ledger'
import useTrezor from '@/composables/trezor'
import useWalletConnect from '@/composables/walletConnectV2'
const { addAccountToUser, checkIfPrimaryUserExists, checkIfSecondaryAddress, login, logout } = useAuth()
const { ethersProviderList, detectActiveWalletAddress, getEthersAddressesWithBalances } = useEthers()
const { screenWidth } = useScreenDimensions()
const { convertString, trimAndLowercaseAddress } = useFormat()
const { getLedgerAddress } = useLedger()
const { getTrezorAddress } = useTrezor()
const { screenWidth } = useScreenDimensions()
const { user } = useUser()
const { connectWalletConnectV2 } = useWalletConnect()
const activeWallets = [
Expand All @@ -36,9 +38,6 @@ const openRouterMenu = ref(false)
const openWalletsModal = ref(false)
const walletProviderAddresses = ref([] as CryptoAddress[])
const { addAccountToUser, checkIfPrimaryUserExists, checkIfSecondaryAddress, login, logout } = useAuth()
const { user } = useUser()
function checkIfAddressIsUsed (account: CryptoAddress): boolean {
const { address } = account
if (user.value?.accounts) {
Expand Down
Loading

0 comments on commit 63326e9

Please sign in to comment.