All files / app/store/stacking stacking.actions.ts

0% Statements 0/42
0% Branches 0/4
0% Functions 0/5
0% Lines 0/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                                                                                                                       
import { Api } from '@api/api';
import { createAsyncThunk, createAction } from '@reduxjs/toolkit';
import { StackingClient } from '@stacks/stacking';
import { RootState } from '@store/index';
import {
  selectActiveNodeApi,
  selectActiveStacksNetwork,
} from '@store/stacks-node/stacks-node.reducer';
import { safeAwait } from '@utils/safe-await';
 
export const fetchStackingInfo = createAsyncThunk('stacking/details', async (_arg, thunkApi) => {
  const state = thunkApi.getState() as RootState;
  const network = selectActiveNodeApi(state);
  const resp = await new Api(network.url).getPoxInfo();
  return resp.data;
});
 
export const fetchCoreDetails = createAsyncThunk(
  'stacking/core-node-details',
  async (_arg, thunkApi) => {
    const state = thunkApi.getState() as RootState;
    const network = selectActiveNodeApi(state);
    const resp = await new Api(network.url).getCoreDetails();
    return resp.data;
  }
);
export const fetchBlockTimeInfo = createAsyncThunk(
  'stacking/block-time-details',
  async (_arg, thunkApi) => {
    const state = thunkApi.getState() as RootState;
    const network = selectActiveNodeApi(state);
    const resp = await new Api(network.url).getNetworkBlockTimes();
    return resp.data;
  }
);
 
export const fetchStackerInfo = createAsyncThunk(
  'stacking/stacker-info',
  async (address: string, thunkApi) => {
    const state = thunkApi.getState() as RootState;
    const network = selectActiveStacksNetwork(state);
    const stackingClient = new StackingClient(address, network);
    const [error, resp] = await safeAwait(stackingClient.getStatus());
    Iif (resp) return resp as any;
    Iif (error) return { error };
    throw new Error();
  }
);
 
export const fetchAccountBalanceLocked = createAsyncThunk(
  'stacking/balance-locked',
  async (address: string, thunkApi) => {
    const state = thunkApi.getState() as RootState;
    const network = selectActiveStacksNetwork(state);
    const stackingClient = new StackingClient(address, network);
    const [error, resp] = await safeAwait(stackingClient.getAccountBalanceLocked());
    Iif (resp !== undefined) return resp;
    Iif (error) return { error };
    throw new Error();
  }
);
 
export const activeStackingTx = createAction<{ txId: string }>(
  'stacking/call-stacking-contract-tx'
);
 
export const removeStackingTx = createAction('stacking/remove-active-tx');