Skip to content

Commit

Permalink
Unify polkadot set identity after link
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Dec 12, 2023
1 parent 6ab43f7 commit 6a62846
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
26 changes: 8 additions & 18 deletions src/components/auth/ProfileModal/ProfileModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CommonEvmAddressLinked } from '@/components/auth/common/evm/CommonEvmModalContent'
import Modal from '@/components/modals/Modal'
import { getLinkedTelegramAccountsQuery } from '@/services/api/notifications/query'
import { getProfileQuery } from '@/services/api/query'
import { getAccountDataQuery } from '@/services/subsocial/evmAddresses'
import { useSendEvent } from '@/stores/analytics'
import { useMyAccount, useMyMainAddress } from '@/stores/my-account'
Expand All @@ -26,7 +25,9 @@ import PushNotificationContent, {
} from './contents/notifications/PushNotificationContent'
import TelegramNotificationContent from './contents/notifications/TelegramNotificationContent'
import PolkadotConnectContent from './contents/polkadot-connect/PolkadotConnectContent'
import PolkadotConnectIdentityRemovedContent from './contents/polkadot-connect/PolkadotConnectIdentityRemovedContent'
import PolkadotConnectIdentityRemovedContent, {
useHasPreviousGrillIdentity,
} from './contents/polkadot-connect/PolkadotConnectIdentityRemovedContent'
import PolkadotConnectUnlink from './contents/polkadot-connect/PolkadotConnectUnlink'
import PrivateKeyContent from './contents/PrivateKeyContent'
import ProfileSettingsContent from './contents/ProfileSettingsContent'
Expand Down Expand Up @@ -66,7 +67,7 @@ const modalContents: {
'polkadot-connect-confirmation': PolkadotConnectConfirmationContent,
'polkadot-connect-success': PolkadotConnectSuccess,
'polkadot-connect-unlink': PolkadotConnectUnlink,
'polkadot-connect-identity-removed': PolkadotConnectIdentityRemovedContent,
'polkadot-connect-set-profile': PolkadotConnectIdentityRemovedContent,
}

const pushNotificationDesc: Record<
Expand Down Expand Up @@ -263,9 +264,9 @@ export default function ProfileModal({ notification }: ProfileModalProps) {
desc: undefined,
withBackButton: false,
},
'polkadot-connect-identity-removed': {
title: '😕 Your previous identity was removed',
desc: 'You will need to reset your nickname or reconnect your EVM address to continue using them.',
'polkadot-connect-set-profile': {
title: '😕 Go to Profile Settings?',
desc: 'You can manage which identities to use as your name.',
withBackButton: false,
},
}
Expand Down Expand Up @@ -297,7 +298,7 @@ export default function ProfileModal({ notification }: ProfileModalProps) {

const augmentedCloseModal = () => {
if (currentState === 'polkadot-connect-success' && hasPreviousIdentity) {
setCurrentStateAugmented('polkadot-connect-identity-removed')
setCurrentStateAugmented('polkadot-connect-set-profile')
} else if (
currentState === 'evm-address-linked' &&
(ensNames?.length ?? 0) > 0
Expand Down Expand Up @@ -330,14 +331,3 @@ export default function ProfileModal({ notification }: ProfileModalProps) {
</Modal>
)
}

function useHasPreviousGrillIdentity() {
const grillAddress = useMyAccount((state) => state.address)
const { data: grillAccountData } = getAccountDataQuery.useQuery(
grillAddress ?? ''
)
const { data: grillProfile } = getProfileQuery.useQuery(grillAddress ?? '')
const hasPreviousIdentity =
grillAccountData?.evmAddress || grillProfile?.profileSpace?.content?.name
return !!hasPreviousIdentity
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import Button from '@/components/Button'
import { getProfileQuery } from '@/services/api/query'
import { getAccountDataQuery } from '@/services/subsocial/evmAddresses'
import { useSendEvent } from '@/stores/analytics'
import { useMyAccount } from '@/stores/my-account'
import { ContentProps } from '../../types'

export default function PolkadotConnectIdentityRemovedContent({
setCurrentState,
}: ContentProps) {
// You will need to reset your nickname or reconnect your EVM address to continue using them.
const hasPreviousIdentity = useHasPreviousGrillIdentity()
const sendEvent = useSendEvent()
return (
<Button
Expand All @@ -18,3 +23,14 @@ export default function PolkadotConnectIdentityRemovedContent({
</Button>
)
}

export function useHasPreviousGrillIdentity() {
const grillAddress = useMyAccount((state) => state.address)
const { data: grillAccountData } = getAccountDataQuery.useQuery(
grillAddress ?? ''
)
const { data: grillProfile } = getProfileQuery.useQuery(grillAddress ?? '')
const hasPreviousIdentity =
grillAccountData?.evmAddress || grillProfile?.profileSpace?.content?.name
return !!hasPreviousIdentity
}
2 changes: 1 addition & 1 deletion src/components/auth/ProfileModal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ProfileModalState =
| 'linked-addresses'
| 'profile-settings'
| 'polkadot-connect-unlink'
| 'polkadot-connect-identity-removed'
| 'polkadot-connect-set-profile'
| 'private-key'
| 'logout'
| 'share-session'
Expand Down

0 comments on commit 6a62846

Please sign in to comment.