|
@@ -8,9 +8,10 @@ import {useDispatch, useSelector} from "react-redux";
|
|
|
import {getProtectGetStatus, getProtectInfo} from "@features/protectSlice";
|
|
import {getProtectGetStatus, getProtectInfo} from "@features/protectSlice";
|
|
|
import {formatCash, stringFormat} from "@utils/helpers";
|
|
import {formatCash, stringFormat} from "@utils/helpers";
|
|
|
import {REQ_STATUS} from "@api/config";
|
|
import {REQ_STATUS} from "@api/config";
|
|
|
-import {reqProtectGet} from "@features/api";
|
|
|
|
|
|
|
+import {reqProtectCheck, reqProtectGet} from "@features/api";
|
|
|
import {APP_WELFARE} from "@constants/app";
|
|
import {APP_WELFARE} from "@constants/app";
|
|
|
import {useThemeProvider} from "@contexts/themeContext";
|
|
import {useThemeProvider} from "@contexts/themeContext";
|
|
|
|
|
+import {getUserInfo} from "@features/mainSlice";
|
|
|
const i18n=global.i18n;
|
|
const i18n=global.i18n;
|
|
|
const WProtect = () => {
|
|
const WProtect = () => {
|
|
|
const [isShow, setIsShow] = useState(false);
|
|
const [isShow, setIsShow] = useState(false);
|
|
@@ -18,9 +19,11 @@ const WProtect = () => {
|
|
|
const status=useSelector(getProtectGetStatus);
|
|
const status=useSelector(getProtectGetStatus);
|
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
|
const {setWelfTabState}=useThemeProvider();
|
|
const {setWelfTabState}=useThemeProvider();
|
|
|
|
|
+ const user=useSelector(getUserInfo);
|
|
|
const show=()=>{
|
|
const show=()=>{
|
|
|
setIsShow(true);
|
|
setIsShow(true);
|
|
|
setWelfTabState(APP_WELFARE.PROTECT);
|
|
setWelfTabState(APP_WELFARE.PROTECT);
|
|
|
|
|
+ dispatch(reqProtectCheck());
|
|
|
}
|
|
}
|
|
|
const hide=()=>{
|
|
const hide=()=>{
|
|
|
setIsShow(false);
|
|
setIsShow(false);
|
|
@@ -31,10 +34,19 @@ const WProtect = () => {
|
|
|
hide();
|
|
hide();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ const checkCanProtect=()=>{
|
|
|
|
|
+ if (user!=null&&protectInfo!=null){
|
|
|
|
|
+ let Score=Number(user.Score)*global.CASH_BASE;
|
|
|
|
|
+ let ProtectLimit=protectInfo.ProtectLimit!=null?parseInt(protectInfo.ProtectLimit):0;
|
|
|
|
|
+ let CurProtectTimes=protectInfo.CurProtectTimes!=null?parseInt(protectInfo.CurProtectTimes):0;
|
|
|
|
|
+ let ProtectTimes=protectInfo.ProtectTimes!=null?parseInt(protectInfo.ProtectTimes):0;
|
|
|
|
|
+ return (Score<ProtectLimit)&&(CurProtectTimes<ProtectTimes);
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
const onGetProtect=()=>{
|
|
const onGetProtect=()=>{
|
|
|
if (status===REQ_STATUS.LOADING)return;
|
|
if (status===REQ_STATUS.LOADING)return;
|
|
|
- let CurProtectTimes=protectInfo.CurProtectTimes!=null?parseInt(protectInfo.CurProtectTimes):0;
|
|
|
|
|
- if (CurProtectTimes<=0)return;
|
|
|
|
|
|
|
+ if (!checkCanProtect())return;
|
|
|
let ProtectNum=protectInfo.ProtectNum!=null?parseInt(protectInfo.ProtectNum):0;
|
|
let ProtectNum=protectInfo.ProtectNum!=null?parseInt(protectInfo.ProtectNum):0;
|
|
|
dispatch(reqProtectGet({callback:callback,ProtectNum:ProtectNum}));
|
|
dispatch(reqProtectGet({callback:callback,ProtectNum:ProtectNum}));
|
|
|
}
|
|
}
|
|
@@ -64,8 +76,9 @@ const WProtect = () => {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
const renderGetBtn=()=>{
|
|
const renderGetBtn=()=>{
|
|
|
|
|
+ let isDisabled=!checkCanProtect();
|
|
|
return (
|
|
return (
|
|
|
- <button className={styles.p_get_btn} onClick={onGetProtect}>
|
|
|
|
|
|
|
+ <button className={`${styles.p_get_btn} ${isDisabled?styles.p_get_btn_disabled:''}`} onClick={onGetProtect} disabled={isDisabled}>
|
|
|
{
|
|
{
|
|
|
status===REQ_STATUS.LOADING?(<SmallLoading fill={"#fff"}/>): (
|
|
status===REQ_STATUS.LOADING?(<SmallLoading fill={"#fff"}/>): (
|
|
|
<span className={styles.text}>
|
|
<span className={styles.text}>
|