Skip to content

Commit

Permalink
added chain filter
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch-txs committed Feb 2, 2024
1 parent 5e6245f commit 1180b43
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 52 deletions.
6 changes: 3 additions & 3 deletions apps/laboratory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@emotion/styled": "11.11.0",
"@sentry/browser": "7.92.0",
"@sentry/react": "7.92.0",
"@tanstack/react-query": "5.17.19",
"@tanstack/react-query": "5.18.1",
"@web3modal/ethers": "4.0.0-648b6755",
"@web3modal/ethers5": "4.0.0-648b6755",
"@web3modal/wagmi": "4.0.0-648b6755",
Expand All @@ -29,8 +29,8 @@
"react-icons": "4.12.0",
"siwe": "2.1.4",
"valtio": "1.11.2",
"viem": "2.5.0",
"wagmi": "2.5.0"
"viem": "2.7.1",
"wagmi": "2.5.5"
},
"devDependencies": {
"@mailsac/api": "1.0.5",
Expand Down
202 changes: 199 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/common/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Transaction {
export interface TransactionMetadata {
operationType: string
hash: string
chain: `${string}:${string}`
minedAt: string
sentFrom: string
sentTo: string
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { subscribeKey as subKey } from 'valtio/utils'
import { proxy, ref } from 'valtio/vanilla'
import { proxy, ref, subscribe as sub } from 'valtio/vanilla'
import type { CaipNetwork, CaipNetworkId } from '../utils/TypeUtil.js'
import { PublicStateController } from './PublicStateController.js'
import { TransactionsController } from './TransactionsController.js'
import { EventsController } from './EventsController.js'
import { ModalController } from './ModalController.js'

Expand Down Expand Up @@ -37,6 +36,10 @@ const state = proxy<NetworkControllerState>({
export const NetworkController = {
state,

subscribe(callback: (newState: NetworkControllerState) => void) {
return sub(state, () => callback(state))
},

subscribeKey<K extends StateKey>(key: K, callback: (value: NetworkControllerState[K]) => void) {
return subKey(state, key, callback)
},
Expand All @@ -54,9 +57,6 @@ export const NetworkController = {
},

setCaipNetwork(caipNetwork: NetworkControllerState['caipNetwork']) {
TransactionsController.setPrevChainInView(TransactionsController.state.chainInView)
TransactionsController.setChainInView(caipNetwork?.name)

state.caipNetwork = caipNetwork
PublicStateController.set({ selectedNetworkId: caipNetwork?.id })
this.checkIfSupportedNetwork()
Expand Down
21 changes: 7 additions & 14 deletions packages/core/src/controllers/TransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type TransactionByYearMap = Record<number, TransactionByMonthMap>
export interface TransactionsControllerState {
transactions: Transaction[]
transactionsByYear: TransactionByYearMap
chainInView: string | undefined
prevChainInView: string | undefined
lastNetworkInView: string | undefined
loading: boolean
empty: boolean
next: string | undefined
Expand All @@ -24,8 +23,7 @@ export interface TransactionsControllerState {
const state = proxy<TransactionsControllerState>({
transactions: [],
transactionsByYear: {},
chainInView: undefined,
prevChainInView: undefined,
lastNetworkInView: undefined,
loading: false,
empty: false,
next: undefined
Expand All @@ -39,12 +37,8 @@ export const TransactionsController = {
return sub(state, () => callback(state))
},

setChainInView(chainInView: TransactionsControllerState['chainInView']) {
state.chainInView = chainInView
},

setPrevChainInView(prevChainInView: TransactionsControllerState['prevChainInView']) {
state.prevChainInView = prevChainInView
setLastNetworkInView(lastNetworkInView: TransactionsControllerState['lastNetworkInView']) {
state.lastNetworkInView = lastNetworkInView
},

async fetchTransactions(accountAddress?: string) {
Expand Down Expand Up @@ -123,11 +117,9 @@ export const TransactionsController = {
},

filterByConnectedChain(transactions: Transaction[]) {
//TOD0 - This should filter by chain - fungible info is very unrelated
const chainName = NetworkController.state.caipNetwork?.name
const chainId = NetworkController.state.caipNetwork?.id
const filteredTransactions = transactions.filter(
transaction =>
transaction.transfers[0]?.fungible_info?.name?.toLowerCase() === chainName?.toLowerCase()
transaction => transaction.metadata.chain === chainId
)

return filteredTransactions
Expand All @@ -136,6 +128,7 @@ export const TransactionsController = {
resetTransactions() {
state.transactions = []
state.transactionsByYear = {}
state.lastNetworkInView = undefined
state.loading = false
state.empty = false
state.next = undefined
Expand Down
Loading

0 comments on commit 1180b43

Please sign in to comment.