Skip to content

Commit

Permalink
Merge pull request #900 from tallycash/revert-818-persist-ui
Browse files Browse the repository at this point in the history
Revert "🗃 Preserve location when reopening extension"
  • Loading branch information
mhluongo authored Jan 26, 2022
2 parents dea70bd + dd22361 commit 5574d09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 49 deletions.
53 changes: 5 additions & 48 deletions ui/pages/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, useState, useRef } from "react"
import React, { ReactElement, useState } from "react"
import { MemoryRouter as Router, Switch, Route } from "react-router-dom"
import classNames from "classnames"

Expand All @@ -24,16 +24,9 @@ const pagePreferences = Object.fromEntries(
])
)

const initialEntries = JSON.parse(
(localStorage.getItem("entries") !== "undefined" &&
localStorage.getItem("entries")) ||
`["/"]`
)

interface Location {
key: string
pathname: string
key?: string
hash: string
}

function transformLocation(inputLocation: Location): Location {
Expand Down Expand Up @@ -61,39 +54,6 @@ export default function Popup({ store }: { store: Store }): ReactElement {
const [shouldDisplayDecoy, setShouldDisplayDecoy] = useState(false)
const [isDirectionRight, setIsDirectionRight] = useState(true)
const [showTabBar, setShowTabBar] = useState(true)
const renderCount = useRef(0)

function saveHistoryEntries(routeHistoryEntities: Location[]) {
const isNotOnKeyringRelatedPage =
routeHistoryEntities[routeHistoryEntities.length - 1].pathname !==
"/signTransaction" &&
!routeHistoryEntities[routeHistoryEntities.length - 1].pathname.includes(
"/keyring/"
)

// Initial extension load takes two renders because of setting
// animation control states. `initialEntries` needs to be a reversed
// version of route history entities. Without avoiding the initial load,
// entries will keep reversing.
if (renderCount.current > 1 && isNotOnKeyringRelatedPage) {
const entries = routeHistoryEntities
.reduce((agg: Partial<Location>[], entity) => {
const { ...entityCopy } = entity as Partial<Location>
delete entityCopy.hash
delete entityCopy.key
agg.push(entityCopy)
return agg
}, [])
.reverse()

localStorage.setItem(
"entries",
JSON.stringify(entries, (key, value) => {
return value
})
)
}
}

return (
<>
Expand All @@ -102,16 +62,14 @@ export default function Popup({ store }: { store: Store }): ReactElement {
<TopMenu />
</div>
<div className="community_edition_label">Community Edition</div>
<Router initialEntries={initialEntries}>
<Router>
<Route
render={(routeProps) => {
// @ts-expect-error TODO: fix the typing when the feature works
const transformedLocation = transformLocation(routeProps.location)
// @ts-expect-error TODO: fix the typing
saveHistoryEntries(routeProps?.history?.entries)

const normalizedPathname =
transformedLocation.pathname !== "/wallet"
? transformedLocation.pathname
? routeProps.location.pathname
: "/"

setAnimationConditions(
Expand All @@ -121,7 +79,6 @@ export default function Popup({ store }: { store: Store }): ReactElement {
setIsDirectionRight
)
setShowTabBar(pagePreferences[normalizedPathname].hasTabBar)
renderCount.current += 1

return (
<TransitionGroup>
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/SignTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface SignLocationState {
export default function SignTransaction({
location,
}: {
location: { key?: string; pathname: string; state?: SignLocationState }
location: { key: string; pathname: string; state?: SignLocationState }
}): ReactElement {
const [networkSettingsModalOpen, setNetworkSettingsModalOpen] =
useState(false)
Expand Down

0 comments on commit 5574d09

Please sign in to comment.