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

implement ip info and send supabase #46

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@radix-ui/react-visually-hidden": "^1.1.0",
"@starknet-react/chains": "^0.1.7",
"@starknet-react/core": "2.9.0",
"@supabase/supabase-js": "^2.45.4",
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Supabase Dependency Version Update Recommended

The dependency @supabase/supabase-js is currently set to version "^2.45.4" in client/package.json.

This version is not the latest as of April 2024. Consider updating to the most recent stable version to incorporate the latest features and important bug fixes.

🔗 Analysis chain

New dependency added: @supabase/supabase-js

The addition of the Supabase JavaScript client library suggests that the project is now integrating with Supabase, a Backend-as-a-Service (BaaS) platform. This aligns with the PR title "implement ip info and send supabase".

A few points to consider:

  1. Ensure that the decision to use Supabase has been approved by the team and aligns with the project's architecture and data management strategy.
  2. The version ^2.45.4 allows for compatible updates. As of my knowledge cutoff, this is not the latest version. Consider updating to the latest stable version for potential bug fixes and new features.
  3. Verify that this addition doesn't conflict with any existing backend solutions or data management practices in the project.
  4. Remember to update any relevant documentation to reflect this new integration.

To ensure this change doesn't introduce any conflicts, please run the following command and verify there are no warnings or errors:

This will install the new dependency and check its placement in the dependency tree.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

npm install && npm ls @supabase/supabase-js

Length of output: 84


Script:

#!/bin/bash
# Check if @supabase/supabase-js is listed in dependencies and retrieve its version
if command -v jq >/dev/null 2>&1; then
  jq '.dependencies["@supabase/supabase-js"]' client/package.json
else
  grep '"@supabase/supabase-js"' client/package.json
fi

Length of output: 91

"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
Expand Down
65 changes: 64 additions & 1 deletion client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/src/dojo/systems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function systems({
});

notify(successMessage, transaction);
return transaction_hash;
} catch (error: any) {
console.error("Error executing transaction:", error);
if (!error?.message) {
Expand Down Expand Up @@ -138,7 +139,7 @@ export function systems({
};

const start = async ({ account, ...props }: SystemTypes.Start) => {
await handleTransaction(
return await handleTransaction(
account,
() => client.play.start({ account, ...props }),
"Game has been started.",
Expand Down
21 changes: 20 additions & 1 deletion client/src/ui/actions/Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createFaucetClaimHandler } from "@/utils/faucet";
import { useContract } from "@starknet-react/core";
import { erc20ABI } from "@/utils/erc20";
import { useCredits } from "@/hooks/useCredits";
import supabase from "@/utils/supabase";

interface BalanceData {
balance: {
Expand Down Expand Up @@ -105,8 +106,9 @@ export const Start: React.FC<StartProps> = ({ mode, handleGameMode }) => {
proof_verify_hint,
beta,
} = await fetchVrfData();
//send to supabase

await start({
const transactionHash = await start({
account: account as Account,
mode: new Mode(mode).into(),
price:
Expand All @@ -121,6 +123,23 @@ export const Start: React.FC<StartProps> = ({ mode, handleGameMode }) => {
sqrt_ratio_hint: proof_verify_hint,
beta: beta,
});

if (import.meta.env.VITE_SEND_TO_SUPABASE) {
try {
const { error } = await supabase.functions.invoke("zkube-payment", {
body: {
timestamp: new Date().toISOString(),
transactionHash: transactionHash,
},
});

if (error) {
console.error("Failed to send data to Supabase", error);
}
} catch (error) {
console.error("Error sending data to Supabase:", error);
}
}
handleGameMode();
} finally {
setIsLoading(false);
Expand Down
12 changes: 12 additions & 0 deletions client/src/utils/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createClient } from "@supabase/supabase-js";

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
Comment on lines +3 to +4
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider adding error handling for missing environment variables

While the environment variables are correctly accessed using import.meta.env, there's no error handling if these variables are not set. This could lead to runtime errors if the Supabase URL or key is missing.

Consider adding a check and throwing an error if either variable is undefined:

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseKey = import.meta.env.VITE_SUPABASE_ANON_KEY;

if (!supabaseUrl || !supabaseKey) {
  throw new Error('Missing Supabase environment variables');
}


if (import.meta.env.VITE_SEND_TO_SUPABASE && (!supabaseUrl || !supabaseKey)) {
throw new Error("Missing Supabase environment variables");
}

const supabase = createClient(supabaseUrl, supabaseKey);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding error handling for Supabase client creation

While the Supabase client creation is correct, it's advisable to add error handling to catch any potential issues during the client initialization process.

Consider wrapping the client creation in a try-catch block:

let supabase;
try {
  supabase = createClient(supabaseUrl, supabaseKey);
} catch (error) {
  console.error("Failed to initialize Supabase client:", error);
  // Optionally, you can re-throw the error or handle it as needed
  throw error;
}


export default supabase;
Loading