Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong default address #526

Merged
merged 9 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/ui/src/components/select/NetworkSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
testChains
} from '../../constants'
import { theme } from '../../styles/theme'
import { useMultiProxy } from '../../contexts/MultiProxyContext'

const NetworkSelection = () => {
const { selectedNetwork, selectNetwork } = useNetwork()
Expand All @@ -20,6 +21,7 @@ const NetworkSelection = () => {
? Object.entries(networkList)
: Object.entries(networkList).filter(([name]) => name !== 'local')
}, [])
const { resetLists } = useMultiProxy()

const handleNetworkSelection = useCallback(
({ target: { value } }: SelectChangeEvent<unknown>) => {
Expand All @@ -28,9 +30,10 @@ const NetworkSelection = () => {
return
}

resetLists()
selectNetwork(value, true)
},
[selectNetwork]
[resetLists, selectNetwork]
)

const renderNetworks = useCallback(
Expand Down
79 changes: 33 additions & 46 deletions packages/ui/src/contexts/MultiProxyContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface IMultisigContext {
setCanFindMultiProxyFromUrl: React.Dispatch<React.SetStateAction<boolean>>
canFindMultiProxyFromUrl: boolean
setRefetchMultisigTimeoutMinutes: React.Dispatch<React.SetStateAction<number>>
resetLists: () => void
}

const MultisigContext = createContext<IMultisigContext | undefined>(undefined)
Expand All @@ -71,7 +72,7 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
)
// if set to null, it means that it hasn't been initialized yet
const [multisigList, setMultisigList] = useState<IMultisigContext['multiProxyList'] | null>(null)
const [pureToQuery, setPureToQuery] = useState<string[]>([])
const [pureLinkedToMultisigs, setPureLinkedToMultisigs] = useState<string[]>([])
const multiProxyList = useMemo(() => {
return [...(pureProxyList || []), ...(multisigList || [])]
}, [multisigList, pureProxyList])
Expand All @@ -82,9 +83,7 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
const { ownAddressList } = useAccounts()
const { watchedAddresses } = useWatchedAddresses()
const selectedHasProxy = useMemo(() => !!selectedMultiProxy?.proxy, [selectedMultiProxy])
// This is true if the currently selected Multiproxy contains no signatory owned by the user
// this happens with a watched account
const pureToQueryIds = useAccountId(pureToQuery)
const pureLinkedToMultisigsIds = useAccountId(pureLinkedToMultisigs)
const getMultiProxyByAddress = useCallback(
(address?: string) => {
if (!address) return undefined
Expand All @@ -100,6 +99,8 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
[multiProxyList]
)

// This is true if the currently Multiproxy passed as param contains no signatory
// owned by the user this happens with a watched account
const isWatchedAccount = useCallback(
(who: string | MultiProxy | undefined) => {
if (!who) return false
Expand All @@ -116,11 +117,15 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
() => isWatchedAccount(selectedMultiProxy),
[isWatchedAccount, selectedMultiProxy]
)
const [isRefreshingMultiProxyList, setIsRefreshingMultiProxyList] = useState(false)
const [, setSearchParams] = useSearchParams({
address: ''
})

const resetLists = useCallback(() => {
setMultisigList(null)
setPureProxyList(null)
}, [])

const setAddress = useCallback(
(address: string) => {
setSearchParams((prev) => {
Expand All @@ -132,19 +137,14 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
)

const refreshPureToQueryAndMultisigList = useCallback(
(data: MultisigsBySignatoriesOrWatchedQuery | null) => {
setIsRefreshingMultiProxyList(true)
// Data is only null when it is fetching
if (!data) {
setPureToQuery([])
setMultisigList(null)
}
(data: MultisigsBySignatoriesOrWatchedQuery) => {
// we do have an answer, but there is no multisig
if (!!data?.accountMultisigs && data.accountMultisigs.length === 0) {
setPureToQuery([])
setPureLinkedToMultisigs([])
setMultisigList([])
// watched addresses are part of the pure to query
// only signal we're done querying if there are no watched addresses
// watched addresses are part of the pure to query though
// only signal we're done querying by setting pureProxyList to []
// if there are no watched addresses
watchedAddresses.length === 0 && setPureProxyList([])
}

Expand Down Expand Up @@ -185,26 +185,17 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
setMultisigList(multisigArray)

// add the selection to the pure to query
setPureToQuery(Array.from(pureToQuerySet))
setPureLinkedToMultisigs(Array.from(pureToQuerySet))

// if there is no pure to query set the PureProxyList to empty array
// to signify that the pure proxies are done loading
pureToQuerySet.size === 0 && watchedAddresses.length === 0 && setPureProxyList([])
}

setIsRefreshingMultiProxyList(false)
},
[watchedAddresses]
)

const refreshWatchedPureList = useCallback((data: PureByIdsQueryQuery | null) => {
setIsRefreshingMultiProxyList(true)
// Data is only null when it is fetching
if (!data) {
// signal that we are fetching by setting the list to null
setPureProxyList(null)
}

const refreshWatchedPureList = useCallback((data: PureByIdsQueryQuery) => {
const pureProxyMap = new Map<string, Omit<MultiProxy, 'proxy'>>()
// we do have an answer, but there is nothing
if (!!data?.accounts && data.accounts.length === 0) {
Expand Down Expand Up @@ -251,7 +242,6 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
)

setPureProxyList(pureProxyArray)
setIsRefreshingMultiProxyList(false)
}, [])

useEffect(() => {
Expand All @@ -272,21 +262,21 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
const watchedAddressesIds = useAccountId(watchedAddresses)
const {
data: multisigData,
isLoading: isMultisigsubLoading,
error: isMultisigSubError,
refetch: refetchMultisigSub
isLoading: isMultisigQueryLoading,
error: multisigQueryError,
refetch: refetchMultisigQuery
} = useQueryMultisigs({
accountIds: ownAddressIds,
watchedAccountIds: watchedAddressesIds,
shouldRefetch: shouldPollMultisigs
})
const {
data: pureQueryResultData,
isLoading: isPureSubLoading,
error: isPureSubError,
refetch: refetchPureSub
isLoading: isPureQueryLoading,
error: isPureQueryError,
refetch: refetchPureQuery
} = useQueryPure({
pureIds: [...watchedAddressesIds, ...pureToQueryIds]
pureIds: [...watchedAddressesIds, ...pureLinkedToMultisigsIds]
})

useEffect(() => {
Expand Down Expand Up @@ -342,17 +332,17 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
)

const refetch = useCallback(() => {
refetchMultisigSub()
refetchPureSub()
}, [refetchMultisigSub, refetchPureSub])
refetchMultisigQuery()
refetchPureQuery()
}, [refetchMultisigQuery, refetchPureQuery])

const isDoneFetchingIndexerInfo = useMemo(() => {
if (ownAddressList.length === 0 && watchedAddresses.length === 0) {
// nothing to fetch
return true
}

if (!multisigList || !pureProxyList) {
if (multisigList === null || pureProxyList === null) {
// if any is null, we're still fetching
return false
}
Expand All @@ -361,12 +351,8 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
}, [multisigList, ownAddressList, pureProxyList, watchedAddresses])

const isLoading = useMemo(
() =>
isMultisigsubLoading ||
isPureSubLoading ||
isRefreshingMultiProxyList ||
!isDoneFetchingIndexerInfo,
[isDoneFetchingIndexerInfo, isMultisigsubLoading, isPureSubLoading, isRefreshingMultiProxyList]
() => isMultisigQueryLoading || isPureQueryLoading || !isDoneFetchingIndexerInfo,
[isDoneFetchingIndexerInfo, isMultisigQueryLoading, isPureQueryLoading]
)

const defaultAddress = useMemo(() => {
Expand All @@ -387,15 +373,16 @@ const MultiProxyContextProvider = ({ children }: MultisigContextProps) => {
selectMultiProxy,
isLoading,
selectedHasProxy,
error: isMultisigSubError || isPureSubError,
error: multisigQueryError || isPureQueryError,
getMultisigByAddress,
getMultisigAsAccountBaseInfo,
selectedIsWatched,
refetch,
canFindMultiProxyFromUrl,
setCanFindMultiProxyFromUrl,
isWatchedAccount,
setRefetchMultisigTimeoutMinutes
setRefetchMultisigTimeoutMinutes,
resetLists
}}
>
{children}
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/src/hooks/useQueryMultisigCalls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useMultisigCallsByMultisigIdQuery } from '../../types-and-hooks'
import { useMemo } from 'react'
import { useNetwork } from '../contexts/NetworkContext'

const DEFAULT_REFETCH_INTERVAL = 5000

interface Args {
multisigIds: string[]
}
Expand All @@ -15,9 +17,9 @@ export const useMultisigCallQuery = ({ multisigIds }: Args) => {
{
enabled: hasSomethingToQuery,
queryKey: [`KeyMultisigCallsByMultisigId-${multisigIds}-${selectedNetwork}`],
refetchInterval: 5000
refetchInterval: DEFAULT_REFETCH_INTERVAL
}
)

return { error, data, isLoading, refetch }
return { error, data, isLoading: isLoading && hasSomethingToQuery, refetch }
}
2 changes: 1 addition & 1 deletion packages/ui/src/hooks/useQueryMultisigs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useQueryMultisigs = ({

return {
data,
isLoading: hasSomethingToQuery && isLoading,
isLoading: isLoading && hasSomethingToQuery,
error,
refetch
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/hooks/useQueryPure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Args {
export const useQueryPure = ({ pureIds }: Args) => {
const { selectedNetwork } = useNetwork()
const hasSomethingToQuery = useMemo(() => pureIds.length > 0, [pureIds])

const { error, data, isLoading, refetch } = usePureByIdsQueryQuery(
{ pureIds },
{
Expand All @@ -17,5 +18,5 @@ export const useQueryPure = ({ pureIds }: Args) => {
}
)

return { data, isLoading: hasSomethingToQuery && isLoading, error, refetch }
return { data, isLoading: isLoading && hasSomethingToQuery, error, refetch }
}
9 changes: 3 additions & 6 deletions squid/squid-manifests/large-squid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ deploy:
cmd: ['sqd', 'start-westend']
- name: paseo-processor
cmd: ['sqd', 'start-paseo']
# - name: kilt-processor
# cmd: ['sqd', 'start-kilt']
- name: kilt-processor
cmd: ['sqd', 'start-kilt']
# - name: joystream-processor
# cmd: ['sqd', 'start-joystream']
# - name: watr-processor
Expand All @@ -61,7 +61,6 @@ deploy:
[
'npx',
'squid-graphql-server',
'--subscriptions',
'--sql-statement-timeout',
3000,
'--dumb-cache',
Expand All @@ -71,9 +70,7 @@ deploy:
'--dumb-cache-size',
100,
'--dumb-cache-max-age',
1000,
'--subscription-max-response-size',
500000
1000
]
scale:
dedicated: true
Expand Down
Loading