From 7954e5193db0e102c9f396ed641c82dd60399c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 12 Jun 2024 13:56:17 +0200 Subject: [PATCH 1/3] Set era to 900 blocks --- src/api/era.tsx | 41 +++++++++++++------ src/api/timestamp.ts | 9 ++-- src/i18n/locales/en/translations.json | 4 +- .../transaction/ReviewTransactionForm.tsx | 2 + .../ReviewTransactionForm.utils.tsx | 1 - .../transaction/ReviewTransactionSummary.tsx | 19 ++++++--- 6 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/api/era.tsx b/src/api/era.tsx index 55560924e..ca9a75813 100644 --- a/src/api/era.tsx +++ b/src/api/era.tsx @@ -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, @@ -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) @@ -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]) } diff --git a/src/api/timestamp.ts b/src/api/timestamp.ts index 1d4b40ede..17becdc50 100644 --- a/src/api/timestamp.ts +++ b/src/api/timestamp.ts @@ -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, }, ) } @@ -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() diff --git a/src/i18n/locales/en/translations.json b/src/i18n/locales/en/translations.json index 14a8eab8a..f056242b0 100644 --- a/src/i18n/locales/en/translations.json +++ b/src/i18n/locales/en/translations.json @@ -377,7 +377,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.", @@ -909,7 +909,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?", diff --git a/src/sections/transaction/ReviewTransactionForm.tsx b/src/sections/transaction/ReviewTransactionForm.tsx index f63eabb02..6a7e2253c 100644 --- a/src/sections/transaction/ReviewTransactionForm.tsx +++ b/src/sections/transaction/ReviewTransactionForm.tsx @@ -83,6 +83,7 @@ export const ReviewTransactionForm: FC = (props) => { isLinkedAccount, storedReferralCode, tx, + era, } = transactionValues.data const isLinking = !isLinkedAccount && storedReferralCode @@ -121,6 +122,7 @@ export const ReviewTransactionForm: FC = (props) => { } const signature = await tx.signAsync(address, { + era: era?.period?.toNumber(), tip: tipAmount?.gte(0) ? tipAmount.toString() : undefined, signer: wallet.signer, // defer to polkadot/api to handle nonce w/ regard to mempool diff --git a/src/sections/transaction/ReviewTransactionForm.utils.tsx b/src/sections/transaction/ReviewTransactionForm.utils.tsx index 374ff55bc..f1f151355 100644 --- a/src/sections/transaction/ReviewTransactionForm.utils.tsx +++ b/src/sections/transaction/ReviewTransactionForm.utils.tsx @@ -105,7 +105,6 @@ export const useTransactionValues = ({ const era = useEra( boundedTx.era, bestNumber.data?.parachainBlockNumber.toString(), - boundedTx.era.isMortalEra, ) const feePaymentValue = paymentInfo?.partialFee.toBigNumber() ?? BN_NAN diff --git a/src/sections/transaction/ReviewTransactionSummary.tsx b/src/sections/transaction/ReviewTransactionSummary.tsx index 812593d3c..8cacb5890 100644 --- a/src/sections/transaction/ReviewTransactionSummary.tsx +++ b/src/sections/transaction/ReviewTransactionSummary.tsx @@ -24,7 +24,6 @@ type ReviewTransactionSummaryProps = { } export const ReviewTransactionSummary: FC = ({ - tx, transactionValues, xcallMeta, editFeePaymentAssetEnabled, @@ -116,11 +115,19 @@ export const ReviewTransactionSummary: FC = ({ rows={[ { label: t("liquidity.reviewTransaction.modal.detail.lifetime"), - content: tx.era.isMortalEra - ? t("transaction.mortal.expire", { - date: era?.deathDate, - }) - : t("transaction.immortal.expire"), + content: ( + + {era?.isLoading ? ( + + ) : era?.deathDate ? ( + t("transaction.mortal.expire", { + date: era.deathDate, + }) + ) : ( + t("transaction.immortal.expire") + )} + + ), }, { label: t("liquidity.reviewTransaction.modal.detail.nonce"), From ec34164ca123d24842e62fcfc0d8092deb867b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 12 Jun 2024 14:17:38 +0200 Subject: [PATCH 2/3] added lifetime tooltip --- src/i18n/locales/en/translations.json | 1 + .../transaction/ReviewTransactionSummary.tsx | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/i18n/locales/en/translations.json b/src/i18n/locales/en/translations.json index f056242b0..fd8500e68 100644 --- a/src/i18n/locales/en/translations.json +++ b/src/i18n/locales/en/translations.json @@ -286,6 +286,7 @@ "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.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", diff --git a/src/sections/transaction/ReviewTransactionSummary.tsx b/src/sections/transaction/ReviewTransactionSummary.tsx index 8cacb5890..818d29ac3 100644 --- a/src/sections/transaction/ReviewTransactionSummary.tsx +++ b/src/sections/transaction/ReviewTransactionSummary.tsx @@ -12,6 +12,8 @@ import { useRpcProvider } from "providers/rpcProvider" import { ReviewTransactionAuthorTip } from "sections/transaction/ReviewTransactionAuthorTip" import { NATIVE_EVM_ASSET_SYMBOL } from "utils/evm" import { Transaction } from "state/store" +import { InfoTooltip } from "components/InfoTooltip/InfoTooltip" +import { SInfoIcon } from "components/InfoTooltip/InfoTooltip.styled" type ReviewTransactionSummaryProps = { tx: SubmittableExtrinsic<"promise"> @@ -116,13 +118,22 @@ export const ReviewTransactionSummary: FC = ({ { label: t("liquidity.reviewTransaction.modal.detail.lifetime"), content: ( - + {era?.isLoading ? ( ) : era?.deathDate ? ( - t("transaction.mortal.expire", { - date: era.deathDate, - }) + <> + {t("transaction.mortal.expire", { + date: era.deathDate, + })} + + + + ) : ( t("transaction.immortal.expire") )} From 9b4b4d478b632a10edca3e72404109b51795aef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 12 Jun 2024 14:59:36 +0200 Subject: [PATCH 3/3] update tx lifetime summary label --- src/i18n/locales/en/translations.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/locales/en/translations.json b/src/i18n/locales/en/translations.json index fd8500e68..702d5ae62 100644 --- a/src/i18n/locales/en/translations.json +++ b/src/i18n/locales/en/translations.json @@ -285,7 +285,7 @@ "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:",