Skip to content

Commit

Permalink
revision
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Sep 13, 2024
1 parent 7d36faa commit b68f364
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ class AffiliatesController extends Controller {
async getMetadata(
@Query() address: string,
): Promise<AffiliateMetadataResponse> {
const [walletRow, referredUserRows] = await Promise.all([
const [walletRow, referredUserRows, subaccountRows] = await Promise.all([
WalletTable.findById(address),
AffiliateReferredUsersTable.findByAffiliateAddress(address),
SubaccountTable.findAll(
{
address,
subaccountNumber: 0,
},
[],
),
]);

// Check that the address exists
Expand All @@ -54,21 +61,14 @@ class AffiliatesController extends Controller {
const isVolumeEligible = Number(walletRow.totalVolume) >= config.VOLUME_ELIGIBILITY_THRESHOLD;
const isAffiliate = referredUserRows !== undefined ? referredUserRows.length > 0 : false;

// Get referral code (subaccount 0 username)
const subaccountRows = await SubaccountTable.findAll(
{
address,
subaccountNumber: 0,
},
[],
);
// No need to check subaccountRows.length > 1 as subaccountNumber is unique for an address
if (subaccountRows.length === 0) {
// error logging will be performed by handleInternalServerError
throw new UnexpectedServerError(`Subaccount 0 not found for address ${address}`);
}
const subaccountId = subaccountRows[0].id;

// Get subaccount0 username, which is the referral code
const usernameRows = await SubaccountUsernamesTable.findAll(
{
subaccountId: [subaccountId],
Expand Down

0 comments on commit b68f364

Please sign in to comment.