Require verified ethereum address when working with subscriptions
This commit is contained in:
parent
be63806e9d
commit
cfb7bf26c1
3 changed files with 40 additions and 9 deletions
|
@ -29,8 +29,15 @@ export interface Profile {
|
||||||
statuses_count: number;
|
statuses_count: number;
|
||||||
|
|
||||||
source: Source | null;
|
source: Source | null;
|
||||||
|
}
|
||||||
|
|
||||||
wallet_address: string | null;
|
export function getVerifiedEthereumAddress(profile: Profile): string | null {
|
||||||
|
for (const field of profile.identity_proofs) {
|
||||||
|
if (field.name === "$ETH") {
|
||||||
|
return field.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User extends Profile {
|
export interface User extends Profile {
|
||||||
|
|
|
@ -171,6 +171,7 @@ import {
|
||||||
createIdentityProof,
|
createIdentityProof,
|
||||||
getIdentityClaim,
|
getIdentityClaim,
|
||||||
getProfile,
|
getProfile,
|
||||||
|
getVerifiedEthereumAddress,
|
||||||
Profile,
|
Profile,
|
||||||
ProfileField,
|
ProfileField,
|
||||||
} from "@/api/users"
|
} from "@/api/users"
|
||||||
|
@ -392,11 +393,22 @@ export default class ProfileView extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
canConfigureSubscription(): boolean {
|
canConfigureSubscription(): boolean {
|
||||||
return Boolean(this.store.instance?.blockchain_contract_address) && Boolean(this.profile?.wallet_address) && this.isCurrentUser()
|
// Only users with verified address can configure subscription
|
||||||
|
return (
|
||||||
|
Boolean(this.store.instance?.blockchain_contract_address) &&
|
||||||
|
this.profile !== null &&
|
||||||
|
getVerifiedEthereumAddress(this.profile) !== null &&
|
||||||
|
this.isCurrentUser()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
canSubscribe(): boolean {
|
canSubscribe(): boolean {
|
||||||
return Boolean(this.store.instance?.blockchain_contract_address) && Boolean(this.profile?.wallet_address) && !this.isCurrentUser()
|
return (
|
||||||
|
Boolean(this.store.instance?.blockchain_contract_address) &&
|
||||||
|
this.profile !== null &&
|
||||||
|
getVerifiedEthereumAddress(this.profile) !== null &&
|
||||||
|
!this.isCurrentUser()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadNextPage(maxId: string) {
|
async loadNextPage(maxId: string) {
|
||||||
|
|
|
@ -34,7 +34,11 @@
|
||||||
import { ref, onMounted } from "vue"
|
import { ref, onMounted } from "vue"
|
||||||
import { useRoute } from "vue-router"
|
import { useRoute } from "vue-router"
|
||||||
|
|
||||||
import { getProfile, Profile } from "@/api/users"
|
import {
|
||||||
|
getProfile,
|
||||||
|
getVerifiedEthereumAddress,
|
||||||
|
Profile,
|
||||||
|
} from "@/api/users"
|
||||||
import {
|
import {
|
||||||
getSubscriptionAuthorization,
|
getSubscriptionAuthorization,
|
||||||
configureSubscription,
|
configureSubscription,
|
||||||
|
@ -69,9 +73,11 @@ function isCurrentUser(): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
function canConnectWallet(): boolean {
|
function canConnectWallet(): boolean {
|
||||||
|
// Only profiles with verified address can have subscription
|
||||||
return (
|
return (
|
||||||
Boolean(instance?.blockchain_contract_address) &&
|
Boolean(instance?.blockchain_contract_address) &&
|
||||||
Boolean(profile?.wallet_address) &&
|
profile !== null &&
|
||||||
|
getVerifiedEthereumAddress(profile) !== null &&
|
||||||
!walletConnected
|
!walletConnected
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -88,12 +94,15 @@ async function connectWallet() {
|
||||||
async function checkSubscriptionConfigured() {
|
async function checkSubscriptionConfigured() {
|
||||||
if (
|
if (
|
||||||
!profile ||
|
!profile ||
|
||||||
!profile.wallet_address ||
|
|
||||||
!instance ||
|
!instance ||
|
||||||
!instance.blockchain_contract_address
|
!instance.blockchain_contract_address
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const profileEthereumAddress = getVerifiedEthereumAddress(profile)
|
||||||
|
if (!profileEthereumAddress) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const signer = await getWallet()
|
const signer = await getWallet()
|
||||||
if (!signer) {
|
if (!signer) {
|
||||||
return
|
return
|
||||||
|
@ -101,7 +110,7 @@ async function checkSubscriptionConfigured() {
|
||||||
subscriptionConfigured = await isSubscriptionConfigured(
|
subscriptionConfigured = await isSubscriptionConfigured(
|
||||||
instance.blockchain_contract_address,
|
instance.blockchain_contract_address,
|
||||||
signer,
|
signer,
|
||||||
profile.wallet_address,
|
profileEthereumAddress,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,12 +151,15 @@ function canSubscribe(): boolean {
|
||||||
async function onMakeSubscriptionPayment() {
|
async function onMakeSubscriptionPayment() {
|
||||||
if (
|
if (
|
||||||
!profile ||
|
!profile ||
|
||||||
!profile.wallet_address ||
|
|
||||||
!instance ||
|
!instance ||
|
||||||
!instance.blockchain_contract_address
|
!instance.blockchain_contract_address
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const profileEthereumAddress = getVerifiedEthereumAddress(profile)
|
||||||
|
if (!profileEthereumAddress) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const signer = await getWallet()
|
const signer = await getWallet()
|
||||||
if (!signer) {
|
if (!signer) {
|
||||||
return
|
return
|
||||||
|
@ -155,7 +167,7 @@ async function onMakeSubscriptionPayment() {
|
||||||
await makeSubscriptionPayment(
|
await makeSubscriptionPayment(
|
||||||
instance.blockchain_contract_address,
|
instance.blockchain_contract_address,
|
||||||
signer,
|
signer,
|
||||||
profile.wallet_address,
|
profileEthereumAddress,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue