Skip to content

Commit

Permalink
Sale widget/remove expiry endpoint (#1228)
Browse files Browse the repository at this point in the history
Co-authored-by: Jimmy Hardwick <[email protected]>
  • Loading branch information
mimi-imtbl and jwhardwick authored Dec 6, 2023
1 parent 5f0d9c4 commit ce3898b
Showing 1 changed file with 1 addition and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,35 +228,9 @@ export const useSignOrder = (input: SignOrderInput) => {
[provider],
);

const expirePrevSignedOrder = useCallback(async () => {
const reference = signResponse?.transactions
.find((txn) => txn.methodCall.startsWith('execute'))?.params.reference;

if (!reference) return;

try {
const baseUrl = `${PRIMARY_SALES_API_BASE_URL[env]}/${environmentId}/order/expire`;
const response = await fetch(baseUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ reference }),
});

if (!response.ok) {
const { code, message } = (await response.json()) as SignApiError;
throw new Error(code, { cause: message });
}
} catch (e) {
// eslint-disable-next-line no-console
console.warn(`Failed to expire transaction with ref: '${reference}'`, e);
}
}, [signResponse, env, environmentId]);

const sign = useCallback(
async (paymentType: PaymentTypes): Promise<SignResponse | undefined> => {
try {
await expirePrevSignedOrder();

const data: SignApiRequest = {
recipient_address: recipientAddress,
payment_type: paymentType,
Expand Down Expand Up @@ -291,7 +265,7 @@ export const useSignOrder = (input: SignOrderInput) => {
}
return undefined;
},
[items, fromContractAddress, recipientAddress, environmentId, env, provider, expirePrevSignedOrder],
[items, fromContractAddress, recipientAddress, environmentId, env, provider],
);

const execute = async (
Expand Down

0 comments on commit ce3898b

Please sign in to comment.