Skip to content

Commit

Permalink
Merge pull request #93 from crowdtainer/201123
Browse files Browse the repository at this point in the history
Added missing order confirmation status handling
  • Loading branch information
tfalencar authored Nov 20, 2023
2 parents 097e4e7 + f459ee9 commit b3dd88b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/lib/Database/schemes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// key schemes

export const deliveryRequestsKey = 'deliveryRequests:v1';

export function deliveryVoucherKey(chainId: number, vouchers721address: string, voucherId: number): string {
return `deliveryRequest:v1:${chainId}:${vouchers721address}:${voucherId}`;
}
3 changes: 1 addition & 2 deletions src/lib/DeliveryAddress.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@
<p class="text-secondary text-xl">Success !</p>
<br />
<p>
Thank you. We have received your delivery address and in a few minutes you should receive an
invoice by Email as a final confirmation.
Thank you for providing your delivery address. A confirmation email will be sent shortly to confirm receipt.
</p>
</div>
{:else}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/DetailedTokenIdState.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<p>• Next step: &nbsp;Please proceed to <b>Checkout</b> to complete your order.</p>
{:else if orderStatus !== undefined && orderStatus === OrderStatus.DeliveryAddressReceived}
<p>• Next step: &nbsp;Your order has been received and is being processed.</p>
{:else if orderStatus !== undefined && orderStatus === OrderStatus.InvoiceSent}
<p>• Your order has been confirmed. The invoice and delivery status will be sent by email.</p>
{/if}
{/if}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/deliveryAddressAPI/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';

import { Vouchers721__factory } from "../typechain/factories/Vouchers721__factory";
import { deliveryVoucherKey } from "$lib/Database/schemes";
import { deliveryRequestsKey, deliveryVoucherKey } from "$lib/Database/schemes";
import { provider } from '$lib/ethersCalls/provider';
import { loadTokenURIRepresentation, type TokenURIObject, type Description } from "$lib/Converters/tokenURI.js";
import { MockERC20__factory, Crowdtainer__factory } from "../typechain/index.js";
Expand Down Expand Up @@ -346,7 +346,7 @@ export const POST: RequestHandler = async ({ request }) => {
.hset(`${key}:billingAddress`, deliveryDetails.billingAddress) // Save billing address
.set(`${key}:quantities`, JSON.stringify(quantities)) // Save order quantities
.set(`${key}:discount`, JSON.stringify(toHuman(userDiscount.unwrap(), decimals.unwrap()))) // Save discount value
.lpush("deliveryRequests:v1", key) // Add its id to the work queue
.lpush(deliveryRequestsKey, key) // Add its id to the work queue
.exec();

} catch (e) {
Expand Down
11 changes: 8 additions & 3 deletions src/routes/orderDetailsAPI/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RequestHandler } from './$types';

import { error } from '@sveltejs/kit';

import { deliveryVoucherKey } from "$lib/Database/schemes";
import { deliveryRequestsKey, deliveryVoucherKey } from "$lib/Database/schemes";

// Monads
import { type Result, Ok, Err } from "@sniptt/monads";
Expand All @@ -18,9 +18,14 @@ async function fetchData(chainId: number, vouchers721Address: string, voucherId:

let key = deliveryVoucherKey(chainId, vouchers721Address, voucherId);

if (await redis.lpos('deliveryRequests:v1', key) !== null) {
if (await redis.lpos(deliveryRequestsKey, key) !== null) {
return Ok(OrderStatus.DeliveryAddressReceived);
} else {
}
else {
let orderCreated = await redis.hexists(`${key}:orderCreated`, 'epochTimeInMilliseconds')
if(orderCreated) {
return Ok(OrderStatus.InvoiceSent);
}
return Ok(OrderStatus.WaitingForDeliveryAddress);
}
} catch (error) {
Expand Down

0 comments on commit b3dd88b

Please sign in to comment.