sunrise-stake / app

A proxy around Solana Stake Pools that diverts yield to public goods programs
https://app.sunrisestake.com
12 stars 5 forks source link

Feature/impact levels #204

Closed dankelleher closed 1 year ago

dankelleher commented 1 year ago

Refactored lock logic into a lock client.

To use:

Get the lock balance

const details = await client.details()
return details.lockTokenAccount

Get the current impact nft level

const details = await client.details()
return details.currentLevel

To get the amount needed to get to the next level

const details = await client.details()
return details.yieldToNextLevel

note - instead of calling await client.details() (Asynchronous) you can also just call client.lockClient.... This is useful if you have a client but have not called details, for whatever reason. (Usually the UI has access to the details object via the useSunriseStake() hook)

NOTE

The API is simpler (fewer arguments need to be passed around), and more efficient (it doesn't have to load the state, and balance, all the time). However, the client lock balance is now stored inside the state, which means it has to be refreshed. This differs from the gsol balance, which is retrieved on the details() call, so the lock client has user balance state whereas the main client does not, which is inconsistent. We might want to fix this later.

This means that after locking, unlocking or updating, the client needs to be refreshed. This is happening, but I am not sure if client.details() is re-called. So depending on how this is wired into the UI, it may need client.details() to be retriggered in the wrapper.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 3, 2023 1:17pm