diff --git a/src/codec-components/common/scroll.ts b/src/codec-components/common/scroll.ts index 1df2c21..abd6fcf 100644 --- a/src/codec-components/common/scroll.ts +++ b/src/codec-components/common/scroll.ts @@ -2,24 +2,15 @@ export function synchronizeScroll( scrollingElement: HTMLElement, targetElement: HTMLElement, ) { - let heightCache = { - time: 0, - targetHeight: 0, - } const onScroll = async () => { - await Promise.resolve() - const now = Date.now() - heightCache = - heightCache.time > now - 500 - ? heightCache - : { - time: now, - targetHeight: targetElement.getBoundingClientRect().height, - } - + const buffer = targetElement.offsetHeight / 3 const listScrollPos = - scrollingElement.scrollTop / scrollingElement.scrollHeight - targetElement.scrollTop = listScrollPos * heightCache.targetHeight + Math.max(0, scrollingElement.scrollTop - buffer) / + (scrollingElement.scrollHeight - scrollingElement.offsetHeight) + + targetElement.scrollTop = + listScrollPos * + (targetElement.scrollHeight - targetElement.offsetHeight + buffer / 2) } scrollingElement.addEventListener("scroll", onScroll) diff --git a/src/pages/Extrinsics/SubmitTx/AccountProvider.tsx b/src/pages/Extrinsics/SubmitTx/AccountProvider.tsx index 142f47a..549bd99 100644 --- a/src/pages/Extrinsics/SubmitTx/AccountProvider.tsx +++ b/src/pages/Extrinsics/SubmitTx/AccountProvider.tsx @@ -22,7 +22,15 @@ import { state, useStateObservable } from "@react-rxjs/core" import { createSignal } from "@react-rxjs/utils" import { InjectedExtension } from "polkadot-api/pjs-signer" import React from "react" -import { combineLatest, distinctUntilChanged, map, merge, of, tap } from "rxjs" +import { + combineLatest, + defer, + distinctUntilChanged, + map, + merge, + of, + tap, +} from "rxjs" const Accounts: React.FC<{ extension: InjectedExtension }> = ({ extension, @@ -68,7 +76,7 @@ const [valueSelected$, selectValue] = createSignal() const LS_KEY = "selected-signer" const selectedValue$ = state( merge( - of(localStorage.getItem(LS_KEY)), + defer(() => of(localStorage.getItem(LS_KEY))), valueSelected$.pipe(tap((v) => localStorage.setItem(LS_KEY, v))), ), null, diff --git a/src/pages/Extrinsics/SubmitTx/SubmitTxForm.tsx b/src/pages/Extrinsics/SubmitTx/SubmitTxForm.tsx index d280a33..272a980 100644 --- a/src/pages/Extrinsics/SubmitTx/SubmitTxForm.tsx +++ b/src/pages/Extrinsics/SubmitTx/SubmitTxForm.tsx @@ -78,7 +78,6 @@ export default function SubmitTxF(props: {
-
Or
diff --git a/src/pages/Transactions/Transaction.tsx b/src/pages/Transactions/Transaction.tsx index b989963..0fc0fbf 100644 --- a/src/pages/Transactions/Transaction.tsx +++ b/src/pages/Transactions/Transaction.tsx @@ -3,7 +3,8 @@ import { Link } from "@/hashParams" import { shortStr } from "@/utils" import { TxBroadcastEvent } from "polkadot-api" import * as React from "react" -import { onGoingEvents } from "./transactions.state" +import { dismissTransaction, onGoingEvents } from "./transactions.state" +import { Trash2 } from "lucide-react" export const Transaction: React.FC<{ event: @@ -23,7 +24,8 @@ export const Transaction: React.FC<{ case "invalid": return ( - Invalid transaction. {JSON.stringify(event.value, null, 2)} + Invalid transaction.{" "} + {JSON.stringify(event.value, bigintReplacer, 2)} ) case "txBestBlocksState": { @@ -37,7 +39,7 @@ export const Transaction: React.FC<{ > best block - . + {event.ok ? "." : ", but it's failing."} ) : ( Transaction no longer in a best block. @@ -58,7 +60,9 @@ export const Transaction: React.FC<{ {" "} finalized block - . + {event.ok + ? "." + : `, but it failed: ${JSON.stringify(event.dispatchError, bigintReplacer, 2)}.`} ) } @@ -66,14 +70,22 @@ export const Transaction: React.FC<{ const { txHash, type } = event return (
-

- {shortStr(txHash, 14)} -

+
+

+ {shortStr(txHash, 14)} +

+ +

) } + +const bigintReplacer = (_key: string, value: any) => + typeof value === "bigint" ? value.toString() : value diff --git a/src/pages/Transactions/transactions.state.ts b/src/pages/Transactions/transactions.state.ts index e49be45..75a8a84 100644 --- a/src/pages/Transactions/transactions.state.ts +++ b/src/pages/Transactions/transactions.state.ts @@ -9,6 +9,8 @@ import { import { HexString, InvalidTxError, TxBroadcastEvent } from "polkadot-api" import { catchError, + filter, + merge, mergeMap, Observable, of, @@ -22,6 +24,8 @@ const [signedTx$, trackSignedTx] = createSignal() const [unsignedTx$, trackUnsignedTx] = createSignal() export { trackSignedTx, trackUnsignedTx } +export const [dismissTransaction$, dismissTransaction] = createSignal() + const transactions$ = mergeWithKey({ signedTx$, unsignedTx$ }).pipe( withLatestFrom(chainClient$), mergeMap(([tx, { client }]) => { @@ -46,6 +50,7 @@ const transactions$ = mergeWithKey({ signedTx$, unsignedTx$ }).pipe( value: err, }), ), + takeUntil(dismissTransaction$.pipe(filter((v) => v === txHash))), ) }), ) @@ -53,7 +58,15 @@ const transactions$ = mergeWithKey({ signedTx$, unsignedTx$ }).pipe( const [tx$, txKeys$] = partitionByKey( transactions$, (x) => x.txHash, - (x) => x.pipe(takeUntil(chainClient$.pipe(skip(1)))), + (x, hash) => + x.pipe( + takeUntil( + merge( + chainClient$.pipe(skip(1)), + dismissTransaction$.pipe(filter((v) => v === hash)), + ), + ), + ), ) export const grouppedTransactions$ = state(combineKeys(txKeys$, tx$))