Skip to content

Commit

Permalink
♻️ (shopify/index.ts & validators.ts): Refactor Shopify integration f…
Browse files Browse the repository at this point in the history
…or clarity and robustness

- Improve error handling by adding braces for better readability
- Log resultParams and organizerId for debugging purposes
- Ensure customerId is treated as a string for consistency
- Convert contractAddress and ownerAddress to lowercase for standardization

♻️ (loyalty-card/index.ts): Refactor loyalty card minting logic
- Pass ownerAddress explicitly to maintain consistency and improve readability
- Add ownerAddress to the minting object for completeness
  • Loading branch information
sebpalluel committed Apr 30, 2024
1 parent cc9f6af commit 8048a53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 6 additions & 5 deletions libs/integrations/external-api-handlers/src/lib/shopify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export class ShopifyWebhookAndApiHandler extends BaseWebhookAndApiHandler {
): Promise<RequestTypeToValidator[T]> {
const deserializedParams = this.deserializeParams(params);
const validator = requestTypeValidators[requestType];

if (!validator) {
throw new Error(`Validator for request type ${requestType} not found.`);
}
Expand All @@ -97,8 +96,9 @@ export class ShopifyWebhookAndApiHandler extends BaseWebhookAndApiHandler {
const queryHash = this.populateQueryHash(searchParams);
const resultParams = this.populateResultParams(searchParams);
const signature = searchParams.get('signature');
if (!signature || !this.verifyRequestSignature(queryHash, signature))
if (!signature || !this.verifyRequestSignature(queryHash, signature)) {
throw new Error('Invalid signature');
}
const res = await adminSdk.GetShopifyDomain({
domain: shop,
});
Expand All @@ -121,6 +121,7 @@ export class ShopifyWebhookAndApiHandler extends BaseWebhookAndApiHandler {
'Not Authorized: ' + getErrorMessage(error),
);
});
console.log({ resultParams, organizerId });
const validatedParams = await this.serializeAndValidateParams(
requestType,
resultParams,
Expand Down Expand Up @@ -194,7 +195,7 @@ export class ShopifyWebhookAndApiHandler extends BaseWebhookAndApiHandler {
);
const shopifyCustomer = await this.getShopifyCustomer({
organizerId,
customerId,
customerId: customerId.toString(),
});
if (!shopifyCustomer) {
throw new BadRequestError('Customer not found');
Expand All @@ -208,8 +209,8 @@ export class ShopifyWebhookAndApiHandler extends BaseWebhookAndApiHandler {
// Attempt to mint loyalty card
await loyaltyCardSdk
.mint({
contractAddress,
ownerAddress,
contractAddress: contractAddress.toLowerCase(),
ownerAddress: ownerAddress.toLowerCase(),
chainId: getCurrentChain().chainIdHex,
organizerId,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const MintLoyaltyCardWithPasswordParams = z.object({

export const MintLoyaltyCardWithCustomerIdParams = z.object({
ownerAddress: z.string(),
customerId: z.string(),
customerId: z.string().or(z.number()),
});

export const HasLoyaltyCardParams = z.object({
Expand Down
8 changes: 6 additions & 2 deletions libs/nft/loyalty-card/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ export class LoyaltyCardNftWrapper {
await this.adminSdk.GetLoyaltyCardNftContractByContractAddress(props);
return res.loyaltyCardNftContract?.[0];
}
async mint(props: MintProps) {
const loyaltyCard = await this.getLoyaltyCardOwnedByAddress(props);
async mint({ ownerAddress, ...props }: MintProps) {
const loyaltyCard = await this.getLoyaltyCardOwnedByAddress({
...props,
ownerAddress,
});
if (
loyaltyCard &&
(loyaltyCard.status !== NftStatus_Enum.Burned ||
Expand All @@ -57,6 +60,7 @@ export class LoyaltyCardNftWrapper {
object: {
loyaltyCardId,
status: NftStatus_Enum.Confirmed,
ownerAddress,
...props,
},
});
Expand Down

0 comments on commit 8048a53

Please sign in to comment.