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;
|
||||
|
||||
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 {
|
||||
|
|
|
@ -171,6 +171,7 @@ import {
|
|||
createIdentityProof,
|
||||
getIdentityClaim,
|
||||
getProfile,
|
||||
getVerifiedEthereumAddress,
|
||||
Profile,
|
||||
ProfileField,
|
||||
} from "@/api/users"
|
||||
|
@ -392,11 +393,22 @@ export default class ProfileView extends Vue {
|
|||
}
|
||||
|
||||
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 {
|
||||
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) {
|
||||
|
|
|
@ -34,7 +34,11 @@
|
|||
import { ref, onMounted } from "vue"
|
||||
import { useRoute } from "vue-router"
|
||||
|
||||
import { getProfile, Profile } from "@/api/users"
|
||||
import {
|
||||
getProfile,
|
||||
getVerifiedEthereumAddress,
|
||||
Profile,
|
||||
} from "@/api/users"
|
||||
import {
|
||||
getSubscriptionAuthorization,
|
||||
configureSubscription,
|
||||
|
@ -69,9 +73,11 @@ function isCurrentUser(): boolean {
|
|||
}
|
||||
|
||||
function canConnectWallet(): boolean {
|
||||
// Only profiles with verified address can have subscription
|
||||
return (
|
||||
Boolean(instance?.blockchain_contract_address) &&
|
||||
Boolean(profile?.wallet_address) &&
|
||||
profile !== null &&
|
||||
getVerifiedEthereumAddress(profile) !== null &&
|
||||
!walletConnected
|
||||
)
|
||||
}
|
||||
|
@ -88,12 +94,15 @@ async function connectWallet() {
|
|||
async function checkSubscriptionConfigured() {
|
||||
if (
|
||||
!profile ||
|
||||
!profile.wallet_address ||
|
||||
!instance ||
|
||||
!instance.blockchain_contract_address
|
||||
) {
|
||||
return
|
||||
}
|
||||
const profileEthereumAddress = getVerifiedEthereumAddress(profile)
|
||||
if (!profileEthereumAddress) {
|
||||
return
|
||||
}
|
||||
const signer = await getWallet()
|
||||
if (!signer) {
|
||||
return
|
||||
|
@ -101,7 +110,7 @@ async function checkSubscriptionConfigured() {
|
|||
subscriptionConfigured = await isSubscriptionConfigured(
|
||||
instance.blockchain_contract_address,
|
||||
signer,
|
||||
profile.wallet_address,
|
||||
profileEthereumAddress,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -142,12 +151,15 @@ function canSubscribe(): boolean {
|
|||
async function onMakeSubscriptionPayment() {
|
||||
if (
|
||||
!profile ||
|
||||
!profile.wallet_address ||
|
||||
!instance ||
|
||||
!instance.blockchain_contract_address
|
||||
) {
|
||||
return
|
||||
}
|
||||
const profileEthereumAddress = getVerifiedEthereumAddress(profile)
|
||||
if (!profileEthereumAddress) {
|
||||
return
|
||||
}
|
||||
const signer = await getWallet()
|
||||
if (!signer) {
|
||||
return
|
||||
|
@ -155,7 +167,7 @@ async function onMakeSubscriptionPayment() {
|
|||
await makeSubscriptionPayment(
|
||||
instance.blockchain_contract_address,
|
||||
signer,
|
||||
profile.wallet_address,
|
||||
profileEthereumAddress,
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue