From 64d85c6baa14b136173dcbac58902e7142257689 Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 4 Aug 2022 20:52:22 +0000 Subject: [PATCH] Update sender profile after connecting wallet at subscription page --- src/api/search.ts | 15 +++++++++++++++ src/components/Subscription.vue | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/api/search.ts b/src/api/search.ts index 81c963c..ac3f65f 100644 --- a/src/api/search.ts +++ b/src/api/search.ts @@ -25,3 +25,18 @@ export async function getSearchResults( } return data } + +export async function searchProfileByEthereumAddress( + walletAddress: string, +): Promise { + 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 +} diff --git a/src/components/Subscription.vue b/src/components/Subscription.vue index 70d22bb..ce960ee 100644 --- a/src/components/Subscription.vue +++ b/src/components/Subscription.vue @@ -9,7 +9,7 @@ >
{{ sender.getDisplayName() }}
-
{{ senderEthereumAddress || '?' }}
+
{{ sender.getVerifiedEthereumAddress() || '?' }}
@@ -101,6 +101,7 @@ import { BigNumber, FixedNumber } from "ethers" import { onMounted, watch } from "vue" import { $, $$, $ref } from "vue/macros" +import { searchProfileByEthereumAddress } from "@/api/search" import { Profile, ProfileWrapper } from "@/api/users" import { cancelSubscription, @@ -145,8 +146,7 @@ const { instance } = $(useInstanceInfo()) const { connectWallet: connectEthereumWallet } = useWallet() const recipient = new ProfileWrapper(props.profile) const recipientEthereumAddress = recipient.getVerifiedEthereumAddress() -const sender = $ref(new ProfileWrapper(currentUser || guest)) -let senderEthereumAddress = $ref(sender.getVerifiedEthereumAddress()) +let sender = $ref(new ProfileWrapper(currentUser || guest)) let { walletAddress, walletError, getSigner } = $(useWallet()) let subscriptionsEnabled = $ref(null) let subscription = $ref(null) @@ -176,7 +176,6 @@ function canConnectWallet(): boolean { } function reset() { - senderEthereumAddress = null subscriptionsEnabled = null subscription = null subscriptionState = null @@ -208,7 +207,18 @@ async function checkSubscription() { walletError = "Incorrect wallet address" 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() isLoading = true subscription = await getSubscriptionInfo(