import React from "react"; import { Meta } from "@storybook/react"; import { useEthers } from "@usedapp/core"; import { GoodIdContextProvider, SupportedChains, useAggregatedCertificates, useCertificatesSubject, useIdentityExpiryDate, useIsAddressVerified } from "@gooddollar/web3sdk-v2"; import { HStack, Spinner, Text, VStack } from "native-base"; import { Wizard } from "react-use-wizard"; import moment from "moment"; import { Provider } from "react-native-paper"; import { GoodButton } from "../../../core/buttons"; import { W3Wrapper } from "../../W3Wrapper"; import { useGoodId } from "../../../hooks/useGoodId"; import { OffersAgreement } from "../../../apps/goodid/screens/OffersAgreement"; import { GoodIdProvider } from "../../../apps/goodid/context/GoodIdProvider"; import { CheckAvailableOffers, GoodIdCard } from "../../../apps/goodid"; import { DisputeThanks, OnboardScreen, SegmentationScreen as SegScreen, SegmentationConfirmation, SegmentationDispute } from "../../../apps/goodid/screens"; import { SegmentationController, OnboardController } from "../../../apps/goodid/controllers"; import { GoodUIi18nProvider, useGoodUILanguage } from "../../../theme"; import { ClaimProvider } from "../../../apps/ubi"; const GoodIdWrapper = ({ children }) => { return {children}; }; //todo: add expiration date utilty example export const GoodIdCardExample = { render: (args: any) => { const { account = "" } = useEthers(); const { certificateSubjects, expiryFormatted, isWhitelisted } = useGoodId(account); return ( alert("Should navigate to the claim-page")}> For testing purposes. this card is using dev contracts ); }, args: { styles: { containerStyles: { width: "100%", space: 4 } }, isWhitelisted: false, fullname: "Just a name" } }; export const SegmentationScreen = { render: (args: any) => { const { account = "" } = useEthers(); const certificates = useAggregatedCertificates(args.account ?? account); const certificateSubjects = useCertificatesSubject(certificates); return ( ); }, args: {} }; export const SegmentationFlow = { render: (args: any) => { const { account = "" } = useEthers(); const { certificates, certificateSubjects, expiryFormatted, isWhitelisted } = useGoodId(account); return ( alert("Should navigate to the claim-page")}> For testing purposes. this flow is using staging/QA contracts { console.log({ e }); alert("Segmentation finished"); }} /> ); }, args: { width: "100%", account: "0x00", env: "fuse" } }; export const OnboardScreenExample = { render: (args: any) => { const { account = "" } = useEthers(); const { expiryDate, styles } = args; const formattedExpiryTimestamp = moment(expiryDate).format("MMMM DD, YYYY"); return ( alert("This is just a UI Demo")} {...args} expiryDate={formattedExpiryTimestamp} {...styles} /> ); }, args: { name: "test user", account: "0x066", isWhitelisted: true, isPending: false, hasCertificates: false, expiryDate: new Date().getTime(), styles: { width: "100%" } } }; export const OnboardFlowExample: Meta & { defaultLanguage: string }> = { decorators: [ (Story: any) => ( ) ], render: args => { const { account } = useEthers(); const { setLanguage } = useGoodUILanguage(); return ( {`When demo/testing this story, make sure you cleared your existing certificates and permissions! (clear cache). Also reset your location permissions for the domain. If you don't see a onboard screen, this means there is still a permission 'tos-accepted' in your local-storage.`} setLanguage("es-419")}>Spanish setLanguage("en")}>English ); }, args: { name: "testuser", // onFV: () => alert("onFV"), onSkip: () => alert("Already verified, should go to claim-page"), onDone: async (e: any) => { alert("segmentation complemented, should go to claim-page (Available offers not part of this demo-flow)"); console.log("onDone", e); }, onExit: () => alert("Should exit the flow"), width: "100%", withNavBar: true, isDev: true } }; export const OffersAgreementExample = { render: (args: any) => ( ), args: { width: "100%" } }; export const SegmentationConfirmationScreenExample = { render: (args: any) => { const { account = "" } = useEthers(); const [isWhitelisted] = useIsAddressVerified(account); const [expiryDate, , state] = useIdentityExpiryDate(account); const certificates = useAggregatedCertificates(args.account ?? account); const certificateSubjects = useCertificatesSubject(certificates); return ( ); }, args: { width: "100%" } }; export const SegmentationDisputeScreenExample = { render: (args: any) => { const { account = "" } = useEthers(); const certificates = useAggregatedCertificates(account); const certificateSubjects = useCertificatesSubject(certificates); return ( For testing purposes, this screen is using staging/QA contracts { console.log("Following is to be reported to ga/amp:", { disputedValues }); }} {...args} /> ); }, args: { width: "100%" } }; export const DisputeThanksScreenExample = { render: (args: any) => { const { containerStyles, screenStyles } = args.styles; return ( ); }, args: { styles: { containerStyles: { width: "100%" }, screenStyles: {} } } }; type AvailableOffersPropsAndArgs = React.ComponentProps & { countryCode?: string }; const explorerEndPoints = { CELO: "https://celo.blockscout.com/api?", FUSE: "https://explorer.fuse.io/api?", MAINNET: "" }; type ClaimArgs = { claimArgs: { onNews: () => void; onUpgrade: () => void; isDev: boolean; }; }; export const CheckAvailableOffersExample: Meta = { title: "Core/Modals", component: CheckAvailableOffers, render: args => { const { account, chainId } = useEthers(); // const mockPool = [ // { // campaign: "RedTent", // Location: { // countryCode: args.countryCode ?? "NG" // } // } // ]; const { setLanguage } = useGoodUILanguage(); if (!chainId) return ; return ( setLanguage("en")}>English setLanguage("es-419")}>Spanish {`If you see finished demo change in the controls the country-code the country of your certificate. \n If you have no certificates, go through the segmentation or onboard flow stories to get one.`} { console.log("Finished demo"); }} withNavBar={true} isDev={true} /> ); }, args: { countryCode: "Fill in your two-letter country-code", claimArgs: { onNews: () => { alert("Should go to news page"); }, onUpgrade: () => { alert("Should go to goodid upgrade page"); }, isDev: true } }, argTypes: { account: { description: "User account address, the wallet you currently are connected with." }, countryCode: { description: "What country are you located in?" } } }; export default { title: "Apps/GoodId", component: GoodIdCard, decorators: [ (Story: any) => ( ) ], argTypes: { language: { description: "Set the language of the UI", control: { type: "text" } } } };