| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import {
- APP_WITHDRAW_BASE_INFO,
- APP_WITHDRAW_PAYOUT,
- APP_WITHDRAW_RECORD,
- APP_WITHDRAW_SET_INFO,
- success
- } from "@scripts/api";
- import { Http } from "@scripts/request";
- import { IWithdrawBaseInfo, IWithdrawRecordItem, IWithdrawRecordPageData, IWithdrawSetInfoRequest } from "./data";
- import { CASH_BASE } from "@scripts/constants/App";
- import { PayoutType } from "@scripts/define/PayDefine";
- import { checkResponse } from "@scripts/api/ApiHelper";
- import { AppKernel } from "@scripts/app/AppKernel";
- class WithdrawStore {
- private _baseInfo: IWithdrawBaseInfo = null;
- private _records: IWithdrawRecordItem[] = null;
- public get baseInfo() { return this._baseInfo; }
- public get records() { return this._records; }
- public get minExchange() { return Math.floor(this.baseInfo.MinExchange / CASH_BASE); }
- public get maxExchange() { return Math.floor(this.baseInfo.MaxExchange / CASH_BASE); }
- public get sumCanExchange() {
- const SumCanExchange = this.baseInfo.SumCanExchange;
- return Math.floor(SumCanExchange / CASH_BASE);
- }
- async reqBaseInfo(): Promise<boolean> {
- const res = await Http.call<IWithdrawBaseInfo>(APP_WITHDRAW_BASE_INFO);
- if (success(res) && res.data) {
- this._baseInfo = this.parseWithdrawBaseInfo(res.data);
- AppKernel.events.emit('wallet:update');
- return true;
- }
- return false;
- }
- async reqWithdrawRecord(arg: any = {}) {
- const params: Record<string, unknown> = {
- paypass: arg.paypass || '',
- };
- if (arg.score_type !== undefined) params.score_type = arg.score_type;
- if (arg.sort_by !== undefined) params.sort_by = arg.sort_by;
- if (arg.sort !== undefined) params.sort = arg.sort;
- const res = await Http.call<IWithdrawRecordPageData>(APP_WITHDRAW_RECORD, params);
- if (success(res) && res.data) {
- const list = Array.isArray(res.data.data) ? res.data.data : [];
- this._records = list.map(item => {
- item.ServiceFee = Number(item.ServiceFee);
- item.WithDraw = Number(item.WithDraw);
- item.State = Number(item.State);
- item.PixType = Number(item.PixType);
- return item;
- })
- return true;
- }
- return false;
- }
- async reqWithdrawSetInfo(arg: IWithdrawSetInfoRequest): Promise<boolean> {
- const params = {
- cbPixType: arg.pixType,
- email: arg.paypal || '',
- PixNum: arg.cashTag || '',
- paypass: '',
- bank: '',
- account: '',
- userName: '',
- phone: '',
- PAN: '',
- IFSC: '',
- adhaar: '',
- branceBank: '',
- code: '',
- };
- const res = await Http.call(APP_WITHDRAW_SET_INFO, params);
- if (checkResponse(res)) {
- await this.reqBaseInfo();
- return true;
- }
- return false;
- }
- async reqWithdrawPayout(score: number): Promise<boolean> {
- score = score * CASH_BASE;
- const res = await Http.call(APP_WITHDRAW_PAYOUT, { paypass: '', score });
- if (checkResponse(res)) {
- await this.reqBaseInfo();
- this._records = null;
- return true;
- }
- return false;
- }
- private parseWithdrawBaseInfo(data: IWithdrawBaseInfo): IWithdrawBaseInfo {
- const info = { ...data };
- info.SumCanExchange = Number(info.SumCanExchange);
- const defaultCooldown = Number(info.withdraw_info_cooldown_seconds || 0);
- const cashappCooldown = Number(
- info.withdraw_info_precheck?.cashapp?.cooldown_seconds ?? defaultCooldown,
- );
- const paypalCooldown = Number(
- info.withdraw_info_precheck?.paypal?.cooldown_seconds ?? defaultCooldown,
- );
- info.MinExchange = Number(info.MinExchange);
- info.MaxExchange = Number(info.MaxExchange);
- info.cashapp_update_cd = cashappCooldown > 0 ? Date.now() + cashappCooldown * 1000 : 0;
- info.paypal_update_cd = paypalCooldown > 0 ? Date.now() + paypalCooldown * 1000 : 0;
- info.lastUpdateTs = Date.now() - Number(info.withdraw_info_update_time_pass || 0) * 1000;
- return info;
- }
- getPayoutAccount(type: PayoutType) {
- switch (type) {
- case PayoutType.CashApp:
- return this.baseInfo.PixNum;
- case PayoutType.Paypal:
- return this.baseInfo.EmailAddress;
- }
- }
- getPayoutRange(type: PayoutType) {
- const config = AppKernel.stores.mainStore.withdrawChannel;
- switch (type) {
- case PayoutType.CashApp:
- return config.cashapp;
- case PayoutType.Paypal:
- return config.paypal;
- }
- }
- }
- export const withdrawStore = new WithdrawStore();
|