fix trustless registers + prettier fix (#215)

This commit is contained in:
Adrian Brzeziński 2023-07-22 14:36:22 +02:00 committed by GitHub
parent 9b1c111270
commit 2ee8b708ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 42 additions and 52 deletions

View File

@ -1,4 +1,5 @@
{ {
"semi": false, "semi": false,
"singleQuote": true "singleQuote": true,
"trailingComma": "all"
} }

View File

@ -102,7 +102,7 @@ let marketType: 'spot' | 'perp'
export const queryPerpBars = async ( export const queryPerpBars = async (
tokenAddress: string, tokenAddress: string,
resolution: (typeof SUPPORTED_RESOLUTIONS)[number], resolution: typeof SUPPORTED_RESOLUTIONS[number],
periodParams: { periodParams: {
firstDataRequest: boolean firstDataRequest: boolean
from: number from: number
@ -150,7 +150,7 @@ export const queryPerpBars = async (
export const queryBirdeyeBars = async ( export const queryBirdeyeBars = async (
tokenAddress: string, tokenAddress: string,
resolution: (typeof SUPPORTED_RESOLUTIONS)[number], resolution: typeof SUPPORTED_RESOLUTIONS[number],
periodParams: { periodParams: {
firstDataRequest: boolean firstDataRequest: boolean
from: number from: number

View File

@ -66,7 +66,7 @@ const configurationData = {
export const queryBars = async ( export const queryBars = async (
tokenAddress: string, tokenAddress: string,
resolution: (typeof SUPPORTED_RESOLUTIONS)[number], resolution: typeof SUPPORTED_RESOLUTIONS[number],
periodParams: { periodParams: {
firstDataRequest: boolean firstDataRequest: boolean
from: number from: number

View File

@ -52,12 +52,9 @@ const Layout = ({ children }: { children: ReactNode }) => {
const animationFrames = 15 const animationFrames = 15
for (let x = 1; x <= animationFrames; x++) { for (let x = 1; x <= animationFrames; x++) {
setTimeout( setTimeout(() => {
() => { window.dispatchEvent(new Event('resize'))
window.dispatchEvent(new Event('resize')) }, (sideBarAnimationDuration / animationFrames) * x)
},
(sideBarAnimationDuration / animationFrames) * x,
)
} }
}, [isCollapsed]) }, [isCollapsed])

View File

@ -38,23 +38,17 @@ const HydrateStore = () => {
actions.fetchGroup() actions.fetchGroup()
}, [marketName]) }, [marketName])
useInterval( useInterval(() => {
() => { actions.fetchGroup()
actions.fetchGroup() }, (slowNetwork ? 40 : 20) * SECONDS)
},
(slowNetwork ? 40 : 20) * SECONDS,
)
// refetches open orders every 30 seconds // refetches open orders every 30 seconds
// only the selected market's open orders are updated via websocket // only the selected market's open orders are updated via websocket
useInterval( useInterval(() => {
() => { if (mangoAccountAddress) {
if (mangoAccountAddress) { actions.fetchOpenOrders()
actions.fetchOpenOrders() }
} }, (slowNetwork ? 60 : 30) * SECONDS)
},
(slowNetwork ? 60 : 30) * SECONDS,
)
// refetch trade history and activity feed when switching accounts // refetch trade history and activity feed when switching accounts
useEffect(() => { useEffect(() => {
@ -65,13 +59,10 @@ const HydrateStore = () => {
}, [mangoAccountAddress]) }, [mangoAccountAddress])
// reload and parse market fills from the event queue // reload and parse market fills from the event queue
useInterval( useInterval(async () => {
async () => { const actions = mangoStore.getState().actions
const actions = mangoStore.getState().actions actions.loadMarketFills()
actions.loadMarketFills() }, (slowNetwork ? 60 : 20) * SECONDS)
},
(slowNetwork ? 60 : 20) * SECONDS,
)
// The websocket library solana/web3.js uses closes its websocket connection when the subscription list // The websocket library solana/web3.js uses closes its websocket connection when the subscription list
// is empty after opening its first time, preventing subsequent subscriptions from receiving responses. // is empty after opening its first time, preventing subsequent subscriptions from receiving responses.

View File

@ -492,7 +492,7 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
.instruction() .instruction()
proposalTx.push(editIx) proposalTx.push(editIx)
} else { } else {
await client!.program.methods const trustlessIx = await client!.program.methods
.tokenRegisterTrustless(Number(advForm.tokenIndex), advForm.name) .tokenRegisterTrustless(Number(advForm.tokenIndex), advForm.name)
.accounts({ .accounts({
mint: new PublicKey(advForm.mintPk), mint: new PublicKey(advForm.mintPk),
@ -503,6 +503,8 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
group: group!.publicKey, group: group!.publicKey,
}) })
.instruction() .instruction()
proposalTx.push(trustlessIx)
} }
const registerMarketix = await client!.program.methods const registerMarketix = await client!.program.methods

View File

@ -63,8 +63,8 @@ export default function useSelectedMarket() {
mangoTokens.find( mangoTokens.find(
(t) => t.symbol.toLowerCase() === lowerCaseBaseSymbol, (t) => t.symbol.toLowerCase() === lowerCaseBaseSymbol,
) || ) ||
mangoTokens.find( mangoTokens.find((t) =>
(t) => t.symbol.toLowerCase()?.includes(lowerCaseBaseSymbol), t.symbol.toLowerCase()?.includes(lowerCaseBaseSymbol),
) )
if (token) { if (token) {
return token.logoURI return token.logoURI

View File

@ -825,11 +825,11 @@ const Dashboard: NextPage = () => {
${ ${
perpMarket.quoteLotSize perpMarket.quoteLotSize
} quote (tick size: $${perpMarket.priceLotsToUi( } quote (tick size: $${perpMarket.priceLotsToUi(
new BN(1), new BN(1),
)}, 1 base lot: $${( )}, 1 base lot: $${(
perpMarket.baseLotsToUi(new BN(1)) * perpMarket.baseLotsToUi(new BN(1)) *
perpMarket.uiPrice perpMarket.uiPrice
).toFixed(3)})`} ).toFixed(3)})`}
/> />
<KeyValuePair <KeyValuePair
label="Maint Asset/Liab Weight" label="Maint Asset/Liab Weight"
@ -839,12 +839,14 @@ const Dashboard: NextPage = () => {
${perpMarket.maintBaseLiabWeight.toFixed( ${perpMarket.maintBaseLiabWeight.toFixed(
4, 4,
)} (maint leverage: ${( )} (maint leverage: ${(
1 / 1 /
(perpMarket.maintBaseLiabWeight.toNumber() - 1) (perpMarket.maintBaseLiabWeight.toNumber() -
).toFixed(2)}x, init leverage: ${( 1)
1 / ).toFixed(2)}x, init leverage: ${(
(perpMarket.initBaseLiabWeight.toNumber() - 1) 1 /
).toFixed(2)}x)`} (perpMarket.initBaseLiabWeight.toNumber() -
1)
).toFixed(2)}x)`}
/> />
<KeyValuePair <KeyValuePair
label="Init Asset/Liab Weight" label="Init Asset/Liab Weight"

View File

@ -85,7 +85,7 @@ export const getDeposits = async ({
...x, ...x,
mint: mints[mintCfgs![x.votingMintConfigIdx].mint.toBase58()], mint: mints[mintCfgs![x.votingMintConfigIdx].mint.toBase58()],
index: idx, index: idx,
}) as unknown as DepositWithMintAccount, } as unknown as DepositWithMintAccount),
) )
.filter((x) => typeof isUsed === 'undefined' || x.isUsed === isUsed) .filter((x) => typeof isUsed === 'undefined' || x.isUsed === isUsed)
const usedDeposits = deposits.filter((x) => x.isUsed) const usedDeposits = deposits.filter((x) => x.isUsed)

View File

@ -7,10 +7,7 @@ export const DEFAULT_VSR_ID = new web3.PublicKey(
) )
export class VsrClient { export class VsrClient {
constructor( constructor(public program: Program<Idl>, public devnet?: boolean) {}
public program: Program<Idl>,
public devnet?: boolean,
) {}
static async connect( static async connect(
provider: Provider, provider: Provider,

View File

@ -6,7 +6,7 @@ export const ONE_HOUR_SECONDS = ONE_HOUR_MINS * ONE_MINUTE_SECONDS
export const ONE_DAY_SECONDS = ONE_HOUR_SECONDS * 24 export const ONE_DAY_SECONDS = ONE_HOUR_SECONDS * 24
export type BASE_CHART_QUERY = { export type BASE_CHART_QUERY = {
address: string address: string
type: (typeof SUPPORTED_SPOT_RESOLUTIONS)[number] type: typeof SUPPORTED_SPOT_RESOLUTIONS[number]
time_to: number time_to: number
} }
export type CHART_QUERY = BASE_CHART_QUERY & { export type CHART_QUERY = BASE_CHART_QUERY & {
@ -16,7 +16,7 @@ export type CHART_QUERY = BASE_CHART_QUERY & {
//Translate values that api accepts to chart seconds //Translate values that api accepts to chart seconds
export const RES_NAME_TO_RES_VAL: { export const RES_NAME_TO_RES_VAL: {
[key: string]: { [key: string]: {
val: (typeof SUPPORTED_SPOT_RESOLUTIONS)[number] val: typeof SUPPORTED_SPOT_RESOLUTIONS[number]
seconds: number seconds: number
} }
} = { } = {