aboutsummaryrefslogtreecommitdiff
path: root/src/models/cashoutMethodSlice.ts
blob: a6d02111b6152707f2c16801905d96e074fecbf5 (plain)
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
69
70
71
72
73
74
75
76
77
78
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
import type {RootState} from '@/store'
import {CashoutMethodOut} from "@/api";


const initialState: CashoutMethodOut[] = []

const cashoutMethodSlice = createSlice({
    name: 'cashoutMethods',
    initialState,
    reducers: {
        setCashoutMethods(state, action: PayloadAction<CashoutMethodOut[]>) {
            return action.payload;
        },
        redeem: {
            //     let res = {'status': false, 'msg': ''};
            //     let cashout_method = this.collection.getCashoutMethod();
            //     let req_amt = +this.ui.amount.val();
            //
            //     // Generic checks
            //     if (!cashout_method) {
            //         res['msg'] = "Cashout method not selected";
            //         return res
            //     }
            //
            //     if (isNaN(req_amt)) {
            //         res['msg'] = "Invalid amount (numbers only)";
            //         return res;
            //     }
            //
            //     if (!this.WALLET) {
            //         res['msg'] = "Unknown wallet balance";
            //         return res
            //     }
            //
            //     let balance: number = this.WALLET.get("redeemable_amount");
            //
            //     // Limit checks
            //     if (balance < cashout_method.get("min_value")) {
            //         res["msg"] = "Wallet balance not large enough";
            //         return res;
            //     }
            //
            //     let req_amount = this.getIntCentsValue()
            //
            //     if (req_amount < cashout_method.get("min_value")) {
            //         res["msg"] = "Requested amount not large enough";
            //         return res;
            //     }
            //
            //     if (req_amount > cashout_method.get("max_value")) {
            //         res["msg"] = "Amount too large for payout method";
            //         return res;
            //     }
            //
            //     if (req_amount > balance) {
            //         res["msg"] = "Amount is more than wallet balance";
            //         return res;
            //     }
            //
            //     res["status"] = true;
            //     return res;
            // },
        }
    }
})

export const {
    setCashoutMethods,
} = cashoutMethodSlice.actions;
export default cashoutMethodSlice.reducer

export const selectCashoutMethods = (state: RootState) => state.cashoutMethods

export const selectFixedCashoutMethods = (state: RootState) =>
    state.cashoutMethods.filter(cm => cm.data.value_type === "fixed")
export const selectVariableCashoutMethods = (state: RootState) =>
    state.cashoutMethods.filter(cm => cm.data.value_type === "variable")