From 53fd20b28eb452c81008fac2bd7b67ba342e5038 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 22 Dec 2021 10:45:50 +0100 Subject: [PATCH] use modals in matamo & origin --- .../app/src/lib/remix-app/actions/modals.ts | 12 ++--- .../remix-app/components/modals/dialogs.tsx | 10 ---- .../remix-app/components/modals/matomo.tsx | 49 +++++++++---------- .../components/modals/modal-wrapper.tsx | 5 +- .../components/modals/origin-warning.tsx | 28 ++++------- .../src/lib/remix-app/context/provider.tsx | 10 ++-- .../app/src/lib/remix-app/reducer/modals.ts | 10 ++-- 7 files changed, 54 insertions(+), 70 deletions(-) diff --git a/libs/remix-ui/app/src/lib/remix-app/actions/modals.ts b/libs/remix-ui/app/src/lib/remix-app/actions/modals.ts index 4d11831bc6..95400ca77b 100644 --- a/libs/remix-ui/app/src/lib/remix-app/actions/modals.ts +++ b/libs/remix-ui/app/src/lib/remix-app/actions/modals.ts @@ -1,6 +1,6 @@ import { AppModal } from '../interface' -export type ActionMap = { +type ActionMap = { [Key in keyof M]: M[Key] extends undefined ? { type: Key; @@ -11,7 +11,7 @@ export type ActionMap = { } } -export const enum actionTypes { +export const enum modalActionTypes { setModal = 'SET_MODAL', setToast = 'SET_TOAST', handleHideModal = 'HANDLE_HIDE_MODAL', @@ -19,10 +19,10 @@ export const enum actionTypes { } type ModalPayload = { - [actionTypes.setModal]: AppModal - [actionTypes.handleHideModal]: any - [actionTypes.setToast]: string - [actionTypes.handleToaster]: any + [modalActionTypes.setModal]: AppModal + [modalActionTypes.handleHideModal]: any + [modalActionTypes.setToast]: string + [modalActionTypes.handleToaster]: any } export type ModalAction = ActionMap[keyof ActionMap< diff --git a/libs/remix-ui/app/src/lib/remix-app/components/modals/dialogs.tsx b/libs/remix-ui/app/src/lib/remix-app/components/modals/dialogs.tsx index 2e1dd0cc1d..0173da73c2 100644 --- a/libs/remix-ui/app/src/lib/remix-app/components/modals/dialogs.tsx +++ b/libs/remix-ui/app/src/lib/remix-app/components/modals/dialogs.tsx @@ -8,16 +8,6 @@ const AppDialogs = () => { const { modal, toast, alert, handleHideModal, handleToaster } = useDialogDispatchers() const { focusModal, focusToaster } = useDialogs() - const ok = (returnedValue) => { - console.log('ok', returnedValue) - } - - useEffect(() => { - modal('test', 'Enter gist url', 'yes', ok, 'cancel', () => { }, ModalTypes.prompt, 'wss://remix.ethereum.org:8545') - toast('test toast') - // alert('fat error') - }, []) - return ( <> diff --git a/libs/remix-ui/app/src/lib/remix-app/components/modals/matomo.tsx b/libs/remix-ui/app/src/lib/remix-app/components/modals/matomo.tsx index cf95d1d4c7..82f4df86b0 100644 --- a/libs/remix-ui/app/src/lib/remix-app/components/modals/matomo.tsx +++ b/libs/remix-ui/app/src/lib/remix-app/components/modals/matomo.tsx @@ -1,27 +1,40 @@ import React, { useContext, useEffect, useState } from 'react' -import { ModalDialog } from '@remix-ui/modal-dialog' import { AppContext } from '../../context/context' +import { useDialogDispatchers } from '../../context/provider' const _paq = window._paq = window._paq || [] const MatomoDialog = (props) => { const { settings, showMatamo, appManager } = useContext(AppContext) + const { modal } = useDialogDispatchers() const [visible, setVisible] = useState(props.hide) + useEffect(() => { - if (showMatamo) { - setVisible(true) - } else { - setVisible(false) - } + }, []) + + const message = () => { + return (<>

An Opt-in version of Matomo, an open source data analytics platform is being used to improve Remix IDE.

+

We realize that our users have sensitive information in their code and that their privacy - your privacy - must be protected.

+

All data collected through Matomo is stored on our own server - no data is ever given to third parties. Our analytics reports are public: take a look.

+

We do not collect nor store any personally identifiable information (PII).

+

For more info, see: Matomo Analyitcs on Remix iDE.

+

You can change your choice in the Settings panel anytime.

) + } + + useEffect(() => { + if (visible && showMatamo) { + console.log('show matomo') + modal('Help us to improve Remix IDE', message(), 'Accept', handleModalOkClick, 'Decline', declineModal) + } + }, [visible]) + const declineModal = async () => { settings.updateMatomoAnalyticsChoice(false) _paq.push(['optUserOut']) appManager.call('walkthrough', 'start') setVisible(false) } - const hideModal = async () => { - setVisible(false) - } + const handleModalOkClick = async () => { _paq.push(['forgetUserOptOut']) // @TODO remove next line when https://github.com/matomo-org/matomo/commit/9e10a150585522ca30ecdd275007a882a70c6df5 is used @@ -30,22 +43,8 @@ const MatomoDialog = (props) => { appManager.call('walkthrough', 'start') setVisible(false) } - return ( -

An Opt-in version of Matomo, an open source data analytics platform is being used to improve Remix IDE.

-

We realize that our users have sensitive information in their code and that their privacy - your privacy - must be protected.

-

All data collected through Matomo is stored on our own server - no data is ever given to third parties. Our analytics reports are public: take a look.

-

We do not collect nor store any personally identifiable information (PII).

-

For more info, see: Matomo Analyitcs on Remix iDE.

-

You can change your choice in the Settings panel anytime.

-
) + + return (<>) } export default MatomoDialog diff --git a/libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx b/libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx index b5a6c1d807..c86b29ed8d 100644 --- a/libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx +++ b/libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx @@ -45,10 +45,13 @@ const ModalWrapper = (props: ModalWrapperProps) => { setState({ ...props }) break } + } else { + setState({ ...props }) } }, [props]) return ( - ) + + ) } export default ModalWrapper diff --git a/libs/remix-ui/app/src/lib/remix-app/components/modals/origin-warning.tsx b/libs/remix-ui/app/src/lib/remix-app/components/modals/origin-warning.tsx index 19c8f41c27..f44f0c622c 100644 --- a/libs/remix-ui/app/src/lib/remix-app/components/modals/origin-warning.tsx +++ b/libs/remix-ui/app/src/lib/remix-app/components/modals/origin-warning.tsx @@ -1,9 +1,10 @@ import React, { useEffect, useState } from 'react' import { ModalDialog } from '@remix-ui/modal-dialog' +import { useDialogDispatchers } from '../../context/provider' const OriginWarning = () => { - const [visible, setVisible] = useState(true) - const [content, setContent] = useState('') + const { alert } = useDialogDispatchers() + const [content, setContent] = useState(null) useEffect(() => { // check the origin and warn message @@ -20,24 +21,15 @@ const OriginWarning = () => { This instance of Remix you are visiting WILL NOT BE UPDATED.\n Please make a backup of your contracts and start using http://remix.ethereum.org`) } - setVisible(content !== '') }, []) - const closeModal = async () => { - setVisible(false) - } - const handleModalOkClick = async () => { - setVisible(false) - } - return ({content}) + useEffect(() => { + if (content) { + alert(content) + } + }, [content]) + + return (<>) } export default OriginWarning diff --git a/libs/remix-ui/app/src/lib/remix-app/context/provider.tsx b/libs/remix-ui/app/src/lib/remix-app/context/provider.tsx index e590c60631..0fc3e776a5 100644 --- a/libs/remix-ui/app/src/lib/remix-app/context/provider.tsx +++ b/libs/remix-ui/app/src/lib/remix-app/context/provider.tsx @@ -1,5 +1,5 @@ import React, { useReducer } from 'react' -import { actionTypes } from '../actions/modals' +import { modalActionTypes } from '../actions/modals' import { modalReducer } from '../reducer/modals' import { ModalInitialState } from '../state/modals' import { ModalTypes } from '../types' @@ -10,7 +10,7 @@ export const ModalProvider = ({ children = [], reducer = modalReducer, initialSt const modal = (title: string, message: string | JSX.Element, okLabel: string, okFn: (value?:any) => void, cancelLabel?: string, cancelFn?: () => void, modalType?: ModalTypes, defaultValue?: string) => { dispatch({ - type: actionTypes.setModal, + type: modalActionTypes.setModal, payload: { title, message, okLabel, okFn, cancelLabel, cancelFn, modalType: modalType || ModalTypes.default, defaultValue: defaultValue } }) } @@ -21,21 +21,21 @@ export const ModalProvider = ({ children = [], reducer = modalReducer, initialSt const handleHideModal = () => { dispatch({ - type: actionTypes.handleHideModal, + type: modalActionTypes.handleHideModal, payload: null }) } const toast = (message: string) => { dispatch({ - type: actionTypes.setToast, + type: modalActionTypes.setToast, payload: message }) } const handleToaster = () => { dispatch({ - type: actionTypes.handleToaster, + type: modalActionTypes.handleToaster, payload: null }) } diff --git a/libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts b/libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts index d2f8ac1b39..106aa837a7 100644 --- a/libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts +++ b/libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts @@ -1,11 +1,11 @@ -import { actionTypes, ModalAction } from '../actions/modals' +import { modalActionTypes, ModalAction } from '../actions/modals' import { ModalInitialState } from '../state/modals' import { AppModal, ModalState } from '../interface' export const modalReducer = (state: ModalState = ModalInitialState, action: ModalAction) => { console.log(action) switch (action.type) { - case actionTypes.setModal: { + case modalActionTypes.setModal: { console.log('set modal', action, Date.now()) let modalList:AppModal[] = state.modals modalList.push(action.payload) @@ -28,12 +28,12 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda } return { ...state, modals: modalList } } - case actionTypes.handleHideModal: + case modalActionTypes.handleHideModal: console.log('handle hid', JSON.stringify(state.modals)) state.focusModal = { ...state.focusModal, hide: true, message: null } return { ...state } - case actionTypes.setToast: + case modalActionTypes.setToast: state.toasters.push(action.payload) if (state.toasters.length > 0) { const focus = state.toasters[0] @@ -42,7 +42,7 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda } return { ...state } - case actionTypes.handleToaster: + case modalActionTypes.handleToaster: return { ...state, focusToaster: '' } } }