Skip to content

Commit

Permalink
Mining low balance (#247)
Browse files Browse the repository at this point in the history
* Update miner_toggle.ts

Errorhandler for toggling mining with balances lower than 10 libra

* Update miner_toggle.ts

Errorhandler for toggling mining with balances lower than 10 libra
  • Loading branch information
Teisson authored Feb 28, 2024
1 parent 78d8adf commit 4160b04
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/modules/miner_toggle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { get } from 'svelte/store'
import { signingAccount } from './accounts'
import { raise_error, ErrMap } from './carpeError'
import { notify_success } from './carpeNotify'
import { minerLoopEnabled } from './miner'
import {
killBacklogListener,
Expand Down Expand Up @@ -37,10 +40,35 @@ export async function disableMining(): Promise<boolean> {
return true
}

export function toggleMining() {
export async function toggleMining() {
const account = get(signingAccount)

// Check if the account exists and has an unlocked balance sufficient for mining
if (!account || account.balance.unlocked < 10) {
// Customizing the variable for the error message based on the specific condition
let errorMessage = 'Your balance is too low to start mining.'
if (!account) {
errorMessage += ' Account does not exist or is not currently active on-chain.'
} else if (account.balance.unlocked < 10) {
errorMessage += ' You need at least 10 tokens in your wallet to start mining.'
}

// Construct a CarpeError object according to the CarpeError interface
const error = {
category: ErrMap.InsufficientBalance, // Assuming this is the correct category for this error
uid: ErrMap.InsufficientBalance, // This should be a unique identifier, using the same value for simplicity
msg: errorMessage,
}

raise_error(error, false, 'toggleMining')
return // Exit the function to prevent further execution
}

// enableMining and disableMining functions
if (get(minerLoopEnabled)) {
disableMining()
} else {
enableMining()
notify_success('Mining status toggled.') // Notify the user of successful operation
}
}

0 comments on commit 4160b04

Please sign in to comment.