Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Feb 5, 2025
1 parent 05d5830 commit 1c9b0bd
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 36 deletions.
6 changes: 3 additions & 3 deletions packages/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ThemeProvider as MuiThemeProvider } from '@mui/material/styles'
import { AccountNamesContextProvider } from './contexts/AccountNamesContext'
import { NetworkContextProvider } from './contexts/NetworkContext'
import MainLayout from './components/layout/Main'
import { WatchedAddressesContextProvider } from './contexts/WatchedAddressesContext'
import { WatchedAccountsContextProvider } from './contexts/WatchedAccountsContext'
import { WalletConnectContextProvider } from './contexts/WalletConnectContext'
import { ModalsContextProvider } from './contexts/ModalsContext'
import { PplApiContextProvider } from './contexts/PeopleChainApiContext'
Expand All @@ -34,7 +34,7 @@ const App = () => {
<ApiContextProvider>
<PplApiContextProvider>
<AssetsContextProvider>
<WatchedAddressesContextProvider>
<WatchedAccountsContextProvider>
<HiddenAccountsContextProvider>
<AccountContextProvider>
<AccountNamesContextProvider>
Expand All @@ -48,7 +48,7 @@ const App = () => {
</AccountNamesContextProvider>
</AccountContextProvider>
</HiddenAccountsContextProvider>
</WatchedAddressesContextProvider>
</WatchedAccountsContextProvider>
</AssetsContextProvider>
</PplApiContextProvider>
</ApiContextProvider>
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/ConnectCreateOrWatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { styled } from '@mui/material'
import { createSearchParams, useNavigate, useSearchParams } from 'react-router'
import { Button } from './library'
import { WATCH_ACCOUNT_ANCHOR } from '../pages/Settings/Settings'
import { useWatchedAddresses } from '../contexts/WatchedAddressesContext'
import { useWatchedAccounts } from '../contexts/WatchedAccountsContext'
import { useNetwork } from '../contexts/NetworkContext'
import { useAccounts } from '../contexts/AccountsContext'

export const ConnectOrWatch = () => {
const { setIsConnectionDialogOpen, isAllowedToConnectToExtension, allowConnectionToExtension } =
useAccounts()
const { watchedAddresses } = useWatchedAddresses()
const { watchedAddresses } = useWatchedAccounts()
const navigate = useNavigate()
const [searchParams] = useSearchParams()
const { selectedNetwork } = useNetwork()
Expand Down
6 changes: 2 additions & 4 deletions packages/ui/src/contexts/HiddenAccountsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useNetwork } from './NetworkContext'
import { HexString } from 'polkadot-api'
import { useGetEncodedAddress } from '../hooks/useGetEncodedAddress'
import { useSearchParams } from 'react-router'
import { useWatchedAddresses } from './WatchedAddressesContext'
import { useWatchedAccounts } from './WatchedAccountsContext'

const LOCALSTORAGE_HIDDEN_ACCOUNTS_KEY = 'multix.hiddenAccounts'

Expand Down Expand Up @@ -45,7 +45,7 @@ const HiddenAccountsContextProvider = ({ children }: HiddenAccountsProps) => {
const { selectedNetwork } = useNetwork()
const getEncodedAddress = useGetEncodedAddress()
const [searchParams, setSearchParams] = useSearchParams({ address: '' })
const { watchedAddresses, removeWatchedAccount } = useWatchedAddresses()
const { watchedAddresses, removeWatchedAccount } = useWatchedAccounts()

const networkHiddenAccounts = useMemo(() => {
if (!selectedNetwork) return []
Expand Down Expand Up @@ -73,8 +73,6 @@ const HiddenAccountsContextProvider = ({ children }: HiddenAccountsProps) => {
})
}

console.log('watchedAddresses.includes(address))', watchedAddresses.includes(address))
console.log('watchedAddresses', watchedAddresses)
// if we are hiding a watched account
// just remove it from the watch list
if (watchedAddresses.includes(address)) {
Expand Down
7 changes: 3 additions & 4 deletions packages/ui/src/contexts/MultiProxyContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MultisigsAndPureByAccountQuery, ProxyType } from '../../types-and-hooks
import { AccountBaseInfo } from '../components/select/GenericAccountSelection'
import { useQueryMultisigsAndPureByAccounts } from '../hooks/useQueryMultisigsAndPureByAccounts'
import { useAccounts } from './AccountsContext'
import { useWatchedAddresses } from './WatchedAddressesContext'
import { useWatchedAccounts } from './WatchedAccountsContext'
import { useAccountId } from '../hooks/useAccountId'
import { getMultiProxyAddress } from '../utils/getMultiProxyAddress'
import { useSearchParams } from 'react-router'
Expand Down Expand Up @@ -73,7 +73,7 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
}, [multisigList, networkHiddenAccounts])
const { ownAddressList } = useAccounts()
const ownPubKeys = useMemo(() => getPubKeyFromAddress(ownAddressList), [ownAddressList])
const { watchedPubKeys } = useWatchedAddresses()
const { watchedPubKeys } = useWatchedAccounts()
const { selectedNetwork } = useNetwork()
const LOCALSTORAGE_LAST_MULTIPROXY_KEY_NETWORK = useMemo(
() => selectedNetwork && `multix.lastUsedMultiProxy.${selectedNetwork}`,
Expand Down Expand Up @@ -191,8 +191,7 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
if (delegatee.isMultisig) {
const pureAddress = getEncodedAddress(account.pubKey) || ''
const multisigAddress = getEncodedAddress(delegatee.pubKey) || ''
console.log('never empty pureAddress', pureAddress)
console.log('never empty multisigAddress', multisigAddress)

const previousMultisigsForProxy = pureProxyMap.get(pureAddress)?.multisigs || []

const isAlreadyInMultisigList = !!previousMultisigsForProxy.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import { getPubKeyFromAddress } from '../utils/getPubKeyFromAddress'

const LOCALSTORAGE_WATCHED_ACCOUNTS_KEY = 'multix.watchedAccount'

type WatchedAddressesProps = {
type WatchedAccountsProps = {
children: ReactNode | ReactNode[]
}

export interface IWatchedAddressesContext {
export interface IWatchedAccountsContext {
addWatchedAccount: (address: string) => void
removeWatchedAccount: (address: string) => void
watchedPubKeys: string[]
watchedAddresses: string[]
isInitialized: boolean
}

const WatchedAddressesContext = createContext<IWatchedAddressesContext | undefined>(undefined)
const WatchedAccountsContext = createContext<IWatchedAccountsContext | undefined>(undefined)

const WatchedAddressesContextProvider = ({ children }: WatchedAddressesProps) => {
const WatchedAccountsContextProvider = ({ children }: WatchedAccountsProps) => {
const [watchedPubKeys, setWatchedPubKeys] = useState<string[]>([])
const [isInitialized, setIsInitialized] = useState(false)
const { chainInfo } = useApi()
Expand Down Expand Up @@ -77,7 +77,7 @@ const WatchedAddressesContextProvider = ({ children }: WatchedAddressesProps) =>
}, [isInitialized, watchedPubKeys])

return (
<WatchedAddressesContext.Provider
<WatchedAccountsContext.Provider
value={{
addWatchedAccount,
removeWatchedAccount,
Expand All @@ -87,16 +87,16 @@ const WatchedAddressesContextProvider = ({ children }: WatchedAddressesProps) =>
}}
>
{children}
</WatchedAddressesContext.Provider>
</WatchedAccountsContext.Provider>
)
}

const useWatchedAddresses = () => {
const context = useContext(WatchedAddressesContext)
const useWatchedAccounts = () => {
const context = useContext(WatchedAccountsContext)
if (context === undefined) {
throw new Error('useWatchedAddresses must be used within a WatchedAddressesContextProvider')
throw new Error('useWatchedAddresses must be used within a WatchedAccountsContextProvider')
}
return context
}

export { WatchedAddressesContextProvider, useWatchedAddresses }
export { WatchedAccountsContextProvider, useWatchedAccounts }
4 changes: 2 additions & 2 deletions packages/ui/src/hooks/useDisplayError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { styled } from '@mui/material/styles'
import { useAccounts } from '../contexts/AccountsContext'
import { Button, Link } from '../components/library'
import { Center } from '../components/layout/Center'
import { useWatchedAddresses } from '../contexts/WatchedAddressesContext'
import { useWatchedAccounts } from '../contexts/WatchedAccountsContext'
import { useMultiProxy } from '../contexts/MultiProxyContext'
import { useSearchParams } from 'react-router'
import { useNetwork } from '../contexts/NetworkContext'

export const useDisplayError = () => {
const { ownAccountList, isAllowedToConnectToExtension } = useAccounts()
const { watchedAddresses } = useWatchedAddresses()
const { watchedAddresses } = useWatchedAccounts()
const { error: multisigQueryError, refetch, canFindMultiProxyFromUrl } = useMultiProxy()
const [searchParams, setSearchParams] = useSearchParams({ address: '' })
const { selectedNetwork } = useNetwork()
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/src/hooks/useDisplayLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { useMultiProxy } from '../contexts/MultiProxyContext'
import { useApi } from '../contexts/ApiContext'
import { useNetwork } from '../contexts/NetworkContext'
// import { useAccounts } from '../contexts/AccountsContext'
import { useWatchedAddresses } from '../contexts/WatchedAddressesContext'
import { useWatchedAccounts } from '../contexts/WatchedAccountsContext'
import LoadingBox from '../components/LoadingBox'

export const useDisplayLoader = () => {
const { isLoading: isLoadingMultisigs } = useMultiProxy()
const { api } = useApi()
const { selectedNetworkInfo } = useNetwork()
const { isInitialized: isWatchAddressInitialized } = useWatchedAddresses()
const { isInitialized: isWatchAddressInitialized } = useWatchedAccounts()

if (!isWatchAddressInitialized) {
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/pages/Settings/WatchedAccounts.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { styled } from '@mui/material/styles'
import { Box, Grid2 as Grid, IconButton, Paper } from '@mui/material'
import { useWatchedAddresses } from '../../contexts/WatchedAddressesContext'
import { useWatchedAccounts } from '../../contexts/WatchedAccountsContext'
import AccountDisplay from '../../components/AccountDisplay/AccountDisplay'
import { HiOutlineXMark } from 'react-icons/hi2'
import AccountSelection from '../../components/select/AccountSelection'
import { useMemo } from 'react'

const WatchedAccounts = () => {
const { watchedAddresses, removeWatchedAccount, addWatchedAccount } = useWatchedAddresses()
const { watchedAddresses, removeWatchedAccount, addWatchedAccount } = useWatchedAccounts()
const hasWatchedAddresses = useMemo(() => watchedAddresses.length > 0, [watchedAddresses])

return (
Expand Down
1 change: 0 additions & 1 deletion squid/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ processor.run(
isPureProxy: false
} as NewMultisigsInfo

// ctx.log.info(`${blockNumber}-${newMulti.pubKey.slice(0, 10)}-${newMultisigsInfo.size}`)
newMultisigsInfo.set(newMulti.pubKey, newMulti)
const blockHash = block.header.hash

Expand Down
4 changes: 0 additions & 4 deletions squid/src/multisigCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ import { Call } from '@subsquid/substrate-processor'
// },

export const handleMultisigCall = (multisigArgs: Call['args']) => {
// const encodedOtherSignatories = multisigArgs['otherSignatories'].map((signatory: string) => {
// return encodeId(signatory)
// })

return {
otherSignatories: multisigArgs['otherSignatories'],
threshold: multisigArgs['threshold']
Expand Down
2 changes: 1 addition & 1 deletion squid/src/util/getProxyAccountId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const getProxyAccountId = (
)
}

return `${chainId}-${delegateePubKey.slice(0, 10)}-${delegatorPubKey.slice(0, 10)}-${type}-${delay}`
return `${chainId}-${delegateePubKey.substring(20)}-${delegatorPubKey.substring(20)}-${type}-${delay}`
}

0 comments on commit 1c9b0bd

Please sign in to comment.