Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gRPC gateway routing for affiliate queries #2554

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { LCDClient } from "@osmonauts/lcd";
import { AffiliateInfoRequest, AffiliateInfoResponseSDKType, ReferredByRequest, ReferredByResponseSDKType, AllAffiliateTiersRequest, AllAffiliateTiersResponseSDKType, AffiliateWhitelistRequest, AffiliateWhitelistResponseSDKType } from "./query";
export class LCDQueryClient {
req: LCDClient;

constructor({
requestClient
}: {
requestClient: LCDClient;
}) {
this.req = requestClient;
this.affiliateInfo = this.affiliateInfo.bind(this);
this.referredBy = this.referredBy.bind(this);
this.allAffiliateTiers = this.allAffiliateTiers.bind(this);
this.affiliateWhitelist = this.affiliateWhitelist.bind(this);
}
/* Query AffiliateInfo returns the affiliate info for a given address. */


async affiliateInfo(params: AffiliateInfoRequest): Promise<AffiliateInfoResponseSDKType> {
const endpoint = `dydxprotocol/affiliates/affiliate_info/${params.address}`;
return await this.req.get<AffiliateInfoResponseSDKType>(endpoint);
}
Comment on lines +20 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add input validation and error handling for affiliateInfo

The method should validate the address parameter and handle potential request failures.

 async affiliateInfo(params: AffiliateInfoRequest): Promise<AffiliateInfoResponseSDKType> {
+  if (!params.address || !params.address.trim()) {
+    throw new Error('Address is required');
+  }
   const endpoint = `dydxprotocol/affiliates/affiliate_info/${params.address}`;
-  return await this.req.get<AffiliateInfoResponseSDKType>(endpoint);
+  try {
+    return await this.req.get<AffiliateInfoResponseSDKType>(endpoint);
+  } catch (error) {
+    throw new Error(`Failed to fetch affiliate info: ${error.message}`);
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async affiliateInfo(params: AffiliateInfoRequest): Promise<AffiliateInfoResponseSDKType> {
const endpoint = `dydxprotocol/affiliates/affiliate_info/${params.address}`;
return await this.req.get<AffiliateInfoResponseSDKType>(endpoint);
}
async affiliateInfo(params: AffiliateInfoRequest): Promise<AffiliateInfoResponseSDKType> {
if (!params.address || !params.address.trim()) {
throw new Error('Address is required');
}
const endpoint = `dydxprotocol/affiliates/affiliate_info/${params.address}`;
try {
return await this.req.get<AffiliateInfoResponseSDKType>(endpoint);
} catch (error) {
throw new Error(`Failed to fetch affiliate info: ${error.message}`);
}
}

/* Query ReferredBy returns the affiliate that referred a given address. */


async referredBy(params: ReferredByRequest): Promise<ReferredByResponseSDKType> {
const endpoint = `dydxprotocol/affiliates/referred_by/${params.address}`;
return await this.req.get<ReferredByResponseSDKType>(endpoint);
}
Comment on lines +27 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add input validation and error handling for referredBy

Similar to affiliateInfo, this method needs proper validation and error handling.

 async referredBy(params: ReferredByRequest): Promise<ReferredByResponseSDKType> {
+  if (!params.address || !params.address.trim()) {
+    throw new Error('Address is required');
+  }
   const endpoint = `dydxprotocol/affiliates/referred_by/${params.address}`;
-  return await this.req.get<ReferredByResponseSDKType>(endpoint);
+  try {
+    return await this.req.get<ReferredByResponseSDKType>(endpoint);
+  } catch (error) {
+    throw new Error(`Failed to fetch referral info: ${error.message}`);
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async referredBy(params: ReferredByRequest): Promise<ReferredByResponseSDKType> {
const endpoint = `dydxprotocol/affiliates/referred_by/${params.address}`;
return await this.req.get<ReferredByResponseSDKType>(endpoint);
}
async referredBy(params: ReferredByRequest): Promise<ReferredByResponseSDKType> {
if (!params.address || !params.address.trim()) {
throw new Error('Address is required');
}
const endpoint = `dydxprotocol/affiliates/referred_by/${params.address}`;
try {
return await this.req.get<ReferredByResponseSDKType>(endpoint);
} catch (error) {
throw new Error(`Failed to fetch referral info: ${error.message}`);
}
}

/* Query AllAffiliateTiers returns all affiliate tiers. */


async allAffiliateTiers(_params: AllAffiliateTiersRequest = {}): Promise<AllAffiliateTiersResponseSDKType> {
const endpoint = `dydxprotocol/affiliates/all_affiliate_tiers`;
return await this.req.get<AllAffiliateTiersResponseSDKType>(endpoint);
}
Comment on lines +34 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for list queries

The allAffiliateTiers and affiliateWhitelist methods should include error handling.

 async allAffiliateTiers(_params: AllAffiliateTiersRequest = {}): Promise<AllAffiliateTiersResponseSDKType> {
   const endpoint = `dydxprotocol/affiliates/all_affiliate_tiers`;
-  return await this.req.get<AllAffiliateTiersResponseSDKType>(endpoint);
+  try {
+    return await this.req.get<AllAffiliateTiersResponseSDKType>(endpoint);
+  } catch (error) {
+    throw new Error(`Failed to fetch affiliate tiers: ${error.message}`);
+  }
 }

 async affiliateWhitelist(_params: AffiliateWhitelistRequest = {}): Promise<AffiliateWhitelistResponseSDKType> {
   const endpoint = `dydxprotocol/affiliates/affiliate_whitelist`;
-  return await this.req.get<AffiliateWhitelistResponseSDKType>(endpoint);
+  try {
+    return await this.req.get<AffiliateWhitelistResponseSDKType>(endpoint);
+  } catch (error) {
+    throw new Error(`Failed to fetch affiliate whitelist: ${error.message}`);
+  }
 }

Also applies to: 41-44

/* Query AffiliateWhitelist returns the affiliate whitelist. */


async affiliateWhitelist(_params: AffiliateWhitelistRequest = {}): Promise<AffiliateWhitelistResponseSDKType> {
const endpoint = `dydxprotocol/affiliates/affiliate_whitelist`;
return await this.req.get<AffiliateWhitelistResponseSDKType>(endpoint);
}

}
Loading
Loading