Skip to content

Commit

Permalink
feat: use new stamp url format for space cover and avatar (#858)
Browse files Browse the repository at this point in the history
* feat: add support for offchain testnet space avatar and cover

* fix: move all remaining stamp url to new format

---------

Co-authored-by: Less <[email protected]>
  • Loading branch information
wa0x6e and bonustrack authored Oct 12, 2024
1 parent 8deca71 commit a6714f0
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 41 deletions.
4 changes: 1 addition & 3 deletions apps/ui/src/components/FormSpaceProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ onMounted(() => {
type: 'string',
format: 'stamp',
title: 'Avatar',
default:
props.id ||
'0x2121212121212121212121212121212121212121212121212121212121212121'
default: `${space?.network || 'eth'}:${props.id || '0x2121212121212121212121212121212121212121212121212121212121212121'}`
}"
/>
<h4 class="eyebrow mb-2 font-medium">Profile</h4>
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/components/Layout/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ watch(
const faviconUrl = getStampUrl(
'space',
whiteLabelSpace.value.id,
`${whiteLabelSpace.value.network}:${whiteLabelSpace.value.id}`,
16,
getCacheHash(whiteLabelSpace.value.avatar)
);
Expand Down
5 changes: 2 additions & 3 deletions apps/ui/src/components/SpaceAvatar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { getCacheHash } from '@/helpers/utils';
import { offchainNetworks } from '@/networks';
import { NetworkID } from '@/types';
const props = withDefaults(
Expand All @@ -18,10 +17,10 @@ const cb = computed(() => getCacheHash(props.space.avatar));

<template>
<UiStamp
:id="space.id"
:id="`${space.network}:${space.id}`"
:size="size"
:cb="cb"
class="!bg-skin-bg"
:type="offchainNetworks.includes(space.network) ? 'space' : 'space-sx'"
type="space"
/>
</template>
13 changes: 4 additions & 9 deletions apps/ui/src/components/SpaceCover.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { getCacheHash, getStampUrl } from '@/helpers/utils';
import { offchainNetworks } from '@/networks';
import { NetworkID } from '@/types';
const props = withDefaults(
Expand All @@ -20,24 +19,20 @@ const cb = computed(() => getCacheHash(props.space.cover));
<template>
<UiStamp
v-if="space.cover"
:id="space.id"
:id="`${space.network}:${space.id}`"
:width="width"
:height="height"
:cb="cb"
:type="
offchainNetworks.includes(space.network)
? 'space-cover'
: 'space-cover-sx'
"
type="space-cover"
class="object-cover !rounded-none size-full"
/>
<div
v-else
class="bg-cover bg-center w-full h-full"
:style="{
'background-image': `url(${getStampUrl(
offchainNetworks.includes(space.network) ? 'space' : 'space-sx',
space.id,
'space',
`${space.network}:${space.id}`,
50,
getCacheHash(space.avatar)
)}`,
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/components/Ui/InputStamp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function handleFileChange(e: Event) {
:id="definition.default"
:size="80"
class="pointer-events-none !rounded-none group-hover:opacity-80"
type="space-sx"
type="space"
:class="{
'opacity-80': isUploadingImage
}"
Expand Down
9 changes: 1 addition & 8 deletions apps/ui/src/components/Ui/Stamp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { getStampUrl } from '@/helpers/utils';
withDefaults(
defineProps<{
type?:
| 'avatar'
| 'user-cover'
| 'space'
| 'space-cover'
| 'space-sx'
| 'space-cover-sx'
| 'token';
type?: 'avatar' | 'user-cover' | 'space' | 'space-cover' | 'token';
id: string;
size?: number;
width?: number;
Expand Down
22 changes: 9 additions & 13 deletions apps/ui/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
validateAndParseAddress
} from 'starknet';
import { RouteParamsRaw } from 'vue-router';
import { offchainNetworks } from '@/networks';
import { VotingPowerItem } from '@/stores/votingPowers';
import { Choice, Proposal, SpaceMetadata } from '@/types';
import { Choice, NetworkID, Proposal, SpaceMetadata } from '@/types';
import { MAX_SYMBOL_LENGTH } from './constants';
import pkg from '@/../package.json';
import ICCoingecko from '~icons/c/coingecko';
Expand Down Expand Up @@ -475,14 +476,7 @@ export function getCacheHash(value?: string) {
}

export function getStampUrl(
type:
| 'avatar'
| 'user-cover'
| 'space'
| 'space-cover'
| 'space-sx'
| 'space-cover-sx'
| 'token',
type: 'avatar' | 'user-cover' | 'space' | 'space-cover' | 'token',
id: string,
size: number | { width: number; height: number },
hash?: string
Expand All @@ -495,10 +489,12 @@ export function getStampUrl(
}

const cacheParam = hash ? `&cb=${hash}` : '';

const formattedId = ['avatar', 'space-sx', 'space-cover-sx'].includes(type)
? formatAddress(id)
: id;
const [entryNetwork] = id.split(':') as [NetworkID, string];
const isAddress =
type === 'avatar' ||
(['space', 'space-cover'].includes(type) &&
!offchainNetworks.includes(entryNetwork));
const formattedId = isAddress ? formatAddress(id) : id;

return `https://cdn.stamp.fyi/${type}/${formattedId}${sizeParam}${cacheParam}`;
}
Expand Down
5 changes: 2 additions & 3 deletions apps/ui/src/views/Space.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { getCacheHash, getStampUrl } from '@/helpers/utils';
import { offchainNetworks } from '@/networks';
const { setFavicon } = useFavicon();
const { param } = useRouteParser('space');
Expand Down Expand Up @@ -44,8 +43,8 @@ watchEffect(() => {
}
const faviconUrl = getStampUrl(
offchainNetworks.includes(space.value.network) ? 'space' : 'space-sx',
space.value.id,
'space',
`${space.value.network}:${space.value.id}`,
16,
getCacheHash(space.value.avatar)
);
Expand Down

0 comments on commit a6714f0

Please sign in to comment.