@@ -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)
|
||||
|
||||
@@ -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<string>()
|
||||
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,
|
||||
|
||||
@@ -78,7 +78,6 @@ export default function SubmitTxF(props: {
|
||||
<AccountProvider />
|
||||
<div className="flex flex-col gap-2">
|
||||
<SignAndSubmit {...props} />
|
||||
<div className="text-center">Or</div>
|
||||
<SubmitUnsigned {...props} />
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -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 (
|
||||
<span>
|
||||
Invalid transaction. {JSON.stringify(event.value, null, 2)}
|
||||
Invalid transaction.{" "}
|
||||
{JSON.stringify(event.value, bigintReplacer, 2)}
|
||||
</span>
|
||||
)
|
||||
case "txBestBlocksState": {
|
||||
@@ -37,7 +39,7 @@ export const Transaction: React.FC<{
|
||||
>
|
||||
best block
|
||||
</Link>
|
||||
.
|
||||
{event.ok ? "." : ", but it's failing."}
|
||||
</span>
|
||||
) : (
|
||||
<span>Transaction no longer in a best block.</span>
|
||||
@@ -58,7 +60,9 @@ export const Transaction: React.FC<{
|
||||
{" "}
|
||||
finalized block
|
||||
</Link>
|
||||
.
|
||||
{event.ok
|
||||
? "."
|
||||
: `, but it failed: ${JSON.stringify(event.dispatchError, bigintReplacer, 2)}.`}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -66,14 +70,22 @@ export const Transaction: React.FC<{
|
||||
const { txHash, type } = event
|
||||
return (
|
||||
<div className="mb-4 p-3 bg-secondary/60 text-secondary-foreground/80 border border-border rounded-lg">
|
||||
<p className="font-medium">
|
||||
{shortStr(txHash, 14)} <CopyText text={txHash} />
|
||||
</p>
|
||||
<div className="flex justify-between items-start">
|
||||
<p className="font-medium">
|
||||
{shortStr(txHash, 14)} <CopyText text={txHash} />
|
||||
</p>
|
||||
<button
|
||||
className="text-red-500"
|
||||
onClick={() => dismissTransaction(txHash)}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
</div>
|
||||
<p
|
||||
className={`text-sm ${
|
||||
onGoingEvents.has(type)
|
||||
? "text-yellow-500"
|
||||
: type === "finalized"
|
||||
: type === "finalized" && event.ok
|
||||
? "text-green-500"
|
||||
: "text-red-500"
|
||||
}`}
|
||||
@@ -83,3 +95,6 @@ export const Transaction: React.FC<{
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const bigintReplacer = (_key: string, value: any) =>
|
||||
typeof value === "bigint" ? value.toString() : value
|
||||
|
||||
@@ -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<HexString>()
|
||||
const [unsignedTx$, trackUnsignedTx] = createSignal<HexString>()
|
||||
export { trackSignedTx, trackUnsignedTx }
|
||||
|
||||
export const [dismissTransaction$, dismissTransaction] = createSignal<string>()
|
||||
|
||||
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$))
|
||||
|
||||
Reference in New Issue
Block a user