Fix account restoration view

This commit is contained in:
Armani Ferrante 2021-02-20 17:19:29 +08:00
parent 1fa5f2ce96
commit ff3d98b5c3
No known key found for this signature in database
GPG Key ID: D597A80BCF8E12B7
1 changed files with 26 additions and 31 deletions

View File

@ -1,4 +1,4 @@
import React, { useState, useMemo, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
@ -57,6 +57,28 @@ const balanceFormat = new Intl.NumberFormat(undefined, {
useGrouping: true,
});
const serumMarkets = (() => {
const m = {};
MARKETS.forEach((market) => {
const coin = market.name.split('/')[0];
if (m[coin]) {
// Only override a market if it's not deprecated .
if (!m.deprecated) {
m[coin] = {
publicKey: market.address,
name: market.name.split('/').join(''),
};
}
} else {
m[coin] = {
publicKey: market.address,
name: market.name.split('/').join(''),
};
}
});
return m;
})();
export default function BalancesList() {
const wallet = useWallet();
const [publicKeys, loaded] = useWalletPublicKeys();
@ -66,28 +88,6 @@ export default function BalancesList() {
);
const { accounts, setAccountName } = useWalletSelector();
const selectedAccount = accounts.find((a) => a.isSelected);
const serumMarkets = useMemo(() => {
const m = {};
MARKETS.forEach((market) => {
const coin = market.name.split('/')[0];
if (m[coin]) {
// Only override a market if it's not deprecated .
if (!m.deprecated) {
m[coin] = {
publicKey: market.address,
name: market.name.split('/').join(''),
};
}
} else {
m[coin] = {
publicKey: market.address,
name: market.name.split('/').join(''),
};
}
});
return m;
}, []);
return (
<Paper>
@ -127,11 +127,7 @@ export default function BalancesList() {
</AppBar>
<List disablePadding>
{publicKeys.map((publicKey) => (
<BalanceListItem
key={publicKey.toBase58()}
publicKey={publicKey}
serumMarkets={serumMarkets}
/>
<BalanceListItem key={publicKey.toBase58()} publicKey={publicKey} />
))}
{loaded ? null : <LoadingIndicator />}
</List>
@ -170,7 +166,7 @@ const useStyles = makeStyles((theme) => ({
},
}));
export function BalanceListItem({ publicKey, serumMarkets, expandable }) {
export function BalanceListItem({ publicKey, expandable }) {
const balanceInfo = useBalanceInfo(publicKey);
const classes = useStyles();
const connection = useConnection();
@ -199,7 +195,7 @@ export function BalanceListItem({ publicKey, serumMarkets, expandable }) {
setPrice(null);
}
}
}, [serumMarkets, price, balanceInfo, connection]);
}, [price, balanceInfo, connection]);
expandable = expandable === undefined ? true : expandable;
@ -462,7 +458,6 @@ class PriceStore {
return;
}
if (this.cache[marketName] === undefined) {
this.cache[marketName] = null;
fetch(`https://serum-api.bonfida.com/orderbooks/${marketName}`).then(
(resp) => {
resp.json().then((resp) => {