Skip to content

Commit f1ca1d6

Browse files
authored
Merge pull request #421 from consensusnetworks/update/composables
Update/composables
2 parents f6271c4 + 0a5c7f7 commit f1ca1d6

28 files changed

+1069
-1683
lines changed
40.4 KB
Binary file not shown.
2.13 MB
Binary file not shown.
8.01 KB
Binary file not shown.

apps/web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
},
1010
"dependencies": {
1111
"@heroicons/vue": "^1.0.6",
12-
"@solana/web3.js": "^1.63.1",
1312
"@walletconnect/sign-client": "^2.9.2",
1413
"@walletconnect/types": "^2.9.2",
1514
"@walletconnect/universal-provider": "^2.9.2",

apps/web/src/App.vue

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
<script lang="ts" setup>
22
import { RouterView } from 'vue-router'
33
import DefaultLayout from '@/layouts/default-layout.vue'
4-
import useTxData from '@/mockData/mock_transaction_data'
5-
import { onMounted, watch } from 'vue'
6-
import useUsers from '@/composables/users'
7-
8-
const { mockData } = useTxData()
9-
// Need this to fix initilizing bug between user.ts and ssv.ts
10-
const { user } = useUsers()
11-
12-
const runMockData = () =>{
13-
if(user.value?.accounts.length && user.value?.accounts.length > 0){
14-
const walletAddresses = user.value?.accounts.map(item => {
15-
return item.address
16-
}) as string[]
17-
mockData(walletAddresses)
18-
}
19-
}
20-
21-
watch(user, () =>{
22-
runMockData()
23-
})
24-
25-
onMounted(() => {
26-
runMockData()
27-
})
284
</script>
295

306
<template>

apps/web/src/composables/auth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import useEnvironment from '@/composables/environment'
2-
import { LoginCredentials } from '@casimir/types'
2+
import { SignInWithEthereumCredentials } from '@casimir/types'
33

44
const { domain, origin, usersUrl } = useEnvironment()
55

@@ -45,17 +45,17 @@ export default function useAuth() {
4545
* Signs user up if they don't exist, otherwise
4646
* logs the user in with an address, message, and signed message
4747
*
48-
* @param {LoginCredentials} loginCredentials - The user's address, provider, currency, message, and signed message
48+
* @param {SignInWithEthereumCredentials} signInWithEthereumCredentials - The user's address, provider, currency, message, and signed message
4949
* @returns {Promise<Response>} - The response from the login request
5050
*/
51-
async function signInWithEthereum(loginCredentials: LoginCredentials): Promise<void> {
51+
async function signInWithEthereum(signInWithEthereumCredentials: SignInWithEthereumCredentials): Promise<void> {
5252
try {
5353
const requestOptions = {
5454
method: 'POST',
5555
headers: {
5656
'Content-Type': 'application/json'
5757
},
58-
body: JSON.stringify(loginCredentials)
58+
body: JSON.stringify(signInWithEthereumCredentials)
5959
}
6060
const response = await fetch(`${usersUrl}/auth/login`, requestOptions)
6161
const { error, message } = await response.json()

apps/web/src/composables/contracts.ts

Lines changed: 28 additions & 343 deletions
Large diffs are not rendered by default.

apps/web/src/composables/ethers.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { EthersProvider } from '@casimir/types'
33
import { Account, TransactionRequest, UserWithAccountsAndOperators } from '@casimir/types'
44
import { GasEstimate, LoginCredentials, MessageRequest, ProviderString } from '@casimir/types'
55
import useAuth from '@/composables/auth'
6-
import useContracts from '@/composables/contracts'
76
import useEnvironment from '@/composables/environment'
8-
import useUsers from '@/composables/users'
97

108
interface ethereumWindow extends Window {
119
ethereum: any;
@@ -31,31 +29,6 @@ export default function useEthers() {
3129
}
3230
}
3331

34-
async function blockListener(blockNumber: number) {
35-
const { manager, refreshBreakdown } = useContracts()
36-
const { user } = useUsers()
37-
38-
console.log('blockNumber :>> ', blockNumber)
39-
const addresses = (user.value as UserWithAccountsAndOperators).accounts.map((account: Account) => account.address) as string[]
40-
const block = await provider.getBlockWithTransactions(blockNumber)
41-
42-
const txs = block.transactions.map(async (tx) => {
43-
if (addresses.includes(tx.from.toLowerCase())) {
44-
console.log('tx :>> ', tx)
45-
try {
46-
// const response = manager.interface.parseTransaction({ data: tx.data })
47-
// console.log('response :>> ', response)
48-
await refreshBreakdown()
49-
} catch (error) {
50-
console.error('Error parsing transaction:', error)
51-
}
52-
}
53-
})
54-
55-
await Promise.all(txs)
56-
}
57-
58-
5932
/**
6033
* Estimate gas fee using EIP 1559 methodology
6134
* @returns string in ETH
@@ -176,13 +149,6 @@ export default function useEthers() {
176149
return maxAfterFees
177150
}
178151

179-
async function listenForTransactions() {
180-
provider.on('block', blockListener as ethers.providers.Listener)
181-
await new Promise(() => {
182-
// Wait indefinitely using a Promise that never resolves
183-
})
184-
}
185-
186152
async function loginWithEthers(loginCredentials: LoginCredentials): Promise<void>{
187153
const { provider, address, currency } = loginCredentials
188154
const browserProvider = getBrowserProvider(provider)
@@ -191,7 +157,7 @@ export default function useEthers() {
191157
const message = await createSiweMessage(address, 'Sign in with Ethereum to the app.')
192158
const signer = web3Provider.getSigner()
193159
const signedMessage = await signer.signMessage(message)
194-
await signInWithEthereum({
160+
await signInWithEthereum({
195161
address,
196162
currency,
197163
message,
@@ -241,10 +207,6 @@ export default function useEthers() {
241207
return signature
242208
}
243209

244-
function stopListeningForTransactions() {
245-
provider.off('block', blockListener as ethers.providers.Listener)
246-
}
247-
248210
async function switchEthersNetwork (providerString: ProviderString, chainId: string) {
249211
const provider = getBrowserProvider(providerString)
250212
const currentChainId = await provider.networkVersion
@@ -283,12 +245,10 @@ export default function useEthers() {
283245
getEthersBrowserSigner,
284246
getGasPriceAndLimit,
285247
getMaxETHAfterFees,
286-
listenForTransactions,
287248
loginWithEthers,
288249
requestEthersAccount,
289250
sendEthersTransaction,
290251
signEthersMessage,
291-
stopListeningForTransactions,
292252
switchEthersNetwork
293253
}
294254
}

apps/web/src/composables/format.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ export default function useFormat() {
2323
const scale = Math.pow(10, tier * 3)
2424
const scaled = number / scale
2525
return scaled.toFixed(2) + suffix
26-
}
26+
}
27+
28+
function trimAndLowercaseAddress(address: string) {
29+
return address.trim().toLowerCase()
30+
}
2731

2832
return {
2933
convertString,
3034
formatDecimalString,
31-
formatNumber
35+
formatNumber,
36+
trimAndLowercaseAddress,
3237
}
3338
}

apps/web/src/composables/router.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createWebHistory, createRouter } from 'vue-router'
2-
import useUsers from '@/composables/users'
32
import Overview from '@/pages/overview/Overview.vue'
43
import Operator from '@/pages/operators/Operator.vue'
54

@@ -31,22 +30,4 @@ const router = createRouter({
3130
routes
3231
})
3332

34-
// TO DO: Add a routing beforeEach that
35-
// dynamically fixes rerouting to auth page
36-
37-
router.beforeEach(async (to, from, next) => {
38-
const { checkUserSessionExists } = useUsers()
39-
await checkUserSessionExists()
40-
next()
41-
// if (to.fullPath === '/auth' && !loggedIn) {
42-
// next()
43-
// } else if (to.fullPath === '/auth' && loggedIn) {
44-
// next('/')
45-
// } else if (!loggedIn) {
46-
// next('/auth')
47-
// } else {
48-
// next()
49-
// }
50-
})
51-
5233
export default router

0 commit comments

Comments
 (0)