Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into aave
Browse files Browse the repository at this point in the history
  • Loading branch information
jvonasek committed Oct 4, 2024
2 parents db24cb4 + 9d5b2e1 commit 7d42091
Show file tree
Hide file tree
Showing 26 changed files with 432 additions and 279 deletions.
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<html lang="en">
<head>
<title>Hydration - An Ocean of Liquidity</title>
<link rel="icon" href="/favicon.ico" />
<link rel="icon" href="/favicon/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png" />
<link rel="manifest" href="/favicon/manifest.json" />
<link rel="canonical" href="https://app.hydration.net" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
6 changes: 5 additions & 1 deletion index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<html lang="en">
<head>
<title><%= title %></title>
<link rel="icon" href="/favicon.ico" />
<link rel="icon" href="/favicon/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png" />
<link rel="manifest" href="/favicon/manifest.json" />
<link rel="canonical" href="https://app.hydration.net" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
Binary file removed public/favicon.ico
Binary file not shown.
Binary file added public/favicon/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon/favicon.ico
Binary file not shown.
21 changes: 21 additions & 0 deletions public/favicon/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Hydration",
"short_name": "Hydration",
"icons": [
{
"src": "/favicon/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/favicon/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#060917",
"background_color": "#060917",
"scope": "/",
"display": "standalone",
"start_url": "/?utm_source=androidappinstallbanner"
}
87 changes: 1 addition & 86 deletions src/api/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { SubmittableExtrinsic } from "@polkadot/api/promise/types"
import {
useAccount,
useEvmAccount,
useWallet,
} from "sections/web3-connect/Web3Connect.utils"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { AccountId32 } from "@polkadot/types/interfaces"
import { useMutation, useQueries, useQuery } from "@tanstack/react-query"
import { QUERY_KEYS } from "utils/queryKeys"
import { Maybe, undefinedNoop } from "utils/helpers"
import { ApiPromise } from "@polkadot/api"
import { useRpcProvider } from "providers/rpcProvider"
import { BN_0, BN_1 } from "utils/constants"
import {
EthereumSigner,
PermitResult,
} from "sections/web3-connect/signer/EthereumSigner"
import { create } from "zustand"
import BigNumber from "bignumber.js"
import { useSpotPrice } from "api/spotPrice"
import { useAccountCurrency } from "api/payments"
Expand Down Expand Up @@ -57,51 +48,6 @@ export function useMultiplePaymentInfo(
return useQueries({ queries })
}

export function useNextEvmPermitNonce() {
const { account } = useEvmAccount()
const address = account?.address ?? ""
const { wallet } = useWallet()
const {
permitNonce,
pendingPermit,
setPermitNonce,
incrementPermitNonce,
revertPermitNonce,
setPendingPermit,
} = useEvmPermitStore()

const isEvmSigner = wallet?.signer instanceof EthereumSigner
const currentPermitNonce = permitNonce[address]

useQuery(
QUERY_KEYS.nextEvmPermitNonce(address),
async () => {
if (!address) throw new Error("Missing address")
if (!wallet?.signer) throw new Error("Missing wallet signer")
if (!isEvmSigner) throw new Error("Invalid signer")
return await wallet.signer.getPermitNonce()
},
{
enabled: !!address && isEvmSigner && !currentPermitNonce,
cacheTime: 1000 * 60 * 60 * 24,
keepPreviousData: true,
onSuccess: (nonce) => {
if (address && nonce) {
setPermitNonce(address, nonce)
}
},
},
)

return {
permitNonce: currentPermitNonce ?? BN_0,
pendingPermit,
incrementPermitNonce,
revertPermitNonce,
setPendingPermit,
}
}

export function useNextNonce(account: Maybe<AccountId32 | string>) {
const { api } = useRpcProvider()

Expand Down Expand Up @@ -154,37 +100,6 @@ export async function getTransactionLinkFromHash(
}
}

export const useEvmPermitStore = create<{
pendingPermit: PermitResult | null
permitNonce: { [address: string]: BigNumber }
setPermitNonce: (address: string, nonce: BigNumber) => void
setPendingPermit: (permit: PermitResult | null) => void
revertPermitNonce: (address: string) => void
incrementPermitNonce: (address: string) => void
}>((set) => ({
pendingPermit: null,
permitNonce: {},
setPermitNonce: (address, nonce) =>
set(({ permitNonce }) => ({
permitNonce: { ...permitNonce, [address]: nonce },
})),
setPendingPermit: (permit) => set({ pendingPermit: permit }),
revertPermitNonce: (address) =>
set(({ permitNonce }) => ({
permitNonce: {
...permitNonce,
[address]: (permitNonce[address] ?? BN_0).minus(1),
},
})),
incrementPermitNonce: (address) =>
set(({ permitNonce }) => ({
permitNonce: {
...permitNonce,
[address]: (permitNonce[address] ?? BN_0).plus(1),
},
})),
}))

export const useEstimatedFees = (txs: SubmittableExtrinsic[]) => {
const { getAsset, native } = useAssets()
const { account } = useAccount()
Expand Down
95 changes: 94 additions & 1 deletion src/components/Toast/Toast.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import { QUERY_KEYS } from "utils/queryKeys"
import { Buffer } from "buffer"
import { keccak256 } from "ethers/lib/utils"
import { omit } from "utils/rx"
import { differenceInMinutes } from "date-fns"
import {
differenceInHours,
differenceInMinutes,
differenceInSeconds,
} from "date-fns"
import { useRpcProvider } from "providers/rpcProvider"
import request, { gql } from "graphql-request"
import { useIndexerUrl } from "api/provider"
import { Parachain, SubstrateApis } from "@galacticcouncil/xcm-core"
import { chainsMap } from "@galacticcouncil/xcm-cfg"

const moonbeamRpc = (chainsMap.get("moonbeam") as Parachain).ws
//const txInfoSubscan = "https://hydration.api.subscan.io/api/scan/extrinsic"

type TExtrinsic = {
hash: string
Expand All @@ -21,6 +26,10 @@ type TExtrinsic = {
indexInBlock: string
}

type TSuccessExtrinsic = TExtrinsic & {
success: boolean
}

const getExtrinsicByHash = async (indexerUrl: string, hash: string) => {
return {
...(await request<{
Expand Down Expand Up @@ -73,6 +82,29 @@ const getExtrinsicByBlockNumber = async (
}
}

const getExtrinsic = async (indexerUrl: string, hash: string) => {
return {
...(await request<{
extrinsics: TSuccessExtrinsic[]
}>(
indexerUrl,
gql`
query GetExtrinsic($hash: String) {
extrinsics(where: { hash_eq: $hash }) {
hash
block {
height
}
indexInBlock
success
}
}
`,
{ hash },
)),
}
}

const getExtrinsicIndex = (
{ extrinsics }: { extrinsics: TExtrinsic[] },
i?: number,
Expand Down Expand Up @@ -137,6 +169,67 @@ const getWormholeTx = async (extrinsicIndex: string) => {
}
}

export const useProcessToasts = (toasts: ToastData[]) => {
const indexerUrl = useIndexerUrl()
const toast = useToast()

useQueries({
queries: toasts.map((toastData) => ({
queryKey: QUERY_KEYS.progressToast(toastData.id),
queryFn: async () => {
const secondsDiff = differenceInSeconds(
new Date(),
new Date(toastData.dateCreated),
)

// skip processing
if (secondsDiff < 60) return false

const hoursDiff = differenceInHours(
new Date(),
new Date(toastData.dateCreated),
)

// move to unknown state
if (hoursDiff >= 1) {
toast.remove(toastData.id)
toast.add("unknown", toastData)

return false
}

const res = await getExtrinsic(indexerUrl, toastData.txHash as string)
const isExtrinsic = !!res.extrinsics.length

if (isExtrinsic) {
const isSuccess = res.extrinsics[0].success

// use subscan to get extrinsic info
// const txInfoRes = await fetch(txInfoSubscan, {
// method: "POST",
// body: JSON.stringify({ hash: toastData.txHash }),
// })

// const data: { data: { success: boolean } } = await txInfoRes.json()

toast.remove(toastData.id)

if (isSuccess) {
toast.add("success", toastData)
} else {
toast.add("error", toastData)
}

return true
}

return false
},
refetchInterval: 10000,
})),
})
}

export const useBridgeToast = (toasts: ToastData[]) => {
const { api, isLoaded } = useRpcProvider()
const indexerUrl = useIndexerUrl()
Expand Down
7 changes: 6 additions & 1 deletion src/components/Toast/ToastProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Toast } from "components/Toast/Toast"
import { AnimatePresence, domAnimation, LazyMotion } from "framer-motion"

import { ToastSidebar } from "./sidebar/ToastSidebar"
import { useBridgeToast } from "./Toast.utils"
import { useBridgeToast, useProcessToasts } from "./Toast.utils"

export const ToastProvider: FC<PropsWithChildren> = ({ children }) => {
const { toasts, toastsTemp, hide, sidebar, setSidebar } = useToast()
Expand All @@ -15,7 +15,12 @@ export const ToastProvider: FC<PropsWithChildren> = ({ children }) => {
(toast) => toast.bridge && toast.variant === "progress",
)

const progressToasts = toasts.filter((toast) => {
return !toast.bridge && toast.variant === "progress" && toast.txHash
})

useBridgeToast(bridgeToasts)
useProcessToasts(progressToasts)

const activeToasts = [...toastsTemp, ...toasts.filter((i) => !i.hidden)]
const toast = activeToasts[0]
Expand Down
2 changes: 2 additions & 0 deletions src/sections/transaction/ReviewTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const ReviewTransaction = (props: Transaction) => {
txState,
reset,
txLink,
txHash,
bridge,
} = useSendTx()

Expand Down Expand Up @@ -99,6 +100,7 @@ export const ReviewTransaction = (props: Transaction) => {
isError={isError}
error={error}
link={txLink}
txHash={txHash}
onReview={onReview}
onClose={onMinimizeModal}
toastMessage={props.toastMessage}
Expand Down
Loading

0 comments on commit 7d42091

Please sign in to comment.