-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathutils.ts
More file actions
23 lines (21 loc) · 840 Bytes
/
utils.ts
File metadata and controls
23 lines (21 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { ValidationError } from "@threefold/types";
/**
* Decorator function to check if the balance is enough to apply an extrinsic.
*
* @throws {`ValidationError`} if the balance is less than `0.001`.
* @param target The target object
* @param propertyKey The property key
* @param descriptor The property descriptor
* @returns The modified property descriptor with balance check logic
*/
function checkBalance(target, propertyKey: string, descriptor: PropertyDescriptor) {
const method = descriptor.value;
descriptor.value = async function (...args) {
const balances = await this.config.tfclient.balances.getMyBalance();
if (balances["free"] < 0.001) {
throw new ValidationError("Balance is not enough to apply an extrinsic.");
}
return await method.apply(this, args);
};
}
export { checkBalance };