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

Feature: Implement wallet connection for Stellar #77

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

sotoJ24
Copy link

@sotoJ24 sotoJ24 commented Jan 27, 2025

7️⃣ Create a Pull Request for issue #52 (PR)


! Changes

  • Add Stellar Testnet and Stellar Mainnet to configs/networks.json with the new "chain" field

  • Update pages/verify/[discordServerId]/[discordMemberId]/[customLink].tsx

  • Create separate reusable functions/components for starknetWallet and stellarWallet

Thank you for review this PR ✨

close: #52

@sotoJ24 sotoJ24 changed the title Fix issue 52 Feature: Implement wallet connection for Stellar Jan 27, 2025
Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

It doesn't satisfy what was asked in the issue.

.env.local Outdated
@@ -0,0 +1,20 @@
NEXT_PUBLIC_DISCORD_CLIENT_ID=xxx
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't commit your env file


import { connect as starknetConnect, disconnect as starknetDisconnect } from "starknetkit";
// Import Stellar SDK (you'll need to add this dependency)
import StellarSdk from "stellar-sdk";
Copy link
Collaborator

Choose a reason for hiding this comment

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

You import libraries but do not install them...
Or you forgot to push your package.json

Copy link
Collaborator

Choose a reason for hiding this comment

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

And you don't even use it


async function stellarConnect() {
console.log("Connecting to Stellar wallet...");
const wallet = { address: "stellar-wallet-address" }; // Mock example
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not mock it, the aim of this issue is to actually implement a stellar wallet

@sotoJ24
Copy link
Author

sotoJ24 commented Jan 30, 2025

Dear @Marchand-Nicolas I have already made the commit for the changes

Screenshot 2025-01-30 102424

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

Some code to clean. I will test the feature tomorrow

@@ -2,11 +2,21 @@
{
"name": "mainnet",
"url": "starknetid-mainnet.starknet.a5a.ch",
"indexer": true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don’t delete the indexer field

@@ -288,7 +288,7 @@ export const handleConfigConfirmCommand = async (
discordServerId: interaction.guildId,
starkyModuleConfig: currentConfig.moduleConfig,
discordRoleId: currentConfig.roleId,
starknetNetwork: currentConfig.network,
//starknetNetwork: currentConfig.network,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why ? And don't comment code you don't use anymore, just delete. Else we will end up with comments everywhere

@@ -66,7 +66,7 @@ export const handleDebugUserCommand = async (
const network = discordMember.starknetNetwork as NetworkName;
const discordServerConfigs = await DiscordServerConfigRepository.findBy({
discordServerId: guildId,
starknetNetwork: network,
//starknetNetwork: network,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

@@ -22,14 +22,14 @@ const launchIndexers = () => {
const blockStack = new BlockStack();
// For each network, launch an indexer
for (let network of networks) {
if (network.indexer === true) {
/*if (network.indexer === true) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

@@ -28,7 +28,7 @@ const processBlocks = async (stack: BlockStack) => {
if (!walletAddress) continue;
const discordConfigs = await DiscordServerConfigRepository.findBy({
discordServerId: member.discordServerId,
starknetNetwork: networkName,
//starknetNetwork: networkName,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

@@ -58,7 +58,7 @@ export const refreshDiscordMemberForAllConfigs = async (
const network = discordMember.starknetNetwork as NetworkName;
const discordServerConfigs = await DiscordServerConfigRepository.findBy({
discordServerId: discordMember.discordServerId,
starknetNetwork: network,
// starknetNetwork: network,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

@sotoJ24
Copy link
Author

sotoJ24 commented Jan 30, 2025

I have already fixed, could you check again please

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

Still a lot of problems.
The code is not really clean...
You should install a linter, and take time to read your code. You'll learn a lot if you try reviewing it yourself before pushing.
I haven't tested the feature yet, will do it asap

@@ -1,21 +0,0 @@
NEXT_PUBLIC_DISCORD_CLIENT_ID=xxx
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't touch this file.
Eqverytime, before requesting a review, please check here #77 that you didn't do anything wrong

sepolia: string;
};

const chainIds: ChainIds = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why adding this variable ? It's not used

signMessage: (message: any) => Promise<Signature>;
};

type StarknetAccount = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not define types here, it's not clean. If you want to define types (other than Props), define them in the folder types


useEffect(() => {
const fetchNetworkConfig = async () => {
const response = await fetch("/configs/networks.json");
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to access the config, just import it, do not fetch it

};
const signature = await account.signMessage(messageCopy);
await verifySignature(signature);
let signature;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this variable is not used

domain: { ...messageToSign.domain, chainId },
};
signature = messageCopy;
}
} catch (e: any) {
WatchTowerLogger.error(e.message, e);
}
}, [account, verifySignature, chainId]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

React Hook useCallback has an unnecessary dependency: 'verifySignature'. Either exclude it or remove the dependency array.

@Marchand-Nicolas
Copy link
Collaborator

Also there are still conflicts, so I can't merge

@Marchand-Nicolas
Copy link
Collaborator

Screenshot 2025-01-31 at 6 46 50 PM

Just tested, I see object object instead of the address, and it doesn't open my freighter wallet to accept connection.
Then, after signing with freighter the website does nothing. It should verify the signature like on starknet.

Also, as you didn't pull the changes made by the other contributors you cannot test.
Please TEST! That way you'll understand what you do and avoid errors.
Have you tried actually running the project ?

@sotoJ24
Copy link
Author

sotoJ24 commented Jan 31, 2025

Hi Marchand-Nicolas, I have run the project before, but it shows me errors from the last merges, may be the conflicts come because of it, now I will clean the code, sorry I am learning, it's my first time on how to apply the connection wallet for Stellar, I just want learn and help, regards

@@ -1,21 +0,0 @@
NEXT_PUBLIC_DISCORD_CLIENT_ID=xxx
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not delete this file

@@ -1,5 +1,7 @@
{
"goerli": ["SN_GOERLI", "0x534e5f474f45524c49"],
"sepolia": ["SN_SEPOLIA", "0x534e5f5345504f4c4941"],
"mainnet": ["SN_MAIN", "0x534e5f4d41494e"]
"mainnet": ["SN_MAIN", "0x534e5f4d41494e"],
"stellar-mainnet": ["SN_STELLAR_MAIN", "0x534e5f53544c4c41524d41494e"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename ST_MAIN and ST_TEST instead of SN_xxx for Stellar

{
"name": "stellar-mainnet",
"url": "stellar-mainnet-url",
"indexer": true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Set indexer to false for stellar because we currently don't have one for these networks

@@ -16,7 +16,12 @@ export class DiscordServerConfig {
discordServerId: string;

@Column()
starknetNetwork: "goerli" | "mainnet" | "sepolia";
starknetNetwork:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect!

@@ -14,6 +14,8 @@
"@apibara/protocol": "^0.4.8",
"@apibara/starknet": "^0.3.0",
"@discordjs/rest": "^2.1.0",
"@stellar/freighter-api": "^4.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

The imports look good too well done

signMessage: (message: any) => Promise<Signature>;
};

type StarknetAccount = {
Copy link
Collaborator

Choose a reason for hiding this comment

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


useEffect(() => {
const fetchNetworkConfig = async () => {
const response = await fetch("/configs/networks.json");
Copy link
Collaborator

Choose a reason for hiding this comment

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

@sotoJ24
Copy link
Author

sotoJ24 commented Feb 6, 2025

On it

@sotoJ24
Copy link
Author

sotoJ24 commented Feb 10, 2025

Done, please review

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

image If am trying to connect to stellar, but: the button should be "Connect your Stellar wallet" instead of starknet. Also, when I click it, it opens the popup to connect to starknet, instead of stellar

);

useEffect(() => {
const fetchNetworkConfig = async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't fetch the config. Import it

@sotoJ24
Copy link
Author

sotoJ24 commented Feb 18, 2025

Let me fix it

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

Screenshot 2025-02-20 at 12 19 22 PM Remove this step for stellar. You can add a "connectionNeeded" parameter to do so in configs/networks.json. Because we don't need to accept any connection. We can directly sign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement wallet connection for Stellar
2 participants