Skip to content

Commit

Permalink
add: cancelUrl parameter to pay function
Browse files Browse the repository at this point in the history
  • Loading branch information
ps1dr3x committed Nov 28, 2023
1 parent 2b3df9f commit f4e0709
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/typing/index.ts
Expand Up @@ -41,7 +41,9 @@ export interface IPaymentProps {
challengePeriodExtension?: number;
/** (UI only) A reference for the payment to display */
reference?: string;
/** (UI only) A url to redirect to, when the payment is done or canceled */
/** (UI only) A url to redirect to, when the payment is canceled */
cancelUrl?: string;
/** (UI only) A url to redirect to, when the payment is done */
callbackUrl?: string;
}

Expand Down
10 changes: 4 additions & 6 deletions src/ui/internal/modals/Pay.tsx
Expand Up @@ -53,7 +53,7 @@ export function PayModal(props: IPaymentModalProps) {
} = useTokenInfo(props.paymentProps.tokenAddress);

const closeHandlerRef = useModalCloseHandler(
props.paymentProps?.callbackUrl ? () => {} : onModalClose,
props.paymentProps?.cancelUrl ? () => {} : onModalClose,
);
const [modalTitle, setModalTitle] = React.useState("Payment");
const [paymentStatus, setPaymentStatus] = React.useState<EscrowStatus>(
Expand Down Expand Up @@ -224,16 +224,14 @@ export function PayModal(props: IPaymentModalProps) {
let buttonOnClick;
let buttonCallback = <></>;

if (props.paymentProps?.callbackUrl) {
if (props.paymentProps?.cancelUrl) {
buttonCallback = (
<Button
fullWidth
variant="tertiary"
style={{ marginTop: 15 }}
disabled={isLoadingAnything}
onClick={() =>
(window.location.href = props.paymentProps.callbackUrl)
}
onClick={() => (window.location.href = props.paymentProps?.cancelUrl)}
>
Cancel
</Button>
Expand Down Expand Up @@ -277,7 +275,7 @@ export function PayModal(props: IPaymentModalProps) {
title={modalTitle}
body={<ModalBody />}
footer={<ModalFooter />}
closeable={props.paymentProps?.callbackUrl ? false : true}
closeable={props.paymentProps?.cancelUrl ? false : true}
onClose={onModalClose}
isLoading={isLoadingAnything}
loadingMessage={loadingMessage}
Expand Down

0 comments on commit f4e0709

Please sign in to comment.