Update sender profile after connecting wallet at subscription page
This commit is contained in:
parent
370a08c6fc
commit
64d85c6baa
2 changed files with 30 additions and 5 deletions
|
@ -25,3 +25,18 @@ export async function getSearchResults(
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function searchProfileByEthereumAddress(
|
||||||
|
walletAddress: string,
|
||||||
|
): Promise<Profile[]> {
|
||||||
|
const url = `${BACKEND_URL}/api/v1/accounts/search_did`
|
||||||
|
const response = await http(url, {
|
||||||
|
method: "GET",
|
||||||
|
queryParams: { did: `did:pkh:eip155:1:${walletAddress.toLowerCase()}` },
|
||||||
|
})
|
||||||
|
const data = await response.json()
|
||||||
|
if (response.status !== 200) {
|
||||||
|
throw new Error(data.message)
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
>
|
>
|
||||||
<avatar :profile="sender"></avatar>
|
<avatar :profile="sender"></avatar>
|
||||||
<div class="display-name">{{ sender.getDisplayName() }}</div>
|
<div class="display-name">{{ sender.getDisplayName() }}</div>
|
||||||
<div class="wallet-address">{{ senderEthereumAddress || '?' }}</div>
|
<div class="wallet-address">{{ sender.getVerifiedEthereumAddress() || '?' }}</div>
|
||||||
</component>
|
</component>
|
||||||
<div class="separator">
|
<div class="separator">
|
||||||
<img :src="require('@/assets/feather/arrow-right.svg')">
|
<img :src="require('@/assets/feather/arrow-right.svg')">
|
||||||
|
@ -101,6 +101,7 @@ import { BigNumber, FixedNumber } from "ethers"
|
||||||
import { onMounted, watch } from "vue"
|
import { onMounted, watch } from "vue"
|
||||||
import { $, $$, $ref } from "vue/macros"
|
import { $, $$, $ref } from "vue/macros"
|
||||||
|
|
||||||
|
import { searchProfileByEthereumAddress } from "@/api/search"
|
||||||
import { Profile, ProfileWrapper } from "@/api/users"
|
import { Profile, ProfileWrapper } from "@/api/users"
|
||||||
import {
|
import {
|
||||||
cancelSubscription,
|
cancelSubscription,
|
||||||
|
@ -145,8 +146,7 @@ const { instance } = $(useInstanceInfo())
|
||||||
const { connectWallet: connectEthereumWallet } = useWallet()
|
const { connectWallet: connectEthereumWallet } = useWallet()
|
||||||
const recipient = new ProfileWrapper(props.profile)
|
const recipient = new ProfileWrapper(props.profile)
|
||||||
const recipientEthereumAddress = recipient.getVerifiedEthereumAddress()
|
const recipientEthereumAddress = recipient.getVerifiedEthereumAddress()
|
||||||
const sender = $ref<ProfileWrapper>(new ProfileWrapper(currentUser || guest))
|
let sender = $ref<ProfileWrapper>(new ProfileWrapper(currentUser || guest))
|
||||||
let senderEthereumAddress = $ref<string | null>(sender.getVerifiedEthereumAddress())
|
|
||||||
let { walletAddress, walletError, getSigner } = $(useWallet())
|
let { walletAddress, walletError, getSigner } = $(useWallet())
|
||||||
let subscriptionsEnabled = $ref<boolean | null>(null)
|
let subscriptionsEnabled = $ref<boolean | null>(null)
|
||||||
let subscription = $ref<Subscription | null>(null)
|
let subscription = $ref<Subscription | null>(null)
|
||||||
|
@ -176,7 +176,6 @@ function canConnectWallet(): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
senderEthereumAddress = null
|
|
||||||
subscriptionsEnabled = null
|
subscriptionsEnabled = null
|
||||||
subscription = null
|
subscription = null
|
||||||
subscriptionState = null
|
subscriptionState = null
|
||||||
|
@ -208,7 +207,18 @@ async function checkSubscription() {
|
||||||
walletError = "Incorrect wallet address"
|
walletError = "Incorrect wallet address"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
senderEthereumAddress = walletAddress.toLowerCase()
|
// Update sender info
|
||||||
|
const profiles = await searchProfileByEthereumAddress(walletAddress)
|
||||||
|
if (profiles.length === 1) {
|
||||||
|
sender = new ProfileWrapper(profiles[0])
|
||||||
|
} else {
|
||||||
|
console.warn("can't find profile by wallet address")
|
||||||
|
sender.identity_proofs = [{
|
||||||
|
name: "$ETH",
|
||||||
|
value: walletAddress.toLowerCase(),
|
||||||
|
verified_at: null,
|
||||||
|
}]
|
||||||
|
}
|
||||||
const signer = getSigner()
|
const signer = getSigner()
|
||||||
isLoading = true
|
isLoading = true
|
||||||
subscription = await getSubscriptionInfo(
|
subscription = await getSubscriptionInfo(
|
||||||
|
|
Loading…
Reference in a new issue