Skip to content

Commit

Permalink
Merge branch 'migration-confirmation' into hydration-migration-test
Browse files Browse the repository at this point in the history
  • Loading branch information
jvonasek committed Jun 7, 2024
2 parents bf2aac0 + f0dbdd8 commit f84982d
Show file tree
Hide file tree
Showing 48 changed files with 923 additions and 360 deletions.
3 changes: 1 addition & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ VITE_EVM_PROVIDER_URL=https://rpc.nice.hydration.cloud
VITE_EVM_EXPLORER_URL=https://explorer.nice.hydration.cloud
VITE_EVM_NATIVE_ASSET_ID=20
VITE_MIGRATION_TRIGGER_DOMAIN="deploy-preview-1334--testnet-hydra-app.netlify.app"
VITE_MIGRATION_TARGET_DOMAIN="testnet-app.hydradx.io"

VITE_MIGRATION_TARGET_DOMAIN="deploy-preview-1374--testnet-hydra-app.netlify.app"
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<meta property="og:title" content="Hydration - An Ocean of Liquidity" />
<meta property="og:description" content="Hydration is a next-gen DeFi protocol which is designed to bring an ocean of liquidity to Polkadot. Our tool for the job the Hydration - an innovative Automated Market Maker (AMM) which unlocks unparalleled efficiencies by combining all assets in a single trading pool." />
<meta property="og:image" content="https://app.hydration.net/images/meta-image.jpg" />
<meta property="og:image" content="https://hydration.net/opengraph-image.png" />
<meta property="og:url" content="https://app.hydration.net" />
<meta property="og:type" content="website" />

Expand Down
6 changes: 3 additions & 3 deletions index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title><%= title %></title>
<link rel="icon" href="/favicon.ico" />
<link rel="canonical" href="https://app.hydradx.io" />
<link rel="canonical" href="https://app.hydration.net" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
Expand All @@ -14,11 +14,11 @@
<meta property="og:title" content="<%= title %>" />
<meta property="og:description" content="<%= description %>" />
<meta property="og:image" content="<%= image %>" />
<meta property="og:url" content="https://app.hydradx.io" />
<meta property="og:url" content="https://app.hydration.net" />
<meta property="og:type" content="website" />

<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content="https://app.hydradx.io" />
<meta property="twitter:url" content="https://app.hydration.net" />
<meta property="twitter:title" content="<%= title %>" />
<meta property="twitter:description" content="<%= description %>" />
<meta property="twitter:image" content="<%= image %>" />
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
"@emotion/styled": "^11.10.4",
"@ethersproject/address": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@galacticcouncil/apps": "^3.9.0",
"@galacticcouncil/apps": "^3.9.1",
"@galacticcouncil/math-lbp": "^1.0.0",
"@galacticcouncil/math-liquidity-mining": "^1.0.0",
"@galacticcouncil/math-omnipool": "^1.0.0",
"@galacticcouncil/math-stableswap": "^1.0.0",
"@galacticcouncil/math-staking": "^1.0.0",
"@galacticcouncil/math-xyk": "^1.0.0",
"@galacticcouncil/sdk": "^3.0.0",
"@galacticcouncil/ui": "^3.2.2",
"@galacticcouncil/sdk": "^3.0.1",
"@galacticcouncil/ui": "^3.2.3",
"@galacticcouncil/xcm-cfg": "^2.5.0",
"@galacticcouncil/xcm-core": "^1.4.0",
"@galacticcouncil/xcm-sdk": "^3.3.0",
Expand Down
Binary file modified public/favicon.ico
Binary file not shown.
Binary file removed public/images/meta-image.jpg
Binary file not shown.
9 changes: 7 additions & 2 deletions src/api/accountBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import BN from "bn.js"
import { useRpcProvider } from "providers/rpcProvider"
import { calculateFreeBalance } from "./balances"

export const useAccountBalances = (id: Maybe<AccountId32 | string>) => {
export const useAccountBalances = (
id: Maybe<AccountId32 | string>,
noRefresh?: boolean,
) => {
const { api } = useRpcProvider()
return useQuery(
QUERY_KEYS.accountBalances(id),
noRefresh
? QUERY_KEYS.accountBalances(id)
: QUERY_KEYS.accountBalancesLive(id),
!!id ? getAccountBalances(api, id) : undefinedNoop,
{ enabled: id != null },
)
Expand Down
1 change: 0 additions & 1 deletion src/api/assetDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ export const getAssets = async (api: ApiPromise) => {
if (id === NATIVE_ASSET_ID) {
const asset: TToken = {
...assetCommon,
name: "HydraDX",
symbol: system.tokenSymbol.unwrap()[0].toString(),
decimals: system.tokenDecimals.unwrap()[0].toNumber(),
isNative: true,
Expand Down
109 changes: 108 additions & 1 deletion src/api/democracy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ import { useQuery } from "@tanstack/react-query"
import { QUERY_KEYS } from "utils/queryKeys"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { useRpcProvider } from "providers/rpcProvider"
import { undefinedNoop } from "utils/helpers"
import BN from "bignumber.js"
import { BN_0 } from "utils/constants"

const REFERENDUM_DATA_URL = import.meta.env.VITE_REFERENDUM_DATA_URL as string

const CONVICTIONS_BLOCKS: { [key: string]: number } = {
none: 0,
locked1x: 50400,
locked2x: 100800,
locked3x: 201600,
locked4x: 403200,
locked5x: 806400,
locked6x: 1612800,
}

export const useReferendums = (type?: "ongoing" | "finished") => {
const { api, isLoaded } = useRpcProvider()
const { account } = useAccount()

return useQuery(
QUERY_KEYS.referendums(account?.address),
QUERY_KEYS.referendums(account?.address, type),
getReferendums(api, account?.address),
{
enabled: isLoaded,
Expand Down Expand Up @@ -94,3 +107,97 @@ export type Referendum = {

export const getReferendumInfoOf = async (api: ApiPromise, id: string) =>
await api.query.democracy.referendumInfoOf(id)

export const useAccountVotes = () => {
const { api, isLoaded } = useRpcProvider()
const { account } = useAccount()

return useQuery(
QUERY_KEYS.referendumVotes(account?.address),
account ? getAccountUnlockedVotes(api, account.address) : undefinedNoop,
{
enabled: isLoaded && !!account,
},
)
}

export const getAccountUnlockedVotes =
(api: ApiPromise, accountId: string) => async () => {
const [votesRaw, currentBlock] = await Promise.all([
api.query.democracy.votingOf(accountId),
api.derive.chain.bestNumber(),
])

if (!votesRaw || votesRaw.isDelegating) return undefined

const votes = votesRaw.asDirect.votes.map(([id, dataRaw]) => {
const test = dataRaw.asStandard

return {
id: id.toString(),
balance: test.balance.toBigNumber(),
conviction: test.vote.conviction.toString(),
}
})

const votedAmounts = await Promise.all(
votes.map(async (vote) => {
const voteId = vote.id
const referendumRaw = await api.query.democracy.referendumInfoOf(voteId)
const referendum = referendumRaw.unwrap()
const isFinished = referendum.isFinished

const endBlock = isFinished
? referendum.asFinished.end.toBigNumber()
: referendum.asOngoing.end.toBigNumber()
const convictionBlock =
CONVICTIONS_BLOCKS[vote.conviction.toLocaleLowerCase()]
const unlockBlockNumber = endBlock.plus(convictionBlock)
const isUnlocked = isFinished
? unlockBlockNumber.lte(currentBlock.toNumber())
: false

return {
isUnlocked,
amount: vote.balance,
id: voteId,
endDiff: unlockBlockNumber.minus(currentBlock.toNumber()),
}
}),
)

const unlockedVotes = votedAmounts.reduce<{
maxUnlockedValue: BN
maxLockedValue: BN
maxLockedBlock: BN
ids: string[]
}>(
(acc, votedAmount) => {
if (votedAmount.isUnlocked)
return {
maxUnlockedValue: BN.maximum(
acc.maxUnlockedValue,
votedAmount.amount,
),
maxLockedValue: acc.maxLockedValue,
maxLockedBlock: BN.maximum(votedAmount.endDiff, acc.maxLockedBlock),
ids: [...acc.ids, votedAmount.id],
}

return {
maxLockedValue: BN.maximum(acc.maxLockedValue, votedAmount.amount),
maxUnlockedValue: acc.maxUnlockedValue,
maxLockedBlock: BN.maximum(votedAmount.endDiff, acc.maxLockedBlock),
ids: acc.ids,
}
},
{
maxUnlockedValue: BN_0,
maxLockedValue: BN_0,
ids: [],
maxLockedBlock: BN_0,
},
)

return unlockedVotes
}
13 changes: 8 additions & 5 deletions src/api/externalAssetRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ export const getPedulumAssets = async () => {
const data = dataRaw.unwrap()
const location = data.location.unwrap()

if (location.isV2 && location.asV2.interior.toString() !== "Here") {
if (location) {
const type = location.type.toString()
const interior = location[`as${type}`].interior.toString()

const id = getPendulumAssetId(idRaw)
if (id)
if (interior !== "Here" && id)
acc.push({
id,
// @ts-ignore
Expand All @@ -95,7 +98,7 @@ export const getPedulumAssets = async () => {
symbol: data.symbol.toHuman() as string,
// @ts-ignore
name: data.name.toHuman() as string,
location: location.asV2 as HydradxRuntimeXcmAssetLocation,
location: location[`as${type}`] as HydradxRuntimeXcmAssetLocation,
origin: PENDULUM_ID,
})
}
Expand All @@ -111,11 +114,11 @@ export const getPedulumAssets = async () => {
*/
export const useExternalAssetRegistry = () => {
const assetHub = useAssetHubAssetRegistry()
//const pendulum = usePendulumAssetRegistry()
const pendulum = usePendulumAssetRegistry()

return {
[ASSET_HUB_ID as number]: assetHub,
// [PENDULUM_ID as number]: pendulum,
[PENDULUM_ID as number]: pendulum,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const useCirculatingSupply = () => {
}

const getCirculatingSupply = () => async () => {
const res = await fetch("https://hydradx.api.subscan.io/api/scan/token")
const res = await fetch("https://hydration.api.subscan.io/api/scan/token")

const data: Promise<ISubscanData> = res.json()

Expand Down
2 changes: 1 addition & 1 deletion src/api/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function useNextNonce(account: Maybe<AccountId32 | string>) {
}

export function getSubscanLink(blockNumber: string, txIndex: string) {
return `https://hydradx.subscan.io/extrinsic/${[blockNumber, txIndex].join(
return `https://hydration.subscan.io/extrinsic/${[blockNumber, txIndex].join(
"-",
)}`
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Charts/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Label = ({ value }: { value: number }) => {
zIndex: 1,
}}
>
<Text fs={24} font="GeistMono">
<Text fs={24}>
<DisplayValue value={value} isUSD />
</Text>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Layout/Header/MobileNavBar/MoreButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SQuestionmark } from "components/Layout/Header/Header.styled"
import { Separator } from "components/Separator/Separator"
import { Text } from "components/Typography/Text/Text"
import { theme } from "theme"
import { DOC_LINK } from "utils/constants"

const settingsEanbled = import.meta.env.VITE_FF_SETTINGS_ENABLED === "true"

Expand Down Expand Up @@ -43,7 +44,7 @@ export const MoreButton = ({ tabs }: MoreButtonProps) => {
</>
)}
<a
href="https://docs.hydradx.io/"
href={DOC_LINK}
target="blank"
rel="noreferrer"
sx={{ flex: "row", align: "center", gap: 10, py: 10 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
SToolbarIcon,
} from "components/Layout/Header/toolbar/HeaderToolbar.styled"
import { useTranslation } from "react-i18next"
import { DOC_LINK } from "utils/constants"

export type DocumentationProps = {}

export const Documentation: React.FC<DocumentationProps> = () => {
const { t } = useTranslation()
return (
<InfoTooltip text={t("header.documentation.tooltip")} type="black" asChild>
<a href="https://docs.hydradx.io/" target="blank" rel="noreferrer">
<a href={DOC_LINK} target="blank" rel="noreferrer">
<SToolbarButton as="span">
<SToolbarIcon
as={QuestionmarkIcon}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Separator/Separator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "react"
import { FC, ReactNode } from "react"
import { SSeparator } from "./Separator.styled"
import { theme } from "theme"

Expand All @@ -7,6 +7,7 @@ export type SeparatorProps = {
color?: keyof typeof theme.colors
opacity?: number
size?: number
children?: ReactNode
}

export const Separator: FC<SeparatorProps> = ({
Expand Down
8 changes: 4 additions & 4 deletions src/components/Table/Table.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,17 @@ export const TableHeader = styled.th<{ canSort?: boolean }>`
export const TableData = styled.td<{
isExpanded?: boolean
isSkeleton?: boolean
sub?: boolean
}>`
height: 56px;
${({ isExpanded }) => (isExpanded ? `padding: 16px` : "padding: 0 16px")};
padding: 0 16px;
${({ isSkeleton }) => !isSkeleton && "padding-right: 0px;"}
text-align: start;
${({ isExpanded }) =>
isExpanded && `background: rgba(${theme.rgbColors.white}, 0.06);`}
isExpanded && `background: rgba(${theme.rgbColors.white}, 0.03);`}
&:last-of-type {
width: 1px;
Expand All @@ -198,8 +199,7 @@ export const TableData = styled.td<{
@media ${theme.viewport.gte.sm} {
height: 82px;
${({ isExpanded }) =>
isExpanded ? `padding: 24px 32px` : "padding: 0 32px"};
${({ sub }) => (sub ? `padding: 24px 32px` : "padding: 0 32px")};
&:last-of-type {
padding-right: 10px;
Expand Down
16 changes: 13 additions & 3 deletions src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,15 @@
"wallet.assets.table.details.locked": "Locked",
"wallet.assets.table.details.lockedVesting": "Locked in Vesting",
"wallet.assets.table.details.lockedDemocracy": "Locked in Democracy",
"wallet.assets.table.details.unlockable": "Unlockable",
"wallet.assets.table.details.btn": "Unlock Assets",
"wallet.assets.table.details.lockedStaking": "Total Locked in Staking",
"wallet.assets.table.details.noprice.tooltip": "Spot price currently not available",
"wallet.assets.table.details.expired_one": "{{count}} Expired lock",
"wallet.assets.table.details.expired_other": "{{count}} Expired locks",
"wallet.assets.table.details.expiring": "100% Expires in {{duration}}",
"wallet.assets.table.details.unlock.onLoading": "Unlocking {{value, bignumber(type: token)}} HDX",
"wallet.assets.table.details.unlock.onSuccess": "Uncloked {{value, bignumber(type: token)}} HDX",
"wallet.assets.table.empty.desc": "Looks like you don’t have any assets on Hydration yet. Click below to add them through cross-chain transfers.",
"wallet.assets.table.empty.btn": "Transfer to Hydration",
"wallet.assets.hydraPositions.empty.desc": "You still don't have any liquidity positions. Add liquidity to the Omnipool and begin your hydrated journey.",
Expand Down Expand Up @@ -901,8 +908,11 @@
"migration.export.description": "As part of the rebranding, this app has moved to app.hydration.net.",
"migration.export.question": "Would you like to migrate all past app settings to the new app?",
"migration.export.button": "Migrate Settings",
"migration.import.title": "Do you wish to overwrite your settings?",
"migration.import.description": "You already transferred your settings on {{ date, dd/MM/yyyy hh:mm:ss }}. Do you wish to overwrite your current settings?",
"migration.import.button": "Overwrite Settings",
"migration.import.overwrite.title": "Do you wish to overwrite your settings?",
"migration.import.overwrite.description": "You already transferred your settings on {{ date, dd/MM/yyyy hh:mm:ss }}. Do you wish to overwrite your current settings?",
"migration.import.overwrite.button": "Overwrite Settings",
"migration.import.confirm.title": "You have opened a migration link",
"migration.import.confirm.description": "Do you want to import new app settings?",
"migration.import.confirm.button": "Yes, import settings",
"migration.warning.text": "You can transfer Your app settings from HydraDX to Hydration"
}
1 change: 0 additions & 1 deletion src/sections/migration/MigrationProvider.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { persist } from "zustand/middleware"
export const MIGRATION_LS_KEYS = [
"external-tokens",
"address-book",
"toasts",
"rpcUrl",
"hydradx-rpc-list",
"referral-codes",
Expand Down
Loading

0 comments on commit f84982d

Please sign in to comment.