-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Render toast if the pricing service is down * Allow for external deposit urls * VQA feedback
- Loading branch information
Showing
8 changed files
with
246 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
.DS_Store | ||
*.pem | ||
.idea | ||
*.client-test.* | ||
|
||
# debug | ||
npm-debug.log* | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Button, Dialog, DialogContent, DialogHeader, Text } from 'junoblocks' | ||
|
||
type DepositRedirectDialogProps = { | ||
isShowing: boolean | ||
onRequestClose: () => void | ||
tokenSymbol: string | ||
href: string | ||
} | ||
|
||
export const DepositRedirectDialog = ({ | ||
isShowing, | ||
onRequestClose, | ||
tokenSymbol, | ||
href, | ||
}: DepositRedirectDialogProps) => { | ||
return ( | ||
<Dialog isShowing={isShowing} onRequestClose={onRequestClose}> | ||
<DialogHeader paddingBottom="$10"> | ||
<Text variant="header">External asset deposit</Text> | ||
</DialogHeader> | ||
<DialogContent css={{ paddingBottom: '$12' }}> | ||
<Text css={{ paddingBottom: '$12' }} variant="body"> | ||
You will be redirected to an external service to deposit your{' '} | ||
{tokenSymbol} on the chain. | ||
</Text> | ||
<Button | ||
as="a" | ||
href={href} | ||
target="__blank" | ||
css={{ width: '100%' }} | ||
size="large" | ||
onClick={onRequestClose} | ||
> | ||
Proceed | ||
</Button> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} |
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 was deleted.
Oops, something went wrong.
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,56 @@ | ||
import { ErrorIcon, Toast } from 'junoblocks' | ||
import React from 'react' | ||
import { toast } from 'react-hot-toast' | ||
|
||
import { TokenInfo } from '../hooks/useTokenList' | ||
|
||
const pricingServiceIsDownAlert = createAlertPricingServiceIsDown() | ||
|
||
export async function tokenDollarValueQuery(tokenIds: Array<TokenInfo['id']>) { | ||
const prices = await fetchTokensPrice(tokenIds) | ||
return tokenIds.map((id): number => prices[id]?.usd || 0) | ||
} | ||
|
||
async function fetchTokensPrice(tokenIds: Array<string>) { | ||
const response = await fetch( | ||
`https://api.coingecko.com/api/v3/simple/price?ids=${tokenIds.join( | ||
',' | ||
)}&vs_currencies=usd`, | ||
{ | ||
method: 'GET', | ||
} | ||
) | ||
|
||
if (!response.ok) { | ||
pricingServiceIsDownAlert() | ||
throw new Error('Cannot fetch dollar price from the API.') | ||
} | ||
|
||
return response.json() | ||
} | ||
|
||
function createAlertPricingServiceIsDown() { | ||
let hasRenderedAlert | ||
let timeout | ||
|
||
function renderAlert() { | ||
toast.custom((t) => ( | ||
<Toast | ||
icon={<ErrorIcon />} | ||
title="Oops, sorry! Our pricing service is temporarily down" | ||
onClose={() => toast.dismiss(t.id)} | ||
/> | ||
)) | ||
} | ||
|
||
return () => { | ||
if (hasRenderedAlert) { | ||
clearTimeout(timeout) | ||
timeout = setTimeout(renderAlert, 60 * 1000) | ||
return | ||
} | ||
|
||
hasRenderedAlert = true | ||
renderAlert() | ||
} | ||
} |
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,62 @@ | ||
type ExternalLinkPopupArgs = { | ||
url: string | ||
title: string | ||
width: number | ||
height: number | ||
} | ||
|
||
export function externalLinkPopup({ | ||
url, | ||
title, | ||
width: w, | ||
height: h, | ||
}: ExternalLinkPopupArgs) { | ||
const dualScreenLeft = | ||
window.screenLeft !== undefined ? window.screenLeft : window.screenX | ||
const dualScreenTop = | ||
window.screenTop !== undefined ? window.screenTop : window.screenY | ||
|
||
const width = window.innerWidth | ||
? window.innerWidth | ||
: document.documentElement.clientWidth | ||
? document.documentElement.clientWidth | ||
: screen.width | ||
const height = window.innerHeight | ||
? window.innerHeight | ||
: document.documentElement.clientHeight | ||
? document.documentElement.clientHeight | ||
: screen.height | ||
|
||
const systemZoom = width / window.screen.availWidth | ||
const left = (width - w) / 2 / systemZoom + dualScreenLeft | ||
const top = (height - h) / 2 / systemZoom + dualScreenTop | ||
const newWindow = window.open( | ||
url, | ||
title, | ||
` | ||
scrollbars=yes, | ||
width=${w / systemZoom}, | ||
height=${h / systemZoom}, | ||
top=${top}, | ||
left=${left}, | ||
location=yes, | ||
status=yes | ||
` | ||
) | ||
|
||
if (window.focus) newWindow.focus() | ||
|
||
return newWindow | ||
} | ||
|
||
export function externalLinkPopupAutoWidth( | ||
args: Omit<ExternalLinkPopupArgs, 'width' | 'height'> | ||
) { | ||
const width = Math.max(450, Math.round(window.innerWidth * 0.35)) | ||
const height = Math.max(300, Math.round(window.innerHeight * 0.8)) | ||
return externalLinkPopup({ | ||
...args, | ||
width, | ||
height, | ||
}) | ||
} |