-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5921 payment flow modification (#1113)
* chore(marketplace): Bump packages * feat(marketplace): A modal with cert holder * chore(marketplace): Remove comment * fix(marketplace): Make important text bold and remove unused component * fix(marketplace): Add @rollup/rollup-linux-x64-gnu as optional dep * feat(marketplace): Add a second call to retire credits after they are bought * fix(marketplace): Sloppy previous commit * fix(marketplace): Retire credits immediately properly
- Loading branch information
Showing
8 changed files
with
356 additions
and
462 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
frontend/marketplace/src/components/CertificateHolderModal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<script setup lang="ts"> | ||
import { ref, computed } from "vue"; | ||
import Modal from "@/components/ui/Modal.vue"; | ||
import PrimaryButton from "@/components/ui/PrimaryButton.vue"; | ||
const emit = defineEmits(["continue"]); | ||
const baseModal = ref<HTMLDialogElement | null>(null); | ||
const certificateHolder = ref<string>(""); | ||
const isCertificateHolderValid = computed<boolean>(() => { | ||
return ( | ||
certificateHolder.value.length > 0 && certificateHolder.value.length < 31 | ||
); | ||
}); | ||
const isCertificateHolderTooLong = computed<boolean>(() => { | ||
return certificateHolder.value.length > 30; | ||
}); | ||
const handleOpenModal = () => { | ||
baseModal.value?.show(); | ||
}; | ||
const handleContinue = () => { | ||
emit("continue", certificateHolder.value); | ||
baseModal.value?.close(); | ||
}; | ||
defineExpose({ | ||
show: handleOpenModal, | ||
}); | ||
</script> | ||
<template> | ||
<Modal ref="baseModal" title="Certificate holder"> | ||
<template v-slot:body> | ||
<p class="py-4"> | ||
Provide an individual or company name that is going to be used for the | ||
Plastic Credit Offset Certificate. | ||
<b>Mind that this cannot be changed later.</b> | ||
</p> | ||
<div> | ||
<input | ||
type="text" | ||
placeholder="Certificate holder name" | ||
class="input input-bordered w-full text-black" | ||
v-model="certificateHolder" | ||
/> | ||
<div class="label" v-if="isCertificateHolderTooLong"> | ||
<span class="label-text-alt text-white" | ||
>Name can not be more than 30 characters.</span | ||
> | ||
</div> | ||
</div> | ||
</template> | ||
<template v-slot:actions> | ||
<PrimaryButton | ||
@click.prevent="handleContinue" | ||
:disabled="!isCertificateHolderValid" | ||
>Continue</PrimaryButton | ||
> | ||
</template> | ||
</Modal> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<script setup lang="ts"> | ||
import { ref, defineExpose } from "vue"; | ||
interface Props { | ||
title?: string; | ||
} | ||
const props = defineProps<Props>(); | ||
const isOpen = ref(false); | ||
const dialog = ref<HTMLDialogElement>(); | ||
const show = () => { | ||
isOpen.value = true; | ||
dialog.value?.showModal(); | ||
}; | ||
const close = () => { | ||
isOpen.value = false; | ||
dialog.value?.close(); | ||
}; | ||
defineExpose({ | ||
show, | ||
close, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<dialog ref="dialog" id="modal_dialog" class="modal"> | ||
<div class="modal-box bg-modalBackground"> | ||
<form method="dialog"> | ||
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"> | ||
✕ | ||
</button> | ||
</form> | ||
<h3 v-if="props.title" class="font-bold text-lg">{{ props.title }}</h3> | ||
<slot name="body" /> | ||
<div class="modal-action"> | ||
<slot name="actions"></slot> | ||
</div> | ||
</div> | ||
</dialog> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script setup lang="ts"> | ||
import type { ButtonHTMLAttributes, ReservedProps } from "vue"; | ||
interface Props | ||
extends /* @vue-ignore */ ButtonHTMLAttributes, | ||
/* @vue-ignore */ ReservedProps {} | ||
const props = defineProps<Props>(); | ||
</script> | ||
<template> | ||
<button | ||
v-bind="props" | ||
class="btn btn-ghost text-white btn-block normal-case bg-greenPrimary hover:bg-greenDark text-title24 lg:text-title32 lg:btn-lg p-0 px-12 font-normal disabled:bg-lightGray disabled:text-white" | ||
> | ||
<slot /> | ||
</button> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ref } from "vue"; | ||
import { | ||
empowerchain, | ||
getSigningTM37EmpowerchainClient, | ||
} from "@empower-plastic/empowerjs"; | ||
import { getWallet } from "@/utils/wallet-utils"; | ||
import { CHAIN_ID, RPC_ENDPOINT } from "@/config/config"; | ||
|
||
const { retireCredits } = | ||
empowerchain.plasticcredit.MessageComposer.withTypeUrl; | ||
|
||
export const useRetireCredits = () => { | ||
const loading = ref(false); | ||
|
||
const handleRetireCredits = async ( | ||
amount: any, // Typing, Johannes?! | ||
address: string, | ||
denom: string, | ||
retirererName: string, | ||
onSuccess: () => void, | ||
additionalInfo?: string, | ||
) => { | ||
try { | ||
loading.value = true; | ||
const retireCreditsMsg = retireCredits({ | ||
owner: address, | ||
denom: denom, | ||
amount: amount as bigint, | ||
retiringEntityName: retirererName, | ||
retiringEntityAdditionalData: additionalInfo ?? "", | ||
}); | ||
const wallet = getWallet(); | ||
const offlineSigner = wallet.getOfflineSigner(CHAIN_ID); | ||
const chainClient = await getSigningTM37EmpowerchainClient({ | ||
rpcEndpoint: RPC_ENDPOINT, | ||
signer: offlineSigner, | ||
}); | ||
const fee = { | ||
amount: [{ amount: "100000", denom: "umpwr" }], | ||
gas: "200000", | ||
}; | ||
const response = await chainClient.signAndBroadcast( | ||
address, | ||
[retireCreditsMsg], | ||
fee, | ||
); | ||
if (response && !response.code) { | ||
loading.value = false; | ||
onSuccess(); | ||
} else { | ||
throw new Error("Retire credits failed " + response.rawLog); | ||
} | ||
} catch (error) { | ||
loading.value = false; | ||
throw error; | ||
} | ||
}; | ||
|
||
return { | ||
handleRetireCredits, | ||
loading, | ||
}; | ||
}; |