Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jvonasek committed Jun 12, 2024
2 parents 4c9dd95 + b18c168 commit 37a9121
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 167 deletions.
4 changes: 2 additions & 2 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.1",
"@galacticcouncil/apps": "^4.1.0",
"@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.1",
"@galacticcouncil/ui": "^3.2.3",
"@galacticcouncil/ui": "^4.1.0",
"@galacticcouncil/xcm-cfg": "^2.5.0",
"@galacticcouncil/xcm-core": "^1.4.0",
"@galacticcouncil/xcm-sdk": "^3.3.0",
Expand Down
41 changes: 28 additions & 13 deletions src/api/era.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { ExtrinsicEra } from "@polkadot/types/interfaces/extrinsics"
import { bnToBn } from "@polkadot/util"
import { useTimestamp } from "./timestamp"
import { useMemo } from "react"
import { BLOCK_TIME } from "utils/constants"
import { PARACHAIN_BLOCK_TIME } from "utils/constants"

const DEFAULT_PERIOD = 900

export const useEra = (
era: ExtrinsicEra,
Expand All @@ -14,21 +16,27 @@ export const useEra = (
const blockNumber = bnToBn(hexBlockNumber)

const mortal = useMemo(() => {
if (blockNumber.isZero()) return null
if (era.isMortalEra) {
const mortal = era.asMortalEra
const period = new BN(mortal.period.toHex()) // Blocks validity

if (!blockNumber.isZero()) {
const birth = new BN(mortal.birth(blockNumber))
const death = new BN(mortal.death(blockNumber))
return {
birth,
death,
period,
}
const birth = new BN(mortal.birth(blockNumber))
const death = new BN(mortal.death(blockNumber))
return {
birth,
death,
period,
}
}
return null

const birth = new BN(blockNumber.toString())
const period = new BN(DEFAULT_PERIOD)
return {
birth,
death: birth.plus(period),
period,
}
}, [era, blockNumber])

const timestamp = useTimestamp(mortal?.birth, enabled)
Expand All @@ -38,14 +46,21 @@ export const useEra = (
const birthDate = new Date(timestamp.data)
const deathDate = addSeconds(
birthDate,
mortal.period.times(BLOCK_TIME).toNumber(),
mortal.period.times(PARACHAIN_BLOCK_TIME).toNumber(),
)
return {
birthDate,
deathDate,
period: mortal.period,
isLoading: false,
}
}

return null
}, [timestamp.data, mortal?.period])
return {
birthDate: null,
deathDate: null,
period: null,
isLoading: timestamp.isLoading,
}
}, [timestamp.data, timestamp.isLoading, mortal?.period])
}
66 changes: 48 additions & 18 deletions src/api/staking.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//@ts-nocheck
import { ApiPromise } from "@polkadot/api"
import { useQuery } from "@tanstack/react-query"
import { useMutation, useQuery } from "@tanstack/react-query"
import { QUERY_KEYS } from "utils/queryKeys"
import BN from "bignumber.js"
import { getUniques } from "./uniques"
import { getReferendumInfoOf } from "./democracy"
import request, { gql } from "graphql-request"
import { PROVIDERS } from "./provider"
import { useActiveProvider } from "./provider"
import { useRpcProvider } from "providers/rpcProvider"
import { useActiveProvider } from "api/provider"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { undefinedNoop } from "utils/helpers"

interface ISubscanData {
code: number
Expand Down Expand Up @@ -116,7 +116,7 @@ const getStakingPosition = (api: ApiPromise, id: number) => async () => {
const conviction = data.conviction.toString()

const referendaInfo = await getReferendumInfoOf(api, id.toString())
const isFinished = referendaInfo.unwrapOr(null).isFinished
const isFinished = referendaInfo.unwrapOr(null)?.isFinished

if (isFinished) {
prevAcc.push({
Expand All @@ -127,7 +127,7 @@ const getStakingPosition = (api: ApiPromise, id: number) => async () => {
}

return prevAcc
}, Promise.resolve([]))
}, Promise.resolve<Array<{ id: BN; amount: BN; conviction: string }>>([]))

return {
stake: positionData.stake.toBigNumber() as BN,
Expand Down Expand Up @@ -219,12 +219,7 @@ export type TAccumulatedRpsUpdated = StakeEventBase & {
}

export const useStakingEvents = () => {
const activeProvider = useActiveProvider()
const rpcUrl = activeProvider?.url
const selectedProvider = PROVIDERS.find((provider) => provider.url === rpcUrl)

const indexerUrl =
selectedProvider?.indexerUrl ?? import.meta.env.VITE_INDEXER_URL
const { indexerUrl } = useActiveProvider()

return useQuery(QUERY_KEYS.stakingEvents, async () => {
const [accumulatedRpsUpdated, stakingInitialized] = await Promise.all([
Expand All @@ -241,15 +236,14 @@ export const useStakingEvents = () => {
})
}

export const useStakingPositionBalances = (positionId: Maybe<string>) => {
const activeProvider = useActiveProvider()

const indexerUrl =
activeProvider?.indexerUrl ?? import.meta.env.VITE_INDEXER_URL
export const useStakingPositionBalances = (positionId?: string) => {
const { indexerUrl } = useActiveProvider()

return useQuery(
QUERY_KEYS.stakingPositionBalances(positionId),
getStakingPositionBalances(indexerUrl, positionId),
positionId
? getStakingPositionBalances(indexerUrl, positionId)
: undefinedNoop,
{ enabled: !!positionId },
)
}
Expand Down Expand Up @@ -326,3 +320,39 @@ const getStakingPositionBalances =
)),
}
}

export const useProcessedVotesIds = () => {
const { account } = useAccount()
const { api } = useRpcProvider()

return useMutation(async () => {
if (!account) {
return []
}

const processedVotesRes = await api.query.staking.processedVotes.entries(
account.address,
)

const ids = processedVotesRes.map(([processedVote]) => {
const [, id] = processedVote.toHuman() as string[]

return id
})

return ids
})
}

export const usePositionVotesIds = () => {
const { api } = useRpcProvider()

return useMutation(async (positionId: number) => {
const positionVotesRes = await api.query.staking.positionVotes(positionId)
const positionVotesIds = positionVotesRes.votes.map(([position]) =>
position.toString(),
)

return positionVotesIds
})
}
9 changes: 5 additions & 4 deletions src/api/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export function useTimestamp(
enabled = true,
) {
const { api } = useRpcProvider()
const queryEnabled = !!blockNumber && enabled

return useQuery(
QUERY_KEYS.timestamp(blockNumber),
() =>
blockNumber !== null ? getTimestamp(api, blockNumber) : undefinedNoop(),
() => (queryEnabled ? getTimestamp(api, blockNumber) : undefinedNoop()),
{
enabled: !!blockNumber && enabled,
enabled: queryEnabled,
},
)
}
Expand All @@ -25,7 +26,7 @@ export async function getTimestamp(
api: ApiPromise,
blockNumber?: u32 | BigNumber,
) {
if (blockNumber != null) {
if (blockNumber) {
const blockHash = await api.rpc.chain.getBlockHash(blockNumber.toString())
const apiAt = await api.at(blockHash)
const now = await apiAt.query.timestamp.now()
Expand Down
4 changes: 2 additions & 2 deletions src/assets/icons/HydraLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/components/AppProviders/AppProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { createComponent } from "@lit-labs/react"
import { ProviderReloader } from "sections/provider/ProviderReloader"
import { MigrationProvider } from "sections/migration/MigrationProvider"

const AppsPersistenceProvider = createComponent({
tagName: "gc-database-provider",
elementClass: Apps.DatabaseProvider,
const AppsContextProvider = createComponent({
tagName: "gc-context-provider",
elementClass: Apps.ContextProvider,
react: React,
})

Expand All @@ -31,7 +31,7 @@ export const AppProviders: FC<PropsWithChildren> = ({ children }) => {
highlightColor={`rgba(${theme.rgbColors.white}, 0.24)`}
borderRadius={4}
>
<AppsPersistenceProvider>{children}</AppsPersistenceProvider>
<AppsContextProvider>{children}</AppsContextProvider>
<Transactions />
</SkeletonTheme>
</ToastProvider>
Expand Down
27 changes: 9 additions & 18 deletions src/components/AssetIcon/AssetIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@ import { useRpcProvider } from "providers/rpcProvider"
import { useTranslation } from "react-i18next"
import { AnyParachain } from "@galacticcouncil/xcm-core"
import { isAnyParachain } from "utils/helpers"

const EXTERNAL_ASSETS_WHITELIST = [
// PINK
{ id: "23", origin: 1000 },
// STINK
{ id: "42069", origin: 1000 },
// WUD
{ id: "31337", origin: 1000 },
// WIFD
{ id: "17", origin: 1000 },
// BNDT
{ id: "8889", origin: 1000 },
]
import { MetadataStore } from "@galacticcouncil/ui"

const chains = Array.from(chainsMap.values())

Expand Down Expand Up @@ -57,6 +45,11 @@ export const AssetLogo = ({ id }: { id?: string }) => {
const { t } = useTranslation()
const { assets } = useRpcProvider()

const externalAssetsWhitelist = useMemo(
() => MetadataStore.getInstance().externalWhitelist(),
[],
)

const asset = useMemo(() => {
const assetDetails = id ? assets.getAsset(id) : undefined

Expand All @@ -66,11 +59,9 @@ export const AssetLogo = ({ id }: { id?: string }) => {
chain.parachainId === Number(assetDetails?.parachainId),
) as AnyParachain

const isWhitelisted = EXTERNAL_ASSETS_WHITELIST.some(
(item) =>
item.id === assetDetails?.externalId &&
item.origin === chain?.parachainId,
)
const isWhitelisted = assetDetails
? externalAssetsWhitelist.includes(assetDetails.id)
: false

const badgeVariant: "warning" | "danger" | "" = assetDetails?.isExternal
? isWhitelisted
Expand Down
8 changes: 7 additions & 1 deletion src/components/Layout/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export const Header = () => {
<Link to={LINKS.swap} search={resetSearchParams(search)}>
<Icon
sx={{ color: "white" }}
icon={!isMediumMedia ? <HydraLogoFull /> : <HydraLogo />}
icon={
!isMediumMedia ? (
<HydraLogoFull />
) : (
<Icon size={24} icon={<HydraLogo />} />
)
}
/>
</Link>
<HeaderMenu ref={observe} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modal/Modal.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const SContainer = styled(Content)`
--modal-header-padding-x: 12px;
--modal-header-btn-size: 34px;
--modal-header-height: calc(
var(--modal-header-btn-size) + var(--modal-header-padding-y) * 2
var(--modal-header-btn-size) + var(--modal-header-padding-y) * 1.5
);
--modal-content-padding: 12px;
Expand Down
7 changes: 4 additions & 3 deletions src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@
"liquidity.reviewTransaction.modal.title": "Review transaction details",
"liquidity.reviewTransaction.modal.desc": "Please review your transaction",
"liquidity.reviewTransaction.modal.detail.cost": "Transaction cost:",
"liquidity.reviewTransaction.modal.detail.lifetime": "Transaction lifetime:",
"liquidity.reviewTransaction.modal.detail.lifetime": "Transaction expiration:",
"liquidity.reviewTransaction.modal.detail.lifetime.tooltip": "If the transaction is not included by this time, it will be cancelled.",
"liquidity.reviewTransaction.modal.detail.nonce": "Nonce:",
"liquidity.reviewTransaction.modal.detail.tip":"Tip the block author:",
"liquidity.reviewTransaction.modal.detail.tip.name":"Display user tip",
Expand Down Expand Up @@ -384,7 +385,7 @@
"otc.offers.table.header.status": "Order status",
"otc.offers.table.actions.fill": "Fill order",
"otc.offers.table.actions.cancel": "Cancel order",
"transaction.mortal.expire": "{{ date, dd/MM/yyyy hh:mm:ss }}",
"transaction.mortal.expire": "{{ date, dd/MM/yyyy HH:mm:ss }}",
"transaction.immortal.expire": "Never",
"walletConnect.provider.title": "Connect wallet",
"walletConnect.provider.description.default": "Select your wallet of choice.",
Expand Down Expand Up @@ -916,7 +917,7 @@
"migration.export.question": "Would you like to migrate all past app settings to the new app?",
"migration.export.button": "Migrate 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.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?",
Expand Down
4 changes: 3 additions & 1 deletion src/sections/pools/components/NewFarmsBanner.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const NewFarmsBannerContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
gap: 14px;
flex-direction: row;
gap: 4px;
padding: 6px 0;
`
Loading

0 comments on commit 37a9121

Please sign in to comment.