diff --git a/src/components/SubscriptionSettingsEthereum.vue b/src/components/SubscriptionSettingsEthereum.vue
index 62f2fb5..391648f 100644
--- a/src/components/SubscriptionSettingsEthereum.vue
+++ b/src/components/SubscriptionSettingsEthereum.vue
@@ -6,6 +6,11 @@
{{ walletError }}
+
+
+
Subscriptions are enabled
@@ -94,12 +99,14 @@ import {
} from "@/api/subscriptions-ethereum"
import Loader from "@/components/Loader.vue"
import ProfileListItem from "@/components/ProfileListItem.vue"
+import { useEthereumAddressVerification } from "@/composables/ethereum-address-verification"
import { useWallet } from "@/composables/wallet"
import { useInstanceInfo } from "@/store/instance"
import { useCurrentUser } from "@/store/user"
import { ethereumAddressMatch } from "@/utils/ethereum"
const { ensureAuthToken, ensureCurrentUser, setCurrentUser } = $(useCurrentUser())
+const { verifyEthereumAddress } = useEthereumAddressVerification()
const { instance } = $(useInstanceInfo())
const { connectWallet: connectEthereumWallet, getSigner } = useWallet()
const subscriptionPrice = $ref(1)
@@ -135,8 +142,6 @@ function canConnectWallet(): boolean {
return (
Boolean(blockchain?.contract_address) &&
Boolean(blockchain?.features.subscriptions) &&
- // Only users with verified address can have ethereum subscriptions
- profile.getVerifiedEthereumAddress() !== null &&
walletAddress === null
)
}
@@ -202,6 +207,15 @@ async function loadSubscriptionSettings() {
isLoading = false
}
+function canVerifyEthereumAddress(): boolean {
+ return walletAddress !== null && profile.getVerifiedEthereumAddress() === null
+}
+
+async function onVerifyEthereumAddress() {
+ await verifyEthereumAddress()
+ await loadSubscriptionSettings()
+}
+
function canEnableSubscriptions(): boolean {
return (
profile.getVerifiedEthereumAddress() !== null &&
diff --git a/src/composables/ethereum-address-verification.ts b/src/composables/ethereum-address-verification.ts
new file mode 100644
index 0000000..e144c9a
--- /dev/null
+++ b/src/composables/ethereum-address-verification.ts
@@ -0,0 +1,29 @@
+import { createIdentityProof, getIdentityClaim, User } from "@/api/users"
+import { useCurrentUser } from "@/store/user"
+import { getWallet, getWalletSignature } from "@/utils/ethereum"
+
+async function verifyEthereumAddress(): Promise {
+ const { ensureAuthToken, setCurrentUser } = useCurrentUser()
+ if (!confirm("This action will link your wallet address to your profile. Continue?")) {
+ return null
+ }
+ const signer = await getWallet()
+ if (!signer) {
+ return null
+ }
+ const walletAddress = await signer.getAddress()
+ const authToken = ensureAuthToken()
+ const message = await getIdentityClaim(authToken, walletAddress)
+ const signature = await getWalletSignature(signer, message)
+ const user = await createIdentityProof(
+ authToken,
+ walletAddress,
+ signature,
+ )
+ setCurrentUser(user)
+ return user
+}
+
+export function useEthereumAddressVerification() {
+ return { verifyEthereumAddress }
+}
diff --git a/src/views/Profile.vue b/src/views/Profile.vue
index ac7d76d..30379c1 100644
--- a/src/views/Profile.vue
+++ b/src/views/Profile.vue
@@ -44,7 +44,7 @@
@@ -208,8 +208,6 @@ import {
getFollowing,
} from "@/api/relationships"
import {
- createIdentityProof,
- getIdentityClaim,
getProfile,
Profile,
ProfileField,
@@ -219,18 +217,18 @@ import Avatar from "@/components/Avatar.vue"
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 { BACKEND_URL } from "@/constants"
import { useInstanceInfo } from "@/store/instance"
import { useCurrentUser } from "@/store/user"
-import { getWallet, getWalletSignature } from "@/utils/ethereum"
const route = useRoute()
const {
authToken,
currentUser,
ensureAuthToken,
- setCurrentUser,
} = $(useCurrentUser())
+const { verifyEthereumAddress } = useEthereumAddressVerification()
const { instance, getActorAddress } = $(useInstanceInfo())
let profile = $ref(null)
@@ -420,28 +418,14 @@ const feedUrl = $computed(() => {
return `${BACKEND_URL}/feeds/${profile.username}`
})
-async function verifyEthereumAddress(): Promise {
+async function onVerifyEthereumAddress() {
if (!profile || !isCurrentUser()) {
return
}
- if (!confirm("This action will link your wallet address to your profile. Continue?")) {
- return
+ const user = await verifyEthereumAddress()
+ if (user) {
+ profile.identity_proofs = user.identity_proofs
}
- const signer = await getWallet()
- if (!signer) {
- return
- }
- const walletAddress = await signer.getAddress()
- const authToken = ensureAuthToken()
- const message = await getIdentityClaim(authToken, walletAddress)
- const signature = await getWalletSignature(signer, message)
- const user = await createIdentityProof(
- authToken,
- walletAddress,
- signature,
- )
- setCurrentUser(user)
- profile.identity_proofs = user.identity_proofs
}
function canManageSubscriptions(): boolean {