Skip to content

Commit

Permalink
Resolve usernames from username contract state
Browse files Browse the repository at this point in the history
  • Loading branch information
Nopfed committed Jul 24, 2024
1 parent b22efda commit 25cb510
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
6 changes: 4 additions & 2 deletions components/FeedItemCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ const { data, pending } = useLazyAsyncData(props.id, async () => {
// .curations
// .get<CollaborativeWhitelistCurationState>(props.id)

// const { cachedValue: { state } } = await curation.contract.readState()
// const { cachedValue: { state } } = await curation
// .contract.readState()
// const curatedPublications = []

// let count = 0
Expand All @@ -157,7 +158,8 @@ const { data, pending } = useLazyAsyncData(props.id, async () => {
// desc: state.metadata.description as string,
// state,
// curatedPublications,
// username: await abc.usernames.resolveUsernameFromAddress(state.owner)
// username: await abc
// .usernames.resolveUsernameFromAddress(state.owner)
// }
// } catch (error) {
// console.error('Error fetching curation', props.id, error)
Expand Down
58 changes: 48 additions & 10 deletions components/ResolveUsername.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template>
<!-- <template>
<nuxt-link
v-if="!noLink"
class="text-primary"
Expand All @@ -19,23 +19,61 @@
{{ props.address }}
</code>
</template>
</template> -->

<template>
<nuxt-link
v-if="!noLink"
class="text-primary"
:to="`/${state?.usernames[props.address as string] || props.address}`"
>
<span v-if="state?.usernames[props.address as string]">
{{ state?.usernames[props.address as string] }}
</span>
<code v-else>
{{ props.address }}
</code>
</nuxt-link>
<template v-else>
<span v-if="state?.usernames[props.address as string]">
{{ state?.usernames[props.address as string] }}
</span>
<code v-else>
{{ props.address }}
</code>
</template>
</template>
<script setup lang="ts">
const props = defineProps<{ address?: string, noLink?: boolean}>()
const abc = useArtByCity()
// const {
// data: user
// } = useLazyAsyncData(`resolve-username-${props.address}`, async () => {
// if (!props.address) {
// return { profile: null, username: null }
// }
// const profile = await abc.legacy.fetchProfile(props.address)
// const username =
// await abc.usernames.resolveUsernameFromAddress(props.address)
// return { profile, username }
// })
const {
data: user
data: state
} = useLazyAsyncData(`resolve-username-${props.address}`, async () => {
if (!props.address) {
return { profile: null, username: null }
}
try {
const { cachedValue: { state } } = await abc.usernames.contract.readState()
const profile = await abc.legacy.fetchProfile(props.address)
const username =
await abc.usernames.resolveUsernameFromAddress(props.address)
return { profile, username }
return state
} catch (error) {
console.error(
`Error reading curation state for ${props.address}`,
error
)
}
})
</script>

0 comments on commit 25cb510

Please sign in to comment.