Skip to content

Commit

Permalink
Merge pull request #704 from dappforce/fix/cache
Browse files Browse the repository at this point in the history
Convert addresses to subsocial format
  • Loading branch information
teodorus-nathaniel authored Aug 30, 2024
2 parents 7411556 + 6d693bb commit 28ea9ed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
36 changes: 24 additions & 12 deletions src/services/subsocial/evmAddresses/mutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getAccountDataQuery } from '@/services/subsocial/evmAddresses'
import { useSendEvent } from '@/stores/analytics'
import { MutationConfig } from '@/subsocial-query'
import { useSubsocialMutation } from '@/subsocial-query/subsocial/mutation'
import { convertAddressToSubsocialAddress } from '@/utils/account'
import { useQueryClient } from '@tanstack/react-query'
import { useState } from 'react'
import { useDisconnect } from 'wagmi'
Expand Down Expand Up @@ -74,7 +75,10 @@ export function useLinkEvmAddress({
mutateAccountsDataCache(address)
},
onSuccess: async ({ address }) => {
getAccountDataQuery.invalidate(client, address)
getAccountDataQuery.invalidate(
client,
convertAddressToSubsocialAddress(address)
)

setOnCallbackLoading(false)
sendEvent('evm-address-linked', undefined, { evmLinked: true })
Expand Down Expand Up @@ -126,21 +130,29 @@ export function useUnlinkEvmAddress(config?: MutationConfig<UnlinkEvmAddress>) {
config,
{
txCallbacks: {
onStart: () => setOnCallbackLoading(true),
onStart: ({ address }) => {
setOnCallbackLoading(true)
mutateAccountsDataCache(address)
},
onSend: ({ address }) => {
getAccountDataQuery.setQueryData(client, address, (data) => {
if (!data) return data
return {
...data,
evmAddress: null,
ensNames: null,
getAccountDataQuery.setQueryData(
client,
convertAddressToSubsocialAddress(address),
(data) => {
if (!data) return data
return {
...data,
evmAddress: null,
ensNames: null,
}
}
})
)
},
onSuccess: async ({ address }) => {
await mutateAccountsDataCache(address)

getAccountDataQuery.invalidate(client, address)
getAccountDataQuery.invalidate(
client,
convertAddressToSubsocialAddress(address)
)

setOnCallbackLoading(false)
disconnect()
Expand Down
9 changes: 7 additions & 2 deletions src/stores/my-account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ const useMyAccountBase = create<State & Actions>()((set, get) => ({
const { connectedWallet } = get()
if (!connectedWallet) return
parentProxyAddressStorage.set(connectedWallet.address)
set({ parentProxyAddress: connectedWallet.address })
set({
parentProxyAddress: convertAddressToSubsocialAddress(
connectedWallet.address
),
})
},
disconnectProxy: () => {
get().connectedWallet?._unsubscribeEnergy?.()
Expand Down Expand Up @@ -393,7 +397,8 @@ const useMyAccountBase = create<State & Actions>()((set, get) => ({

set({
isInitialized: true,
parentProxyAddress: parentProxyAddress ?? undefined,
parentProxyAddress:
convertAddressToSubsocialAddress(parentProxyAddress ?? '') ?? undefined,
})

if (parentProxyAddress) {
Expand Down

0 comments on commit 28ea9ed

Please sign in to comment.