From db96aca83fc40a1b215c8eebfc938c31d8038076 Mon Sep 17 00:00:00 2001 From: whilefoo Date: Mon, 11 Dec 2023 12:14:47 +0100 Subject: [PATCH] feat: nft rewards --- .../supabase/helpers/tables/settlement.ts | 8 +++++--- src/adapters/supabase/helpers/tables/wallet.ts | 10 ++++++---- src/handlers/pricing/pricing-label.ts | 16 ++++++++++------ src/types/configuration-types.ts | 1 + 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/adapters/supabase/helpers/tables/settlement.ts b/src/adapters/supabase/helpers/tables/settlement.ts index 98a30502b..8cc979535 100644 --- a/src/adapters/supabase/helpers/tables/settlement.ts +++ b/src/adapters/supabase/helpers/tables/settlement.ts @@ -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); @@ -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); @@ -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); @@ -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"); @@ -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); diff --git a/src/adapters/supabase/helpers/tables/wallet.ts b/src/adapters/supabase/helpers/tables/wallet.ts index d650c9a3c..9b0c4347a 100644 --- a/src/adapters/supabase/helpers/tables/wallet.ts +++ b/src/adapters/supabase/helpers/tables/wallet.ts @@ -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, @@ -87,12 +86,13 @@ 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; @@ -100,6 +100,7 @@ export class Wallet extends Super { 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) { @@ -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; diff --git a/src/handlers/pricing/pricing-label.ts b/src/handlers/pricing/pricing-label.ts index d371fdbce..2d001f88a 100644 --- a/src/handlers/pricing/pricing-label.ts +++ b/src/handlers/pricing/pricing-label.ts @@ -152,10 +152,14 @@ async function addPriceLabelToIssue(context: Context, targetPriceLabel: string, export async function labelExists(context: Context, name: string): Promise { 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; + } } diff --git a/src/types/configuration-types.ts b/src/types/configuration-types.ts index 0246c7000..4914e3c62 100644 --- a/src/types/configuration-types.ts +++ b/src/types/configuration-types.ts @@ -78,6 +78,7 @@ const botConfigSchema = strictObject( setLabel: T.Boolean({ default: true }), fundExternalClosedIssue: T.Boolean({ default: true }), }), + isNftRewardEnabled: T.Boolean({ default: false }), }), timers: strictObject({