@effectai/sdk
Version:
Effect Network Javscript/Typescript SDK (for [https://effect.network](https://effect.network))
42 lines • 1.28 kB
JavaScript
import { VAccountError } from "../../errors";
import { useEFXContracts } from "../../utils/state";
import { getPendingPayments } from "./getPendingPayments";
export const claim = async ({ client }) => {
if (!client.session?.vAccount) {
throw new VAccountError("vAccount is not set.");
}
const { tasks } = useEFXContracts(client);
const { authorization } = client.session;
const { claimablePayments } = await getPendingPayments({
client,
vAccountId: client.session.vAccount.id,
});
const actions = [];
if (claimablePayments) {
actions.push(...claimActions({
payments: claimablePayments,
tasks,
authorization,
}));
}
else {
throw new Error("No pending payouts found");
}
const { transact } = client.session;
return await transact({ actions: actions });
};
export const claimActions = ({ payments, tasks, authorization, }) => {
const actions = [];
for (const payment of payments) {
actions.push({
account: tasks,
name: "payout",
authorization,
data: {
payment_id: payment.id,
},
});
}
return actions;
};
//# sourceMappingURL=claim.js.map