Skip to content

Commit

Permalink
feat: nft rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Dec 11, 2023
1 parent 07ce845 commit db96aca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/adapters/supabase/helpers/tables/settlement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Settlement extends Super {
const { data: debitInsertData, error: debitError } = await this.supabase
.from("debits")
.insert(debitData)
.select("*")
.select()
.maybeSingle();

if (debitError) throw new Error(debitError.message);
Expand All @@ -77,6 +77,7 @@ export class Settlement extends Super {
const { data: settlementInsertData, error: settlementError } = await this.supabase
.from("settlements")
.insert(settlementData)
.select()
.maybeSingle();

if (settlementError) throw new Error(settlementError.message);
Expand All @@ -99,7 +100,7 @@ export class Settlement extends Super {
const { data: creditInsertData, error: creditError } = await this.supabase
.from("credits")
.insert(creditData)
.select("*")
.select()
.maybeSingle();

if (creditError) throw new Error(creditError.message);
Expand All @@ -121,7 +122,7 @@ export class Settlement extends Super {
beneficiary_id: userId,
};

const permitResult = await this.supabase.from("permits").insert(permitData).select("*").maybeSingle();
const permitResult = await this.supabase.from("permits").insert(permitData).select().maybeSingle();

if (permitResult.error) throw new Error(permitResult.error.message);
if (!permitResult.data) throw new Error("Permit not inserted");
Expand Down Expand Up @@ -149,6 +150,7 @@ export class Settlement extends Super {
const { data: settlementInsertData, error: settlementError } = await this.supabase
.from("settlements")
.insert(settlementData)
.select()
.maybeSingle();

if (settlementError) throw new Error(settlementError.message);
Expand Down
10 changes: 6 additions & 4 deletions src/adapters/supabase/helpers/tables/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ export class Wallet extends Super {
| ProbotContext<"issue_comment.edited">["payload"];

const userData = await this._getUserData(payload);
const registeredWalletData = await this._getRegisteredWalletData(userData);

const locationMetaData = this._getLocationMetaData(payload);

if (!registeredWalletData) {
if (!userData.wallet_id) {
await this._registerNewWallet({
address,
locationMetaData,
payload,
});
} else {
const registeredWalletData = await this._getRegisteredWalletData(userData);
await this._updateExistingWallet({
address,
locationMetaData,
Expand Down Expand Up @@ -87,19 +86,21 @@ export class Wallet extends Super {
const { data: locationData, error: locationError } = (await this.supabase
.from("locations")
.insert(locationMetaData)
.select()
.single()) as { data: LocationRow; error: PostgrestError | null };

if (locationError) {
throw new Error(locationError.message);
}

console.log(locationData);
// Get the ID of the inserted location
const locationId = locationData.id;

// Register the new user with the location ID
const { data: userData, error: userError } = await this.supabase
.from("users")
.insert([{ id: user.id, location_id: locationId /* other fields if necessary */ }])
.select()
.single();

if (userError) {
Expand Down Expand Up @@ -167,6 +168,7 @@ export class Wallet extends Super {
const { data: walletInsertData, error: walletInsertError } = await this.supabase
.from("wallets")
.insert(newWallet)
.select()
.single();

if (walletInsertError) throw walletInsertError;
Expand Down
16 changes: 10 additions & 6 deletions src/handlers/pricing/pricing-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ async function addPriceLabelToIssue(context: Context, targetPriceLabel: string,

export async function labelExists(context: Context, name: string): Promise<boolean> {
const payload = context.event.payload as Payload;
const res = await context.event.octokit.rest.issues.getLabel({
owner: payload.repository.owner.login,
repo: payload.repository.name,
name,
});
return res.status === 200;
try {
await context.event.octokit.rest.issues.getLabel({
owner: payload.repository.owner.login,
repo: payload.repository.name,
name,
});
return true;
} catch (error) {
return false;
}
}
1 change: 1 addition & 0 deletions src/types/configuration-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const botConfigSchema = strictObject(
setLabel: T.Boolean({ default: true }),
fundExternalClosedIssue: T.Boolean({ default: true }),
}),
isNftRewardEnabled: T.Boolean({ default: false }),
}),

timers: strictObject({
Expand Down

0 comments on commit db96aca

Please sign in to comment.