Fix unknown markets

This commit is contained in:
Philippe Maes 2020-09-16 10:34:19 +02:00
parent dde7830dd2
commit 6a6e4e6385
3 changed files with 32 additions and 18 deletions

View File

@ -21,11 +21,12 @@ const DATA_LABELS = {
export default function DexInstruction({ instruction, onOpenAddress }) {
const wallet = useWallet();
const [publicKeys] = useWalletPublicKeys();
const { type, data, marketInfo } = instruction;
const { type, data, market, marketInfo } = instruction;
const marketLabel =
marketInfo?.name + (marketInfo?.deprecated ? '(deprecated)' : '') ||
marketInfo?.address?.toBase58() ||
(marketInfo &&
marketInfo?.name + (marketInfo?.deprecated ? '(deprecated)' : '')) ||
market?._decoded?.ownAddress?.toBase58() ||
'Unknown';
const getAddressValue = (address) => {
@ -49,7 +50,11 @@ export default function DexInstruction({ instruction, onOpenAddress }) {
label="Market"
value={marketLabel}
link={true}
onClick={() => onOpenAddress(marketInfo?.address?.toBase58())}
onClick={() =>
onOpenAddress(
(marketInfo?.address || market?._decoded?.ownAddress)?.toBase58(),
)
}
/>
{data &&
Object.entries(data).map(([key, value]) => {

View File

@ -7,8 +7,9 @@ export default function Neworder({ instruction, onOpenAddress }) {
const { side, limitPrice, maxQuantity, orderType } = data;
const marketLabel =
marketInfo?.name + (marketInfo?.deprecated ? '(deprecated)' : '') ||
marketInfo?.address?.toBase58() ||
(marketInfo &&
marketInfo?.name + (marketInfo?.deprecated ? '(deprecated)' : '')) ||
market?._decoded?.ownAddress?.toBase58() ||
'Unknown';
return (
@ -24,7 +25,11 @@ export default function Neworder({ instruction, onOpenAddress }) {
label="Market"
value={marketLabel}
link={true}
onClick={() => onOpenAddress(marketInfo?.address?.toBase58())}
onClick={() =>
onOpenAddress(
(marketInfo?.address || market?._decoded?.ownAddress)?.toBase58(),
)
}
/>
<LabelValue
label="Side"

View File

@ -65,7 +65,7 @@ const toInstruction = async (
console.log('[' + index + '] Handled as dex instruction');
return await handleDexInstruction(
connection,
instruction.accounts,
instruction,
accountKeys,
decodedInstruction,
marketCache,
@ -102,7 +102,7 @@ const toInstruction = async (
const handleDexInstruction = async (
connection,
accounts,
instruction,
accountKeys,
decodedInstruction,
marketCache,
@ -111,6 +111,8 @@ const handleDexInstruction = async (
return;
}
const { accounts, programIdIndex } = instruction;
// get market info
const marketInfo =
accountKeys &&
@ -124,16 +126,18 @@ const handleDexInstruction = async (
// get market
let market;
try {
const marketAddress =
marketInfo?.address || getAccountByIndex(accounts, accountKeys, 0);
const programIdAddress =
marketInfo?.programId ||
getAccountByIndex([programIdIndex], accountKeys, 0);
market =
marketInfo &&
(marketCache[marketInfo.address.toBase58()] ||
(await Market.load(
connection,
marketInfo.address,
{},
marketInfo.programId,
)));
if (market) marketCache[marketInfo.address.toBase58()] = market;
marketAddress &&
programIdAddress &&
(marketCache[marketAddress] ||
(await Market.load(connection, marketAddress, {}, programIdAddress)));
if (market) marketCache[marketAddress.toBase58()] = market;
} catch (e) {
console.log('Error loading market: ' + e.message);
}