-
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.
- Loading branch information
1 parent
3373c0f
commit 4b237ac
Showing
19 changed files
with
200 additions
and
15 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion
2
...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
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
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
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
16 changes: 16 additions & 0 deletions
16
packages/browser-wallet/src/popup/popupX/shared/Toast/Messages.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,16 @@ | ||
import React from 'react'; | ||
import Check from '@assets/svgX/check.svg'; | ||
import { displaySplitAddressShort } from '@popup/shared/utils/account-helpers'; | ||
import Text from '@popup/popupX/shared/Text'; | ||
|
||
export function CopyAddress({ address, message }: { address: string; message: string }) { | ||
return ( | ||
<div className="copy-address-x"> | ||
<Check /> | ||
<div className="copy-message"> | ||
<Text.Label>{message}</Text.Label> | ||
<Text.Capture>{displaySplitAddressShort(address)}</Text.Capture> | ||
</div> | ||
</div> | ||
); | ||
} |
74 changes: 74 additions & 0 deletions
74
packages/browser-wallet/src/popup/popupX/shared/Toast/Toast.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,74 @@ | ||
.toast-x { | ||
visibility: hidden; | ||
width: rem(175px); | ||
left: 0; | ||
right: 0; | ||
margin: 0 auto; | ||
background-color: $color-white; | ||
color: $color-black; | ||
text-align: center; | ||
border-radius: rem(16px); | ||
padding: rem(10px) rem(15px); | ||
position: absolute; | ||
z-index: 2; | ||
bottom: rem(16px); | ||
backdrop-filter: blur(5px); | ||
box-shadow: 0 -6px 15.3px 0 rgba($color-black, 0.25); | ||
|
||
&__show { | ||
visibility: visible; | ||
animation: fadein-toast 0.5s; | ||
} | ||
|
||
&__fadeout { | ||
visibility: visible; | ||
animation: fadeout-toast 0.5s; | ||
} | ||
|
||
@keyframes fadein-toast { | ||
from { | ||
bottom: 0; | ||
opacity: 0; | ||
} | ||
|
||
to { | ||
bottom: rem(16px); | ||
opacity: 1; | ||
} | ||
} | ||
|
||
@keyframes fadeout-toast { | ||
from { | ||
bottom: rem(16px); | ||
opacity: 1; | ||
} | ||
|
||
to { | ||
bottom: rem(16px); | ||
opacity: 0; | ||
} | ||
} | ||
} | ||
|
||
.copy-address-x { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
|
||
.copy-message { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
gap: rem(4px); | ||
margin-left: rem(10px); | ||
|
||
.label__main { | ||
color: $color-black; | ||
white-space: nowrap; | ||
} | ||
|
||
.capture__main_small { | ||
color: $color-black; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/browser-wallet/src/popup/popupX/shared/Toast/Toast.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,49 @@ | ||
import { toastsAtom } from '@popup/state'; | ||
import clsx from 'clsx'; | ||
import { useAtom } from 'jotai'; | ||
import React, { ReactNode, useEffect, useState } from 'react'; | ||
import { noOp } from 'wallet-common-helpers'; | ||
|
||
// The fadeout timeout has to be aligned with the animation in the corresponding CSS. This is | ||
// done by manually tweaking the values until the animation looks decent. Currently the value | ||
// is 100ms less than the corresponding value in CSS. | ||
const fadeoutTimeoutMs = 400; | ||
|
||
// Determines how long we display the toast. | ||
const toastTimeoutMs = 5000; | ||
|
||
export default function Toast() { | ||
const [toasts, setToasts] = useAtom(toastsAtom); | ||
const [toastText, setToastText] = useState<string | ReactNode>(); | ||
const [fadeout, setFadeout] = useState<boolean>(false); | ||
useEffect(() => { | ||
if (!toastText && toasts.length > 0) { | ||
const [nextToast, ...remainderToasts] = toasts; | ||
setToastText(nextToast); | ||
setToasts(remainderToasts); | ||
} | ||
}, [toasts, toastText]); | ||
|
||
useEffect(() => { | ||
if (toastText) { | ||
const fadeoutTimer = setTimeout(() => { | ||
setFadeout(true); | ||
setTimeout(() => setFadeout(false), fadeoutTimeoutMs); | ||
}, toastTimeoutMs - fadeoutTimeoutMs); | ||
|
||
const timeout = setTimeout(() => { | ||
setToastText(undefined); | ||
}, toastTimeoutMs); | ||
|
||
return () => { | ||
clearTimeout(timeout); | ||
clearTimeout(fadeoutTimer); | ||
}; | ||
} | ||
return noOp; | ||
}, [toastText]); | ||
|
||
return ( | ||
<div className={clsx('toast-x', toastText && 'toast-x__show', fadeout && 'toast-x__fadeout')}>{toastText}</div> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/browser-wallet/src/popup/popupX/shared/Toast/index.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 @@ | ||
export { default } from './Toast'; |
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
24 changes: 24 additions & 0 deletions
24
packages/browser-wallet/src/popup/popupX/shared/utils/hooks.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,24 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useSetAtom } from 'jotai'; | ||
import { addToastAtom } from '@popup/state'; | ||
import { copyToClipboard } from '@popup/popupX/shared/utils/helpers'; | ||
import { CopyAddress } from '@popup/popupX/shared/Toast/Messages'; | ||
|
||
export function useCopyAddress() { | ||
const { t } = useTranslation('x', { keyPrefix: 'sharedX.messages' }); | ||
const addToast = useSetAtom(addToastAtom); | ||
|
||
return (address: string) => { | ||
copyToClipboard(address).then(() => addToast(<CopyAddress address={address} message={t('addressCopied')} />)); | ||
}; | ||
} | ||
|
||
export function useCopyToClipboard() { | ||
const { t } = useTranslation('x', { keyPrefix: 'sharedX.messages' }); | ||
const addToast = useSetAtom(addToastAtom); | ||
|
||
return (text: string) => { | ||
copyToClipboard(text).then(() => addToast(t('copied'))); | ||
}; | ||
} |
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
Oops, something went wrong.