Skip to content

Commit

Permalink
332/warning when pinata envs not set locally (#659)
Browse files Browse the repository at this point in the history
* Added `localWarning` for PINATA keys

* Displaying localWarning if any

* Added alternative warning display:

As a permanent toast notification

* Refactor: Renamed WarningPopupContent `message` to `warning`

* Added warning icon to toast notification

* Moved localWarning from Header to state/application

* Changed warning popup key to a more generic value

* Removed banner with warning in favor of the popup notification
  • Loading branch information
alfetopito committed Jun 24, 2022
1 parent 8ae1455 commit 596abcf
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/custom/components/Header/URLWarning/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default function URLWarning() {

const announcementVisible = useAnnouncementVisible(contentHash)
const closeAnnouncement = useCloseAnnouncement()

const announcement = announcementVisible && announcementText && (
<>
<div style={{ display: 'flex' }}>
Expand Down
4 changes: 4 additions & 0 deletions src/custom/components/Popups/PopupItemMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TransactionPopup from './TransactionPopupMod'

// MOD imports
import ListUpdatePopup from 'components/Popups/ListUpdatePopup'
import { WarningPopup } from 'components/Popups/WarningPopup'

export const StyledClose = styled(X)`
position: absolute;
Expand Down Expand Up @@ -84,6 +85,7 @@ export default function PopupItem({
const isListUpdate = 'listUpdate' in content
const isUnsupportedNetwork = 'unsupportedNetwork' in content
const isMetaTxn = 'metatxn' in content
const isWarningTxn = 'warning' in content

let popupContent
if (isTxn) {
Expand All @@ -105,6 +107,8 @@ export default function PopupItem({
popupContent = <FailedNetworkSwitchPopup chainId={content.failedSwitchNetwork} isUnsupportedNetwork />
} else if ('failedSwitchNetwork' in content) {
popupContent = <FailedNetworkSwitchPopup chainId={content.failedSwitchNetwork} />
} else if (isWarningTxn) {
popupContent = <WarningPopup warning={content.warning} />
}

const faderStyle = useSpring({
Expand Down
28 changes: 28 additions & 0 deletions src/custom/components/Popups/WarningPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useContext } from 'react'
import styled, { ThemeContext } from 'styled-components/macro'

import { ThemedText } from 'theme'
import { AutoColumn } from 'components/Column'
import { AutoRow } from 'components/Row'
import { AlertCircle } from 'react-feather'

const RowNoFlex = styled(AutoRow)`
flex-wrap: nowrap;
`

export function WarningPopup({ warning }: { warning: string | JSX.Element }) {
const theme = useContext(ThemeContext)

return (
<RowNoFlex>
<div style={{ paddingRight: 16 }}>
<AlertCircle color={theme.red1} size={24} />
</div>
<AutoColumn gap="sm">
<ThemedText.Body fontWeight={'bold'} color={theme.danger}>
{warning}
</ThemedText.Body>
</AutoColumn>
</RowNoFlex>
)
}
17 changes: 17 additions & 0 deletions src/custom/state/application/initialState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApplicationState } from '@src/state/application/reducer'
import { localWarning } from 'state/application/localWarning'

const popupList: ApplicationState['popupList'] = []

if (localWarning) {
popupList.push({
key: 'localWarning',
show: true,
removeAfterMs: null,
content: {
warning: localWarning,
},
})
}

export const initialState: ApplicationState = { chainId: null, openModal: null, popupList }
12 changes: 12 additions & 0 deletions src/custom/state/application/localWarning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PINATA_API_KEY, PINATA_SECRET_API_KEY } from 'constants/ipfs'
import { isLocal } from 'utils/environments'

let warningMsg

if ((!PINATA_SECRET_API_KEY || !PINATA_API_KEY) && isLocal) {
warningMsg =
"Pinata env vars not set. Order appData upload won't work! " +
'Set REACT_APP_PINATA_API_KEY and REACT_APP_PINATA_SECRET_API_KEY'
}

export const localWarning = warningMsg
11 changes: 7 additions & 4 deletions src/state/application/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { createSlice, nanoid } from '@reduxjs/toolkit'
import { DEFAULT_TXN_DISMISS_MS } from 'constants/misc'

import { SupportedChainId } from 'constants/chains'
import { FlattenInterpolation, ThemeProps, DefaultTheme } from 'styled-components/macro' // mod
import { FlattenInterpolation, ThemeProps, DefaultTheme } from 'styled-components/macro'
import { initialState } from 'state/application/initialState' // mod

type BasePopupContent =
// | {
Expand All @@ -18,7 +19,7 @@ type BasePopupContent =
}

// MOD: Modified PopupContent. The mod happened directly in the src file, to avoid redefining the state/hoos/etc
export type PopupContent = (TxPopupContent | MetaTxPopupContent | BasePopupContent) & {
export type PopupContent = (TxPopupContent | MetaTxPopupContent | BasePopupContent | WarningPopupContent) & {
// mod: custom styles
styles?: FlattenInterpolation<ThemeProps<DefaultTheme>>
}
Expand All @@ -39,6 +40,8 @@ export interface MetaTxPopupContent {
}
}

export type WarningPopupContent = { warning: string }

export enum ApplicationModal {
WALLET,
SETTINGS,
Expand Down Expand Up @@ -67,11 +70,11 @@ export interface ApplicationState {
readonly popupList: PopupList
}

const initialState: ApplicationState = {
/* const initialState: ApplicationState = {
chainId: null,
openModal: null,
popupList: [],
}
} */

const applicationSlice = createSlice({
name: 'application',
Expand Down

0 comments on commit 596abcf

Please sign in to comment.