Improvements
This commit is contained in:
+4
-2
@@ -4,6 +4,8 @@ import { CONSENSUS, NETWORK, isNftTrade, nftTradeMessage, type NftTrade, type Te
|
||||
import { tradeOfferSchema, type TradeOffer } from '../shared/trade-offer.ts';
|
||||
import type { Wallet } from './wallet.ts';
|
||||
import './trade.css';
|
||||
import { StateClient } from '../shared/rpc-client.ts';
|
||||
const stateClient = new StateClient();
|
||||
|
||||
type Props = { wallet?: Wallet; snapshot?: TestnetSnapshot; rpcAvailable: boolean; onNotice: (message: string) => void };
|
||||
type OwnedCard = TestnetDeck['nfts'][number];
|
||||
@@ -124,7 +126,7 @@ export function TradeDesk({ wallet, snapshot, rpcAvailable, onNotice }: Props) {
|
||||
}
|
||||
setBusy(true); setOfferError('');
|
||||
try {
|
||||
const fresh = await api<TestnetSnapshot>('state');
|
||||
const fresh = await stateClient.load();
|
||||
if (fresh.chainId !== snapshot.chainId || remoteDeck.chainId !== fresh.chainId) throw new Error('Chain changed. Refresh and rebuild the trade.');
|
||||
const offeredLegs = [...offered].map(cardHash => {
|
||||
const card = myDeck.find(item => item.block.tokenId === cardHash);
|
||||
@@ -166,7 +168,7 @@ export function TradeDesk({ wallet, snapshot, rpcAvailable, onNotice }: Props) {
|
||||
if (offer.network !== NETWORK || offer.chainId !== snapshot.chainId) throw new Error('Offer is for another network or chain.');
|
||||
if (offer.counterparty !== wallet.address) throw new Error('This offer is addressed to a different wallet.');
|
||||
if (!await verifyOfferSignature(offer)) throw new Error('The proposer signature is invalid; do not accept this offer.');
|
||||
const fresh = await api<TestnetSnapshot>('state');
|
||||
const fresh = await stateClient.load();
|
||||
if (fresh.chainId !== offer.chainId) throw new Error('The chain changed. Reload and review the offer again.');
|
||||
for (const leg of offer.offered) {
|
||||
const block = fresh.blocks.find(item => item.tokenId === leg.cardHash);
|
||||
|
||||
Reference in New Issue
Block a user