diff --git a/src/components/donate/LazyTxButton.tsx b/src/components/donate/LazyTxButton.tsx index aa7507f78..c0a53cef3 100644 --- a/src/components/donate/LazyTxButton.tsx +++ b/src/components/donate/LazyTxButton.tsx @@ -19,6 +19,7 @@ import { showErrorMessage, showSuccessMessage, } from 'src/components/utils/Message' +import config from 'src/config' import { AnyAccountId } from 'src/types' import { getCurrentWallet } from '../auth/utils' import { useResponsiveSize } from '../responsive/ResponsiveContext' @@ -39,6 +40,8 @@ type FailedMessage = Message | FailedMessageFn export type BaseTxButtonProps = Omit +const { appName } = config + export type TxButtonProps = BaseTxButtonProps & { accountId?: AnyAccountId network: string @@ -202,6 +205,7 @@ function LazyTxButton({ } else { const currentWallet = getCurrentWallet() const wallet = getWalletBySource(currentWallet) + await wallet?.enable(appName) signer = wallet?.signer } diff --git a/src/stores/my-account.ts b/src/stores/my-account.ts index d3ba98fe7..1b6538211 100644 --- a/src/stores/my-account.ts +++ b/src/stores/my-account.ts @@ -154,9 +154,24 @@ export const useMyAccount = create()((set, get) => ({ if (parentProxyAddress) { set({ parentProxyAddress }) try { - const proxy = await getProxies(parentProxyAddress) - const isProxyValid = proxy.includes(get().address ?? '') - if (!isProxyValid) { + // Remove proxy with type 'Any' + const proxies = await getProxies(parentProxyAddress) + const currentProxy = proxies.find(({ address }) => address === get().address) + if (currentProxy?.proxyType === 'Any') { + async function removeProxy() { + const api = getSubsocialApi() + const substrateApi = await api.substrateApi + await substrateApi.tx.proxy + .proxy(parentProxyAddress!, null, substrateApi.tx.proxy.removeProxies()) + .signAndSend(get().signer!) + } + removeProxy() + + parentProxyAddressStorage.remove() + set({ parentProxyAddress: undefined }) + get().logout() + alert('Sorry we had to remove your proxy, please relogin to use your account again.') + } else if (!currentProxy) { parentProxyAddressStorage.remove() set({ parentProxyAddress: undefined }) get().logout() @@ -192,11 +207,15 @@ async function getProxies(address: string) { .map(proxy => { const proxyData = proxy.toPrimitive() if (Array.isArray(proxyData)) { - return toSubsocialAddress((proxyData[0] as any)?.delegate)! + const data = proxyData[0] as any + return { + address: toSubsocialAddress(data?.delegate)!, + proxyType: data?.proxyType, + } } return null }) - .filter(Boolean) as string[] + .filter(Boolean) as { address: string; proxyType: string }[] } async function subscribeEnergy(