When a user is funding their account, an L402 will be provisioned for them by secondbrain. An L402 will function as both an account identifier and balance for the user. This is stored inside the macaroon alongside the preimage in the chrome extension. The macaroon is also stored inside the second brain. These macaroons together is how the chrome extension and secondbrain communicate payments and account balances to one another.
There are two instances when this flow is triggers:
When someone first adds a secondbrain
When their account reaches 0.
The flow
When a secondbrain has 0 sats, they will be prompted to fund their account.
User types it amount they want and clicks on "generate invoice". An api call (/buy_lsat) is made to purchase an LSAT. The response returns a Macaroon and Invoice. You can specify which 2B endpoint to hit using the url by using this logic.
The macaroon in the 2B encoded the preimage and send the invoice to the macaroon in the chrome extension.
The macaroon in the chrome extension must decode the preimage and store it.
The user then pays invoice.
In the backend, invoices should be polled every 5 seconds during the duration of the time the invoice is displayed. API for this is /check_lsat.
If status is paid, what will be returned is the the L402 along with the balance.
Then success screen is then triggered and balance amount is displayed. The amount will be set in the frontend and by the amount the user had set previously. However later balance updates will be updated by an api call /balance.
If timer expires, balance is not set.
Design
Fund your secondbrainType in an amount to depositDisplay InvoiceSuccess Screen
This screen lasts for 3 seconds. The user can click anywhere inside the success screen to exit out.
Submit link
After the success screen, they will be taken inside the 2B they funded and prompted to add a link. Make sure to note that the balance is correctly reflected.
L402 and Macaroons
When a user is funding their account, an L402 will be provisioned for them by secondbrain. An L402 will function as both an account identifier and balance for the user. This is stored inside the macaroon alongside the preimage in the chrome extension. The macaroon is also stored inside the second brain. These macaroons together is how the chrome extension and secondbrain communicate payments and account balances to one another.
Here is a visualization to help:
Testing environment
To run a testing environment locally, use sphinx-stack: https://github.com/stakwork/sphinx-stack
User story - Buys L402
There are two instances when this flow is triggers:
The flow
/buy_lsat
) is made to purchase an LSAT. The response returns a Macaroon and Invoice. You can specify which 2B endpoint to hit using the url by using this logic./check_lsat
./balance
.Design
Fund your secondbrain
Type in an amount to deposit
Display Invoice
Success Screen
This screen lasts for 3 seconds. The user can click anywhere inside the success screen to exit out.
Submit link
After the success screen, they will be taken inside the 2B they funded and prompted to add a link. Make sure to note that the balance is correctly reflected.
![29](https://github.com/stakwork/sphinx-js/assets/32662508/ded548bd-980d-453e-8a93-6b1711129c59)
Acceptance Criteria