import React, { useCallback, useEffect, useState } from "react";
import { Box, Checkbox, Center, HStack, Text, View, VStack, Spinner } from "native-base";
import { Wizard, useWizard } from "react-use-wizard";
import { Platform } from "react-native";
import { isBoolean, isEmpty } from "lodash";
import { Envs, useG$Formatted, useGetEnvChainId } from "@gooddollar/web3sdk-v2";
import { RedTentProps } from "../types";
import { withTheme } from "../../../theme/hoc/withTheme";
import ImageCard from "../../../core/layout/ImageCard";
import { Image } from "../../../core/images";
import { WebVideoUploader } from "../../../core/inputs/WebVideoUploader";
import { WizardContextProvider } from "../../../utils/WizardContext";
import { BulletPointList, TransButton, TransText, TransTitle } from "../../../core/layout";
import { YouSureModal } from "../../../core/web3/modals";
import { useClaimContext } from "../../ubi";
import UBICard from "../../../assets/images/WomenUbiGoodDollar.png";
import BillyPhone from "../../../assets/images/billy-phone.png";
import { cardShadow } from "../../../theme";
import { useSendAnalytics } from "@gooddollar/web3sdk-v2";
import { BigNumber } from "ethers";
import { UBIPoolOffer } from "../components";
const videoRequirements = [
/*i18n*/ "Your first name",
/*i18n*/ "Your age",
/*i18n*/ "Your location",
/*i18n*/ "What you plan to do with the money you receive"
];
const videoRestrictions = [/*i18n*/ "Maximum video length 30sec", /*i18n*/ "Maximum size 20mb"];
const videoUsagePolicy = [
/*i18n*/ "Your video may be reviewed by the \n GoodLabs or partner teams for \n verification purposes. Your video \n will not be shared or used publicly, \n and will be erased after a period of \n time."
];
const offerCriteria = {
location: {
NG: /*i18n*/ "Nigeria",
CO: /*i18n*/ "Colombia"
},
gender: {
Female: /*i18n*/ "Female",
Male: /*i18n*/ "Male"
}
};
const CardContent = ({ offer }: { offer: UBIPoolOffer }) => {
const formattedAmount = useG$Formatted(BigNumber.from(offer.claimAmount));
return (
);
};
const CardFooter = ({ linkText }: { linkText: string }) => (
{linkText}
);
const PoolRequirements = ({ offer }: { offer: any }) => {
const gender = offer.Gender;
const country = offerCriteria.location[offer.Location.countryCode as keyof typeof offerCriteria.location];
return (
}}
/>
}}
/>
);
};
const RedtentOffer = ({
dontShowAgainKey,
onDone,
offer
}: {
onDone: RedTentProps["onDone"];
dontShowAgainKey: string;
offer: UBIPoolOffer;
}) => {
const { nextStep } = useWizard();
const [showModal, setShowModal] = useState(false);
const { track } = useSendAnalytics();
const [hasFired, setHasFired] = useState(false);
const { activePoolAddresses } = useClaimContext();
const { baseEnv } = useGetEnvChainId();
const devEnv = baseEnv === "fuse" ? "development" : baseEnv;
const { goodCollectiveUrl } = Envs[devEnv];
const offerTitle =
/*i18n*/ "GoodDollar UBI+ for Women in " +
offerCriteria.location[offer.Location?.countryCode as keyof typeof offerCriteria.location];
const offerLink = `${goodCollectiveUrl}collective/${activePoolAddresses[offer.Location?.countryCode || ""]}`;
const handleSkip = () => {
track("offer_declined", { offer: offerTitle });
setShowModal(true);
};
const handleStart = () => {
track("offer_start", { offer: offerTitle });
void nextStep();
};
const handleOnDone = () => {
setShowModal(false);
void onDone(true);
};
useEffect(() => {
if (!hasFired) {
track("offer_show", { offer: offerTitle });
setHasFired(true);
}
}, []);
if (isEmpty(offer)) return ;
return (
}
footer={>"} />}
picture={UBICard}
link={offerLink}
styles={{
picture: { resizeMode: "cover" },
container: { width: "100%", alignItems: "flex-start" },
title: {
fontFamily: "subheading",
fontSize: "md",
fontWeight: "500",
color: "goodGrey.600",
paddingBottom: 2
}
}}
{...Platform.select({
web: {
style: cardShadow
}
})}
borderRadius={20}
/>
);
};
const RedtentVideoInstructions = withTheme({ name: "RedtentVideoInstructions" })(
({ onDone, onVideo, ...props }: { onDone: RedTentProps["onDone"]; onVideo: RedTentProps["onVideo"] }) => {
const { nextStep } = useWizard();
const [isLoading, setLoading] = useState(false);
const { track } = useSendAnalytics();
const onUpload = useCallback(
async (video?: { base64: string; extension: string }, error?: Error) => {
track("offer_video_upload_start");
if (!video || error) {
void onDone(error || new Error("Video upload failed"));
return;
}
setLoading(true);
try {
await onVideo(video.base64, video.extension);
void nextStep();
} catch (e) {
void onDone(e as Error);
} finally {
setLoading(false);
}
},
[onDone]
);
return (
{[
{ title: /*i18n*/ "Submit a video selfie", pointsList: videoRequirements },
{ title: /*i18n*/ "Restrictions", pointsList: videoRestrictions },
{ title: /*i18n*/ "How will my video be used?", pointsList: videoUsagePolicy }
].map(({ title, pointsList }) => (
))}
);
}
);
const RedtentThanks = ({ onDone, offer }: { onDone: RedTentProps["onDone"]; offer: any }) => {
// when passed down directly into an inline callback, for some reason the onDone is not being called
const onPress = async () => {
void onDone(true);
};
return (
);
};
export const RedtentWizard: React.FC = (props: RedTentProps) => {
const [error, setError] = useState(undefined);
const { videoInstructStyles } = props;
const dontShowAgainKey = "goodid_noOffersModalAgain";
const { track } = useSendAnalytics();
// inject show modal on callbacks exceptions
const modalOnDone: RedTentProps["onDone"] = async errorOnDone => {
try {
if (!isBoolean(errorOnDone)) {
track("offer_video_error", { error: errorOnDone });
}
track("offer_success");
await props.onDone(errorOnDone);
} catch (e: any) {
props.onError && props.onError(error);
}
};
const modalOnVideo: RedTentProps["onVideo"] = async (...args) => {
try {
await props.onVideo(...args);
} catch (e: any) {
setError(e.message);
throw new Error(e);
}
};
return (
);
};