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

Revert "feat: advance verify for profile changes" #10865

Merged
merged 1 commit into from
Aug 19, 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
6 changes: 3 additions & 3 deletions components/profile/FollowButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const buttonRef = ref()

const { $i18n } = useNuxtApp()
const { accountId } = useAuth()
const { getCommonSignaturePair } = useVerifyAccount()
const { getSignaturePair } = useVerifyAccount()
const isHovered = useElementHover(buttonRef)
const { toast } = useToast()
const { doAfterLogin } = useDoAfterlogin()
Expand All @@ -39,7 +39,7 @@ const followConfig = computed<ButtonConfig>(() => ({
doAfterLogin({
onLoginSuccess: async () => {
loading.value = true
const signaturePair = await getCommonSignaturePair().catch((e) => {
const signaturePair = await getSignaturePair().catch((e) => {
toast(e.message)
loading.value = false
return
Expand Down Expand Up @@ -71,7 +71,7 @@ const unfollowConfig = computed<ButtonConfig>(() => ({
label: $i18n.t('profile.unfollow'),
onClick: async () => {
loading.value = true
const signaturePair = await getCommonSignaturePair().catch((e) => {
const signaturePair = await getSignaturePair().catch((e) => {
toast(e.message)
loading.value = false
return
Expand Down
19 changes: 7 additions & 12 deletions components/profile/create/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@

<script setup lang="ts">
import { NeoModal } from '@kodadot1/brick'

import type { StatusAPIResponse } from '@farcaster/auth-client'
import { useDocumentVisibility } from '@vueuse/core'
import {
Form,
Introduction,
Select,
type ProfileFormData,
} from './stages/index'
import type { ProfileFormData } from './stages/index'
import { Form, Introduction, Select } from './stages/index'
import { deleteProfile } from '@/services/profile'
import { appClient, createChannel } from '@/services/farcaster'

Expand All @@ -58,7 +53,7 @@ const props = defineProps<{
const { urlPrefix } = usePrefix()
const { accountId } = useAuth()
const { $i18n } = useNuxtApp()
const { getProfileVersionedSignaturePair } = useVerifyAccount()
const { getSignaturePair } = useVerifyAccount()
const documentVisibility = useDocumentVisibility()
const { add: generateSession, get: getSession } = useIdMap<Ref<SessionState>>()
const { fetchProfile } = useProfile()
Expand All @@ -80,10 +75,10 @@ const close = () => {
emit('close')
}

const handleProfileDelete = async (profileData: ProfileFormData) => {
const handleProfileDelete = async (address: string) => {
try {
const { signature, message } = await getProfileVersionedSignaturePair(profileData.address)
await deleteProfile({ address: profileData.address, message, signature })
const { signature, message } = await getSignaturePair()
await deleteProfile({ address, message, signature })
infoMessage($i18n.t('profiles.profileHasBeenCleared'), {
title: $i18n.t('profiles.profileReset'),
})
Expand All @@ -102,7 +97,7 @@ const handleFormSubmition = async (profileData: ProfileFormData) => {

try {
signingMessage.value = true
signaturePair = await getProfileVersionedSignaturePair(profileData.address)
signaturePair = await getSignaturePair()
signingMessage.value = false
close()
onModalAnimation(() => {
Expand Down
6 changes: 3 additions & 3 deletions components/profile/follow/UserRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const { accountId } = useAuth()
const { $i18n } = useNuxtApp()
const { doAfterLogin } = useDoAfterlogin()
const { toast } = useToast()
const { getCommonSignaturePair } = useVerifyAccount()
const { getSignaturePair } = useVerifyAccount()

const props = defineProps<{
user: Follower
Expand Down Expand Up @@ -103,7 +103,7 @@ const followConfig: ButtonConfig = {
onClick: async () => {
doAfterLogin({
onLoginSuccess: async () => {
const signaturePair = await getCommonSignaturePair().catch((e) => {
const signaturePair = await getSignaturePair().catch((e) => {
toast(e.message)
})

Expand Down Expand Up @@ -135,7 +135,7 @@ const followingConfig: ButtonConfig = {
const unfollowConfig: ButtonConfig = {
label: $i18n.t('profile.unfollow'),
onClick: async () => {
const signaturePair = await getCommonSignaturePair().catch((e) => {
const signaturePair = await getSignaturePair().catch((e) => {
toast(e.message)
})

Expand Down
20 changes: 4 additions & 16 deletions components/shared/modals/keyboardShortcutsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,18 @@
>
<template #default>
<div class="flex justify-between">
<NeoTable
v-for="ktype in types"
:key="ktype"
:data="updateData[ktype]"
>
<NeoTableColumn
v-slot="props"
field="text"
:label="labels[ktype]"
>
<NeoTable v-for="ktype in types" :key="ktype" :data="updateData[ktype]">
<NeoTableColumn v-slot="props" field="text" :label="labels[ktype]">
<div class="text-left">
{{ props.row.text }}
</div>
</NeoTableColumn>
<NeoTableColumn
v-slot="props"
field="shortcut"
>
<NeoTableColumn v-slot="props" field="shortcut">
<div class="flex flex-grow">
<span
v-for="(shortcut, index) in props.row.shortcut.split('+', 2)"
:key="shortcut"
class="inline-flex"
>
class="inline-flex">
<kbd class="keyboard-shortcut-kbd">
{{ shortcut || '+' }}
</kbd>
Expand Down
47 changes: 10 additions & 37 deletions composables/useVerifyAccount.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isEthereumAddress } from '@polkadot/util-crypto'
import { useSignMessage } from '@wagmi/vue'
import { fetchProfileByAddress } from '@/services/profile'

export type SignaturePair = { signature: string, message: string }

Expand All @@ -15,10 +14,7 @@ const signMessagePolkadot = async (address: string, message: string) => {
return signedMessage.signature
}

const SIGNATURE_MESSAGE = 'Verify ownership of this account on Koda'

export const generateVersionedSignatureMessage = (version: number) =>
`${SIGNATURE_MESSAGE} - ${version}`
export const SIGNATURE_MESSAGE = 'Verify ownership of this account on Koda'

export default function useVerifyAccount() {
const walletStore = useWalletStore()
Expand All @@ -36,59 +32,36 @@ export default function useVerifyAccount() {
return signedMessage
}

const getSignedMessage = async (message: string): Promise<string> => {
const getSignedMessage = async () => {
if (!accountId.value) {
throw new Error('Please connect your wallet first')
}
if (signedMessage.value) {
return signedMessage.value
}

const signMessageFn = isEthereumAddress(accountId.value)
? signMessageEthereum
: signMessagePolkadot
const signature = await signMessageFn(accountId.value, message)
const signature = await signMessageFn(accountId.value, SIGNATURE_MESSAGE)

if (signature) {
walletStore.setSignedMessage(signature)
return signature
}

throw new Error('You have not completed address verification')
}

const getCustomSignaturePair = async (message: string) => {
const signature = await getSignedMessage(message)
return {
signature,
message,
}
}

const getProfileVersionedSignaturePair = async (address: string) => {
const profile = await fetchProfileByAddress(address)
return await getCustomSignaturePair(
generateVersionedSignatureMessage(
profile?.version ? profile.version + 1 : 1,
),
)
}

const getCommonSignaturePair = async () => {
if (signedMessage.value) {
return {
signature: signedMessage.value,
message: SIGNATURE_MESSAGE,
}
}
const signature = await getSignedMessage(SIGNATURE_MESSAGE)
walletStore.setSignedMessage(signature)

const getSignaturePair = async (): Promise<SignaturePair> => {
const signature = await getSignedMessage()
return {
signature,
message: SIGNATURE_MESSAGE,
}
}

return {
getCommonSignaturePair,
getCustomSignaturePair,
getProfileVersionedSignaturePair,
getSignaturePair,
}
}
1 change: 0 additions & 1 deletion services/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const api = $fetch.create({
export type Profile = {
address: string
name: string
version?: number
description: string
image: string
banner: string | null
Expand Down
Loading