-
Notifications
You must be signed in to change notification settings - Fork 122
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
/* 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||
/* 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
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.
📝 Committable suggestion