Add profile action that sends signed update
This commit is contained in:
parent
e0137cd541
commit
989945ec9e
3 changed files with 83 additions and 0 deletions
|
@ -225,6 +225,44 @@ export async function updateProfile(
|
|||
}
|
||||
}
|
||||
|
||||
interface UnsignedActivity {
|
||||
internal_activity_id: string,
|
||||
activity: string,
|
||||
}
|
||||
|
||||
export async function getUnsignedUpdate(
|
||||
authToken: string,
|
||||
): Promise<UnsignedActivity> {
|
||||
const url = `${BACKEND_URL}/api/v1/accounts/signed_update`
|
||||
const response = await http(url, { authToken })
|
||||
const data = await response.json()
|
||||
return data
|
||||
}
|
||||
|
||||
export async function sendSignedUpdate(
|
||||
authToken: string,
|
||||
internalActivityId: string,
|
||||
walletAddress: string,
|
||||
signature: string,
|
||||
): Promise<void> {
|
||||
const url = `${BACKEND_URL}/api/v1/accounts/signed_update`
|
||||
const response = await http(url, {
|
||||
method: "POST",
|
||||
json: {
|
||||
internal_activity_id: internalActivityId,
|
||||
signer: createDidFromEthereumAddress(walletAddress),
|
||||
signature: signature.replace(/0x/, ""),
|
||||
},
|
||||
authToken,
|
||||
})
|
||||
const data = await response.json()
|
||||
if (response.status !== 200) {
|
||||
throw new Error(data.message)
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
export async function getIdentityClaim(
|
||||
authToken: string,
|
||||
walletAddress: string,
|
||||
|
|
28
src/composables/signed-activity.ts
Normal file
28
src/composables/signed-activity.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { getUnsignedUpdate, sendSignedUpdate } from "@/api/users"
|
||||
import { useCurrentUser } from "@/store/user"
|
||||
import { getWallet, getWalletSignature } from "@/utils/ethereum"
|
||||
|
||||
async function signActivity(): Promise<void> {
|
||||
const { ensureAuthToken } = useCurrentUser()
|
||||
if (!confirm("This action will sign a message with your wallet and send it to your followers. Continue?")) {
|
||||
return
|
||||
}
|
||||
const signer = await getWallet()
|
||||
if (!signer) {
|
||||
return
|
||||
}
|
||||
const walletAddress = await signer.getAddress()
|
||||
const authToken = ensureAuthToken()
|
||||
const { internal_activity_id, activity } = await getUnsignedUpdate(authToken)
|
||||
const signature = await getWalletSignature(signer, activity)
|
||||
await sendSignedUpdate(
|
||||
authToken,
|
||||
internal_activity_id,
|
||||
walletAddress,
|
||||
signature,
|
||||
)
|
||||
}
|
||||
|
||||
export function useSignedActivity() {
|
||||
return { signActivity }
|
||||
}
|
|
@ -52,6 +52,14 @@
|
|||
Link ethereum address
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="canVerifyEthereumAddress()">
|
||||
<button
|
||||
title="Send signed update"
|
||||
@click="hideProfileMenu(); onSignActivity()"
|
||||
>
|
||||
Send signed update
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="canManageSubscriptions()">
|
||||
<router-link
|
||||
title="Manage subscriptions"
|
||||
|
@ -237,6 +245,7 @@ import PostList from "@/components/PostList.vue"
|
|||
import ProfileListItem from "@/components/ProfileListItem.vue"
|
||||
import SidebarLayout from "@/components/SidebarLayout.vue"
|
||||
import { useEthereumAddressVerification } from "@/composables/ethereum-address-verification"
|
||||
import { useSignedActivity } from "@/composables/signed-activity"
|
||||
import { BACKEND_URL } from "@/constants"
|
||||
import { useInstanceInfo } from "@/store/instance"
|
||||
import { useCurrentUser } from "@/store/user"
|
||||
|
@ -480,6 +489,14 @@ async function onVerifyEthereumAddress() {
|
|||
}
|
||||
}
|
||||
|
||||
async function onSignActivity() {
|
||||
if (!profile || !isCurrentUser()) {
|
||||
return
|
||||
}
|
||||
const { signActivity } = useSignedActivity()
|
||||
await signActivity()
|
||||
}
|
||||
|
||||
function isSubscriptionsFeatureEnabled(): boolean {
|
||||
const blockchain = instance?.blockchains[0]
|
||||
return Boolean(blockchain?.features.subscriptions)
|
||||
|
|
Loading…
Reference in a new issue