Activity Earnings

Objective

The Activity Earnings page (located on the application) aims to provide users with transparency into LM (currently RANDOM) token balances, locked tokens, and platform earnings. This allows users to easily track and manage their holdings and earnings.

Implementation

The Activity Earnings page is implemented as a component that connects to the user's wallet and interacts with smart contracts on the blockchain to retrieve relevant data.

Key features include:

  • Displaying the user's LM token balance

  • Displaying the user's veLM (vote-escrowed LM) token balance

  • Showing the user's total locked tokens and time until unlock

  • Displaying the user's total platform earnings

  • Allowing the user to redeem earned tokens, either a specified amount or the full balance

  • Enabling the user to lock additional LM tokens for a specified duration to receive veLM

  • Letting the user extend an existing token lock period

  • Allowing the user to unlock tokens once the lock period expires

The component loads data from the blockchain when it mounts and whenever the user's wallet address changes. It uses ethers.js to interact with the LM , veLM, and Rewards contracts.

Here are some of the key functions:

  • loadUserBalances: Retrieves the user's token balances and platform earnings from the contracts

  • handleRedeemTokens: Redeems the user's earned tokens, either the specified amount or full balance

  • handleLockTokens: Locks the specified amount of the user's LM tokens for the provided duration

  • handleExtendLock: Extends the lock period of the user's currently locked tokens

  • handleUnlockTokens: Unlocks the user's tokens if the lock period has expired

The component also tracks loading state and uses it to display loading messages on buttons while transactions are pending.

By connecting securely to the user's wallet and smart contracts, the Activity Earnings page provides a transparent, easy-to-use interface for users to monitor and manage their token holdings and earnings, meeting the objective of maintaining high quality and relevant information.

Last updated