diff --git a/centrifuge-js/src/modules/proxies.ts b/centrifuge-js/src/modules/proxies.ts index 279d8989fd..46c349d754 100644 --- a/centrifuge-js/src/modules/proxies.ts +++ b/centrifuge-js/src/modules/proxies.ts @@ -11,7 +11,12 @@ export function getProxiesModule(inst: CentrifugeBase) { const $api = inst.getApi() const $events = inst.getEvents().pipe( filter(({ api, events }) => { - const event = events.find(({ event }) => api.events.proxy.PureCreated.is(event)) + const event = events.find( + ({ event }) => + api.events.proxy.PureCreated.is(event) || + api.events.proxy.PureAdded.is(event) || + api.events.proxy.PureRemoved.is(event) + ) return !!event }) ) diff --git a/centrifuge-react/src/components/WalletProvider/WalletProvider.tsx b/centrifuge-react/src/components/WalletProvider/WalletProvider.tsx index 4097aa261c..4a59873f08 100644 --- a/centrifuge-react/src/components/WalletProvider/WalletProvider.tsx +++ b/centrifuge-react/src/components/WalletProvider/WalletProvider.tsx @@ -8,6 +8,7 @@ import * as React from 'react' import { useQuery } from 'react-query' import { firstValueFrom, map, switchMap } from 'rxjs' import { ReplacedError, useAsyncCallback } from '../../hooks/useAsyncCallback' +import { useCentrifugeQuery } from '../../hooks/useCentrifugeQuery' import { useCentrifuge, useCentrifugeApi, useCentrifugeConsts } from '../CentrifugeProvider' import { EvmChains, getAddChainParameters, getEvmUrls } from './evm/chains' import { EvmConnectorMeta, getEvmConnectors } from './evm/connectors' @@ -191,19 +192,6 @@ export function WalletProvider({ }, [] ) - - /* - ['allProxies'], - () => - firstValueFrom(cent.proxies.getAllProxies()).then((proxies) => { - return Object.fromEntries( - Object.entries(proxies).map(([delegatee, ps]) => [ - utils.formatAddress(delegatee), - ps.map((p) => ({ ...p, delegator: utils.formatAddress(p.delegator) })), - ]) - ) - }), - */ const evmSubstrateAccounts = isEvmOnSubstrate ? state.evm.accounts?.map((addr) => ({ address: evmToSubstrateAddress(addr, centEvmChainId!), @@ -211,36 +199,39 @@ export function WalletProvider({ wallet: state.evm.selectedWallet as any, })) : null - const { data: proxies, isLoading: proxiesAreLoading } = useQuery( - [ - 'proxies', - state.substrate.accounts?.map((acc) => acc.address), - state.substrate.multisigs.map((m) => m.address), - evmSubstrateAccounts?.map((acc) => acc.address), - ], - () => - firstValueFrom( - cent.proxies.getMultiUserProxies([ - (state.substrate.accounts || []) - .map((acc) => acc.address) - .concat(state.substrate.multisigs.map((m) => m.address)) - .concat(evmSubstrateAccounts?.map((acc) => acc.address) || []), - ]) - ), - { - staleTime: Infinity, - } - ) - const delegatees = [...new Set(Object.values(proxies ?? {})?.flatMap((p) => p.map((d) => d.delegator)))] - const { data: nestedProxies, isLoading: nestedProxiesAreLoading } = useQuery( - ['nestedProxies', delegatees], - () => firstValueFrom(cent.proxies.getMultiUserProxies([delegatees])), - { - enabled: !!Object.keys(proxies ?? {})?.length, - staleTime: Infinity, - } - ) + // const { data: proxies, isLoading: proxiesAreLoading } = useQuery( + // [ + // 'proxies', + // state.substrate.accounts?.map((acc) => acc.address), + // state.substrate.multisigs.map((m) => m.address), + // evmSubstrateAccounts?.map((acc) => acc.address), + // ], + // () => + // firstValueFrom( + // cent.proxies.getMultiUserProxies([ + // (state.substrate.accounts || []) + // .map((acc) => acc.address) + // .concat(state.substrate.multisigs.map((m) => m.address)) + // .concat(evmSubstrateAccounts?.map((acc) => acc.address) || []), + // ]) + // ), + // { + // staleTime: Infinity, + // } + // ) + + // const delegatees = [...new Set(Object.values(proxies ?? {})?.flatMap((p) => p.map((d) => d.delegator)))] + // const { data: nestedProxies, isLoading: nestedProxiesAreLoading } = useQuery( + // ['nestedProxies', delegatees], + // () => firstValueFrom(cent.proxies.getMultiUserProxies([delegatees])), + // { + // enabled: !!Object.keys(proxies ?? {})?.length, + // staleTime: Infinity, + // } + // ) + + const [proxies] = useCentrifugeQuery(['allProxies'], (cent) => cent.proxies.getAllProxies()) function setFilteredAccounts(accounts: SubstrateAccount[]) { const mappedAccounts = accounts @@ -369,7 +360,9 @@ export function WalletProvider({ const [scopedNetworks, setScopedNetworks] = React.useState(null) const ctx: WalletContextType = React.useMemo(() => { - const combinedProxies = { ...proxies, ...nestedProxies } + const combinedProxies = { + ...proxies, + } const combinedSubstrateAccounts = (evmSubstrateAccounts || state.substrate.accounts)?.flatMap((account) => { const { address } = account @@ -455,7 +448,7 @@ export function WalletProvider({ selectedProxies: selectedCombinedAccount?.proxies || null, selectedMultisig: selectedCombinedAccount?.multisig || null, proxies: combinedProxies, - proxiesAreLoading: nestedProxiesAreLoading || proxiesAreLoading, + proxiesAreLoading: !proxies, subscanUrl, }, evm: { @@ -465,7 +458,7 @@ export function WalletProvider({ chains: evmChains, }, } - }, [connect, disconnect, selectAccount, proxies, nestedProxies, state, isConnectError, isConnecting]) + }, [connect, disconnect, selectAccount, proxies, state, isConnectError, isConnecting]) return ( diff --git a/centrifuge-react/src/hooks/useCentrifugeTransaction.ts b/centrifuge-react/src/hooks/useCentrifugeTransaction.ts index 457af28367..23cdcb5be4 100644 --- a/centrifuge-react/src/hooks/useCentrifugeTransaction.ts +++ b/centrifuge-react/src/hooks/useCentrifugeTransaction.ts @@ -9,6 +9,9 @@ import { PalletError } from '../utils/errors' export type CentrifugeTransactionOptions = Pick & { account?: CombinedSubstrateAccount + // If a transaction can be done via a proxy other than Any, pass the allowed types here, + // to make sure the transaction selects the right one. + // Otherwise by default it will try the transaction with the Any proxy type forceProxyType?: string | string[] }