stellar / basic-payment-app

An example payments application demonstrating integrations of various features and SEPs in a user-facing product.
https://github.com/stellar/basic-payment-app
Apache License 2.0
9 stars 27 forks source link

Testnet accounts should be checked for funding when signing in #7

Closed ElliotFriend closed 1 month ago

ElliotFriend commented 1 month ago

Following a Testnet reset, when logging into an account that was set up before the reset, the login will fail with a 404 error, since the account is no longer live on the Testnet.

The fetchAccount function in /src/lib/stellar/horizonQueries.js should be modified to go ahead and fund the account in the event it finds a 404 response from the Horizon server.

od-hunter commented 1 month ago

Hi @ElliotFriend , please can I be assigned this once od hack starts?

onlydustapp[bot] commented 1 month ago

Hi @od-hunter! Maintainers during the ODHack # 8.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

PoulavBhowmick03 commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm Poulav Bhowmick, a software engineer at Invisible Studios with a robust background in TypeScript, Rust, Solidity Cairo, fullstack development and blockchain technology. My experience includes building robust applications, optimizing functionalities and blockchain integration. I have actively participated in events and open source contributions, enhancing my capability to tackle real-world tech challenges. My projects can be viewed on my GitHub Profile and OnlyDust Profile. Plus I´m active member of Starknet, Ethereum ecosystem.

How I plan on tackling this issue

  1. Modify the fetchAccount Function to Handle 404 Errors:

    • I will modify the fetchAccount function to check if the 404 error occurs when querying the Horizon server. Instead of throwing an error immediately, I will trigger a call to the fundWithFriendbot function to fund the account in case of a 404 error (i.e., the account no longer exists on the Testnet after a reset).
  2. Add Logic to Fund Accounts Automatically:

    • After detecting a 404 error, I will attempt to fund the account using the fundWithFriendbot utility. Once funded, I will retry fetching the account details to confirm the account's existence and return the account data.
  3. Update fetchAccount Function:

    • Here’s an updated version of the fetchAccount function to include the automatic funding step:
    export async function fetchAccount(publicKey) {
       if (StrKey.isValidEd25519PublicKey(publicKey)) {
           try {
               let account = await server.accounts().accountId(publicKey).call()
               return account
           } catch (err) {
               if (err.response?.status === 404) {
                   console.log(`Account ${publicKey} not found on the network. Funding with Friendbot...`)
    
                   // Attempt to fund the account
                   try {
                       await fundWithFriendbot(publicKey)
                       console.log(`Account ${publicKey} successfully funded!`)
    
                       // Retry fetching the account
                       let account = await server.accounts().accountId(publicKey).call()
                       return account
                   } catch (fundError) {
                       throw error(500, { message: `Failed to fund account ${publicKey}: ${fundError.message}` })
                   }
               } else {
                   throw error(err.response?.status ?? 400, {
                       message: `${err.response?.title} - ${err.response?.detail}`,
                   })
               }
           }
       } else {
           throw error(400, { message: 'invalid public key' })
       }
    }
  4. Test the Changes:

    • After implementing the changes, I will thoroughly test the login process with accounts that are unfunded, previously funded but reset, and newly created, to ensure that the funding mechanism works as expected.

ETA - 3 days

ryzen-xp commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm a Solidity developer skilled in building decentralized applications and integrating multi-token support . My experience can help address issues like automatically funding accounts on Testnet after resets, ensuring a seamless user experience.

How I plan on tackling this issue

To approach this issue ----- >

  1. Check for 404 error in the fetchAccount function when logging in.
  2. f 404 occurs, automatically fund the account on the Testnet.
  3. Modify /src/lib/stellar/horizonQueries.js to handle the response and trigger the funding process when needed.
od-hunter commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, please can I be assigned this please? This would be my first time contributing to this repo and I'd love to be given the opportunity. I have experience in html, css, react, JavaScript,TypeScript and solidity, python and Cairo.

How I plan on tackling this issue

To solve this issue, I’d take the following steps: 1.⁠ ⁠First of all, I’ll have to understand the current logic of the fetchAccount function. 2.⁠ ⁠⁠I’ll update the function to check for a 404 response when fetching the account.

  1. If a 404 error is detected, I’ll initiate the funding process for the account using a funding function. 4.⁠ ⁠I’ll modify fetchAccount to handle 404s and call the funding function when needed. 5.⁠ ⁠⁠I’ll verify that the function behaves correctly by funding accounts that are no longer live and handling existing accounts properly. 6.⁠ ⁠⁠Lastly, I’ll provide documentation for the modifications made to the function and the new error handling logic.

Please assign me. I'm ready to work.

josephchimebuka commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hello @ElliotFriend I am Joseph I am a Software developer and blockchain developer and I am also an active contributor here on only dust here is my profile https://app.onlydust.com/u/josephchimebuka. This is my first time to contribute to this repo ill appreciate the opportunity to contribute.

How I plan on tackling this issue

To solve this, I will modify the fetchAccount function in /src/lib/stellar/horizonQueries.js to handle the 404 error. When a 404 response is received from the Horizon server (indicating that the account is no longer live on the Testnet), I will add logic to automatically fund the account. This will involve checking the response for the 404 status and, if detected, triggering the account funding process before retrying the login. This ensures that accounts that were set up before the Testnet reset are automatically funded and can log in successfully. I will complete this in 2-3 days

ShantelPeters commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a blockchain developer with a strong background in html, css, javascript , typescript , this would be my first time contributing to this ecosystem . and i would be glad to work on this issue

How I plan on tackling this issue

I will approach this issue by modifying the fetchAccount function in /src/lib/stellar/horizonQueries.js to detect a 404 error, then automatically fund the account if the account doesn't exist on the Testnet after a reset.