Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5800 plastic credit v2 market place related issues #1103

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions frontend/marketplace/src/components/AuctionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { convertIPFStoHTTPS } from "@/utils/utils";
import auctionCard from "@/assets/auctionCard.png";
import { formatDenom } from "@/utils/wallet-utils";
import { onMounted, ref } from "vue";
import CustomImage from "@/components/CustomImage.vue";
export interface AuctionCardProps {
auctionData: any;
}
Expand All @@ -16,12 +17,12 @@ onMounted(async () => {
</script>
<template>
<div class="bg-lightBlack rounded-lg md:rounded-sm">
<img
class="max-h-[250px] w-full rounded-lg"
<CustomImage
image-class="max-h-[250px] w-full rounded-lg"
:src="
convertIPFStoHTTPS(
auctionData?.creditCollection?.creditData?.nodes[0].mediaFiles
?.nodes[0].url
?.nodes[0].url,
) || auctionCard
"
/>
Expand Down
11 changes: 6 additions & 5 deletions frontend/marketplace/src/components/AuctionResultsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import auctionCard from "@/assets/auctionCard.png";
import { getDetailsList } from "@/utils/utils";
import { formatDenom } from "@/utils/wallet-utils";
import { onMounted, ref } from "vue";
import CustomImage from "@/components/CustomImage.vue";

export interface AuctionResultsCardProps {
cardData: MarketplaceListing & {
Expand All @@ -23,12 +24,12 @@ onMounted(async () => {
<div
class="bg-auctionBackground md:bg-lightBlack rounded-lg font-Inter text-white my-5 md:p-3 md:grid md:grid-cols-5 min-h-[180px]"
>
<img
class="h-full col-span-1 rounded-sm"
<CustomImage
:src="
getDetailsList(cardData.creditCollection.creditData.nodes)
.thumbnailUrl || auctionCard
"
image-class="max-h-[200px] w-full rounded-sm"
/>

<!-- Details for Mobile UI-->
Expand Down Expand Up @@ -73,7 +74,7 @@ onMounted(async () => {
<ul class="list-disc ml-6">
<li
v-for="material in getDetailsList(
cardData.creditCollection.creditData.nodes
cardData.creditCollection.creditData.nodes,
).material"
:key="material.key"
>
Expand All @@ -87,7 +88,7 @@ onMounted(async () => {
<ul class="list-disc ml-6">
<li
v-for="location in getDetailsList(
cardData.creditCollection.creditData.nodes
cardData.creditCollection.creditData.nodes,
).location"
:key="location"
>
Expand All @@ -100,7 +101,7 @@ onMounted(async () => {
<ul class="list-disc ml-6">
<li
v-for="applicant in getDetailsList(
cardData.creditCollection.creditData.nodes
cardData.creditCollection.creditData.nodes,
).applicant"
:key="applicant"
>
Expand Down
13 changes: 12 additions & 1 deletion frontend/marketplace/src/components/BuyButton.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<script setup lang="ts">
import { computed } from "vue";
import { useAuth } from "@/stores/auth";
import { isValidCreditAmount } from "@/utils/utils";
export interface BuyButtonProps {
showButtonSpinner: boolean;
insufficientBalance: boolean;
coinFormatted: string;
handleCardPayment: () => void;
handleBuyCredits: () => void;
isWalletConnected: boolean;
availableCredits: number;
buyingCreditAmount: number;
}
const props = defineProps<BuyButtonProps>();

Expand All @@ -19,13 +22,18 @@ enum BuyButtonState {
ENABLED_CARD = "enabled_card",
ENABLED_WALLET = "enabled_wallet",
LOADING = "loading",
INVALID_CREDIT = "invalid_credit",
}

const buttonState = computed<BuyButtonState>(() => {
if (props.showButtonSpinner) {
return BuyButtonState.LOADING;
}

if (!isValidCreditAmount(props.buyingCreditAmount, props.availableCredits)) {
return BuyButtonState.INVALID_CREDIT;
}

if (isAuthenticated.value) {
return BuyButtonState.ENABLED_CARD;
}
Expand Down Expand Up @@ -53,6 +61,8 @@ const buttonText = computed(() => {
return "Log in to pay";
case BuyButtonState.DISABLED:
return "Insufficient balance";
case BuyButtonState.INVALID_CREDIT:
return "Invalid credit";
default:
return "Unknown state";
}
Expand All @@ -74,7 +84,8 @@ const buttonHandler = computed<(() => void) | undefined>(() => {
const isDisabled = computed(
() =>
buttonState.value === BuyButtonState.DISABLED ||
buttonState.value === BuyButtonState.LOADING,
buttonState.value === BuyButtonState.LOADING ||
buttonState.value === BuyButtonState.INVALID_CREDIT,
);

const buttonsCssClasses = `
Expand Down
2 changes: 2 additions & 0 deletions frontend/marketplace/src/components/BuyCredits.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ const handleCardPayment = async () => {
:handle-buy-credits="handleBuyCredits"
:handle-card-payment="handleCardPayment"
:is-wallet-connected="isWalletConnected"
:available-credits="availableCredits"
:buying-credit-amount="amount"
></BuyButton>
</div>
</div>
Expand Down
33 changes: 33 additions & 0 deletions frontend/marketplace/src/components/CustomImage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script setup lang="ts">
import AuctionCard from "../assets/auctionCard.png";
export interface CustomImageProps {
src: string;
imageClass: string;
fallbackImageSrc?: string;
}

const props = defineProps<CustomImageProps>();
const emits = defineEmits(["onImageClick"]);
const defaultImage = AuctionCard;
const handleClick = () => {
emits("onImageClick");
};

const handleError = (event: Event) => {
const img = event.target as HTMLImageElement;

if (props.fallbackImageSrc) {
img.src = props.fallbackImageSrc;
} else {
img.src = defaultImage;
}
};
</script>
<template>
<img
:class="imageClass || 'rounded-sm h-[200px] w-[200px]'"
v-bind="props"
@click="handleClick"
@error="handleError"
PiranavanShanmugavadivelu marked this conversation as resolved.
Show resolved Hide resolved
/>
</template>
6 changes: 5 additions & 1 deletion frontend/marketplace/src/components/ImageCarousel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { Carousel, Slide, Navigation } from "vue3-carousel";
import "vue3-carousel/dist/carousel.css";
import CustomImage from "@/components/CustomImage.vue";

export interface ImageCarouselProps {
imageArray: string[];
Expand All @@ -11,7 +12,10 @@ defineProps<ImageCarouselProps>();
<template>
<Carousel>
<Slide v-for="url in imageArray" :key="url">
<img class="min-h-48 max-h-[200px] w-full rounded-lg" :src="url" />
<CustomImage
:src="url"
image-class="min-h-48 max-h-[200px] w-full rounded-lg"
/>
</Slide>
<template #addons>
<Navigation />
Expand Down
13 changes: 7 additions & 6 deletions frontend/marketplace/src/components/ImageGallery.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import "vue3-carousel/dist/carousel.css";
import { ref, watch } from "vue";
import CustomImage from "@/components/CustomImage.vue";

export interface ImageGalleryProps {
imageArray: string[];
Expand All @@ -13,7 +14,7 @@ watch(
() => props.imageArray,
(newValue) => {
activeImageURL.value = newValue[0];
}
},
);

const handleActiveImage = (url: string) => {
Expand All @@ -23,9 +24,9 @@ const handleActiveImage = (url: string) => {
<template>
<div class="grid grid-cols-6 gap-5 max-h-[500px] my-5 w-full">
<div class="col-span-4 w-full">
<img
class="rounded-sm h-[500px] w-full object-none"
<CustomImage
:src="activeImageURL"
image-class="rounded-sm h-[500px] w-full object-none"
/>
</div>
<div class="max-h-[500px] px-3 col-span-2 overflow-auto">
Expand All @@ -36,12 +37,12 @@ const handleActiveImage = (url: string) => {
<img src="../assets/scrollBottomIcon.svg" />
</button>
<div class="grid grid-cols-2 gap-5">
<img
class="rounded-sm h-[150px] w-[200px] cursor-pointer"
<CustomImage
@on-image-click="handleActiveImage(url)"
PiranavanShanmugavadivelu marked this conversation as resolved.
Show resolved Hide resolved
:src="url"
image-class="rounded-sm h-[150px] w-[200px] cursor-pointer"
v-for="url in imageArray"
:id="url"
@click="handleActiveImage(url)"
:key="url"
/>
</div>
Expand Down
23 changes: 15 additions & 8 deletions frontend/marketplace/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const getDetailsList = (data: any) => {
const uniqueMaterialArray = materialArray.filter(
(obj, index, self) =>
index ===
self.findIndex((o) => o.key === obj.key && o.value === obj.value)
self.findIndex((o) => o.key === obj.key && o.value === obj.value),
);

return {
Expand All @@ -68,7 +68,7 @@ export const addTextWithSpacing = (
text: string,
x: number,
y: number,
spacing: number
spacing: number,
) => {
for (let i = 0; i < text.length; i++) {
const currentLetter = text[i];
Expand All @@ -84,12 +84,12 @@ export const addTextWithSpacing = (
export const calculateTextProperties = (
name: string,
baseXPos: number = 163,
baseFontSize: number = 50
baseFontSize: number = 50,
): { xPos: number; fontSize: number } => {
const nameLength = name.length;

let stepSize = 0;
let charsPerStep = 1;
const charsPerStep = 1;
let fontSize = baseFontSize;
if (nameLength < 15) {
stepSize = 4;
Expand All @@ -105,16 +105,16 @@ export const calculateTextProperties = (
}
const steps = Math.floor((nameLength - 3) / charsPerStep);

let xPos = baseXPos - steps * stepSize;
const xPos = baseXPos - steps * stepSize;

return { xPos, fontSize };
}
};
export const calculateXPosition = (
text: string,
basePosition: number = 179,
capitalStep: number = 1.5,
otherStep: number = 1,
numberStep: number = 1.4
numberStep: number = 1.4,
): number => {
let currentPosition = basePosition;

Expand All @@ -130,8 +130,15 @@ export const calculateXPosition = (
}

return currentPosition;
}
};

export const ipfsToHttpsProtocol = (url: string) => {
return url.replace("ipfs://", "https://ipfs.empowerchain.io/ipfs/");
};

export const isValidCreditAmount = (
amount: number,
available: number,
): boolean => {
return amount > 0 && Number.isInteger(amount) && amount <= available;
};