-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added prompt window handling for old and new UI
Added ConnectionRequest page Updated styles
- Loading branch information
1 parent
d5e242c
commit 5846799
Showing
28 changed files
with
520 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ser-wallet/src/popup/popupX/page-layouts/ExternalRequestLayout/ExternalRequestLayout.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.external-request-layout-x { | ||
height: calc(100% - 2.4rem); | ||
overflow: hidden; | ||
max-width: rem(1328px); | ||
margin: auto; | ||
|
||
&__main { | ||
padding: rem(20px) rem(24px) 0 rem(24px); | ||
margin: auto; | ||
height: 100%; | ||
max-width: rem(703px); | ||
overflow: auto; | ||
|
||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...wser-wallet/src/popup/popupX/page-layouts/ExternalRequestLayout/ExternalRequestLayout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useMemo } from 'react'; | ||
import { Outlet } from 'react-router-dom'; | ||
import Toast from '@popup/shared/Toast/Toast'; | ||
import clsx from 'clsx'; | ||
import { Connection, Fullscreen } from '@popup/popupX/page-layouts/MainLayout/Header/components'; | ||
import FullscreenPromptLayout from '@popup/popupX/page-layouts/FullscreenPromptLayout'; | ||
|
||
function Header({ isScrolling }: { isScrolling: boolean }) { | ||
return ( | ||
<div className={clsx('main-header', isScrolling && 'scroll-border')}> | ||
<div className="main-header__top"> | ||
<Fullscreen /> | ||
<Connection hideConnection={false} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default function ExternalRequestLayout() { | ||
const [scroll, setScroll] = React.useState(0); | ||
const isScrolling = useMemo(() => scroll > 0, [!!scroll]); | ||
return ( | ||
<FullscreenPromptLayout> | ||
<Header isScrolling={isScrolling} /> | ||
<div className="external-request-layout-x"> | ||
<main | ||
className={clsx('external-request-layout-x__main')} | ||
onScroll={(e) => { | ||
setScroll(e.currentTarget.scrollTop); | ||
}} | ||
> | ||
<Outlet /> | ||
</main> | ||
<Toast /> | ||
</div> | ||
</FullscreenPromptLayout> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/browser-wallet/src/popup/popupX/page-layouts/ExternalRequestLayout/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './ExternalRequestLayout'; |
74 changes: 74 additions & 0 deletions
74
...er-wallet/src/popup/popupX/page-layouts/FullscreenPromptLayout/FullscreenPromptLayout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { createContext, useRef, useCallback, useMemo, useState, ReactNode } from 'react'; | ||
import { useNavigate, To } from 'react-router-dom'; | ||
import { noOp } from 'wallet-common-helpers'; | ||
|
||
import { isSpawnedWindow } from '@popup/shared/window-helpers'; | ||
|
||
type OnCloseHandler = () => void; | ||
type Unsubscribe = () => void; | ||
|
||
type OnClose = (handler: OnCloseHandler) => Unsubscribe; | ||
type WithClose = <A extends unknown[]>(action: (...args: A) => void) => (...args: A) => void; | ||
|
||
type FullscreenPromptContext = { | ||
onClose: OnClose; | ||
/** | ||
* Generate an action, that also closes the prompt. | ||
*/ | ||
withClose: WithClose; | ||
/** | ||
* | ||
*/ | ||
setReturnLocation: (location: To) => void; | ||
}; | ||
|
||
const defaultContext: FullscreenPromptContext = { | ||
onClose: () => noOp, | ||
withClose: () => noOp, | ||
setReturnLocation: noOp, | ||
}; | ||
|
||
export const fullscreenPromptContext = createContext<FullscreenPromptContext>(defaultContext); | ||
|
||
export default function FullscreenPromptLayout({ children }: { children: ReactNode }) { | ||
const nav = useNavigate(); | ||
const [returnLocation, setReturnLocation] = useState<To>(); | ||
|
||
const closeHandler = useRef<OnCloseHandler>(); | ||
const close = useCallback(() => { | ||
closeHandler?.current?.(); | ||
|
||
if (isSpawnedWindow) { | ||
window.close(); | ||
} else if (returnLocation) { | ||
nav(returnLocation); | ||
} else { | ||
// Go back | ||
nav(-1); | ||
} | ||
}, [returnLocation]); | ||
|
||
const withClose: WithClose = useCallback( | ||
(action) => | ||
(...args) => { | ||
action(...args); | ||
close(); | ||
}, | ||
[close] | ||
); | ||
|
||
const onClose: OnClose = useCallback((handler) => { | ||
closeHandler.current = handler; | ||
|
||
return () => { | ||
closeHandler.current = undefined; | ||
}; | ||
}, []); | ||
|
||
const contextValue: FullscreenPromptContext = useMemo( | ||
() => ({ onClose, withClose, setReturnLocation }), | ||
[onClose, withClose] | ||
); | ||
|
||
return <fullscreenPromptContext.Provider value={contextValue}>{children}</fullscreenPromptContext.Provider>; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/browser-wallet/src/popup/popupX/page-layouts/FullscreenPromptLayout/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, fullscreenPromptContext } from './FullscreenPromptLayout'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...es/browser-wallet/src/popup/popupX/pages/prompts/ConnectionRequest/ConnectionRequest.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.connection-request-x { | ||
.text__main { | ||
color: $color-mineral-2; | ||
} | ||
|
||
.white { | ||
color: $color-white; | ||
} | ||
|
||
.capture__main_small { | ||
margin-top: rem(24px); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...ges/browser-wallet/src/popup/popupX/pages/prompts/ConnectionRequest/ConnectionRequest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
import { useAtom, useAtomValue } from 'jotai'; | ||
import Page from '@popup/popupX/shared/Page'; | ||
import Text from '@popup/popupX/shared/Text'; | ||
import Button from '@popup/popupX/shared/Button'; | ||
import { displayNameOrSplitAddress } from '@popup/shared/utils/account-helpers'; | ||
import { selectedCredentialAtom, storedAllowlistAtom } from '@popup/store/account'; | ||
import { fullscreenPromptContext } from '@popup/popupX/page-layouts/FullscreenPromptLayout'; | ||
import { handleAllowlistEntryUpdate } from '@popup/pages/Allowlist/util'; | ||
import { useUrlDisplay } from '@popup/popupX/shared/utils/helpers'; | ||
|
||
type Props = { | ||
onAllow(): void; | ||
onReject(): void; | ||
}; | ||
|
||
export default function ConnectionRequest({ onAllow, onReject }: Props) { | ||
const { t } = useTranslation('x', { keyPrefix: 'prompts.connectionRequestX' }); | ||
const [urlDisplay, url] = useUrlDisplay(); | ||
const { onClose, withClose } = useContext(fullscreenPromptContext); | ||
const selectedAccount = useAtomValue(selectedCredentialAtom); | ||
const [allowlistLoading, setAllowlist] = useAtom(storedAllowlistAtom); | ||
const allowlist = allowlistLoading.value; | ||
const [connectButtonDisabled, setConnectButtonDisabled] = useState<boolean>(false); | ||
|
||
useEffect(() => onClose(onReject), [onClose, onReject]); | ||
|
||
if (!selectedAccount || allowlistLoading.loading) { | ||
return null; | ||
} | ||
|
||
async function connectAccount(account: string, urlString: string) { | ||
await handleAllowlistEntryUpdate(urlString, allowlist, [account], setAllowlist); | ||
} | ||
|
||
return ( | ||
<Page className="connection-request-x"> | ||
<Page.Top heading={t('newConnection')} /> | ||
<Page.Main> | ||
<Text.Main> | ||
<Trans | ||
ns="x" | ||
i18nKey="prompts.connectionRequestX.connectTo" | ||
components={{ 1: <span className="white" /> }} | ||
values={{ dApp: urlDisplay, account: displayNameOrSplitAddress(selectedAccount) }} | ||
/> | ||
</Text.Main> | ||
<Text.Capture> | ||
<Trans | ||
ns="x" | ||
i18nKey="prompts.connectionRequestX.connectionDetails" | ||
components={{ 1: <span className="white" /> }} | ||
values={{ dApp: urlDisplay }} | ||
/> | ||
</Text.Capture> | ||
</Page.Main> | ||
<Page.Footer> | ||
<Button.Main className="secondary" label={t('cancel')} onClick={withClose(onReject)} /> | ||
<Button.Main | ||
label={t('connect')} | ||
disabled={connectButtonDisabled} | ||
onClick={() => { | ||
setConnectButtonDisabled(true); | ||
connectAccount(selectedAccount.address, new URL(url).origin).then(withClose(onAllow)); | ||
}} | ||
/> | ||
</Page.Footer> | ||
</Page> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/browser-wallet/src/popup/popupX/pages/prompts/ConnectionRequest/i18n/en.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const t = { | ||
newConnection: 'New connection', | ||
connectTo: 'Connect {{ account }} to \n<1>{{dApp}}</1> ?', | ||
connectionDetails: | ||
'This will allow <1>{{dApp}}</1> to see your account address, public balance, transaction history, and suggest transactions to sign.\n\nYou should only connect your account to websites and services you trust.', | ||
connect: 'Connect', | ||
cancel: 'Cancel', | ||
}; | ||
|
||
export default t; |
1 change: 1 addition & 0 deletions
1
packages/browser-wallet/src/popup/popupX/pages/prompts/ConnectionRequest/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './ConnectionRequest'; |
Oops, something went wrong.