From e348e1a6ed1dcce02734362c637cd0aa9e55f8ec Mon Sep 17 00:00:00 2001 From: anhnh12 Date: Thu, 23 May 2024 16:22:10 +0700 Subject: [PATCH] fix: vault detail format (#1666) --- src/commands/vault/info/processor.ts | 28 ++++++++++---------- src/commands/vault/list/processor.ts | 39 +++++++++++++++------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/commands/vault/info/processor.ts b/src/commands/vault/info/processor.ts index 985fd0df4..f9240c0b5 100644 --- a/src/commands/vault/info/processor.ts +++ b/src/commands/vault/info/processor.ts @@ -186,14 +186,16 @@ export async function runGetVaultDetail( const creator = await getDiscordRenderableByProfileId(profileId) const { trade_rounds: rounds, account } = data const basicInfo = [ - `${getEmoji("ANIMATED_VAULT", true)}\`Name. ${data.name}\``, + `${getEmoji("ANIMATED_VAULT", true)}\`Name. \` ${data.name}`, `${getEmoji("ANIMATED_VAULT_KEY", true)}\`Creator. \`${creator}`, `${getEmoji("CALENDAR")}\`Created. \` ${formatDate( new Date(data.created_at), )}`, - `${getEmoji("ANIMATED_BADGE_1")}\`Tier. \` ${account.tier.name}`, - `${getEmoji("CASH")}\`Balance. \`$${formatUsdDigit(account.balance)}`, - `${getEmoji("ANIMATED_VAULT_KEY")}\`Key. \` ${account.api_key}`, + `${getEmoji("ANIMATED_BADGE_1")}\`Tier. \` ${account.tier.name}`, + `${getEmoji("CASH")}\`Balance. \`${utils.formatUsdPriceDigit( + account.balance, + )}`, + `${getEmoji("ANIMATED_VAULT_KEY")}\`Key. \` ${account.api_key}`, ].join("\n") const openRound = rounds.find((r: any) => r.status === 1) @@ -204,19 +206,19 @@ export async function runGetVaultDetail( const roundFields = [ `**Round info**`, - `${getEmoji("CALENDAR")} \`Start. \` ${formatDate( + `${getEmoji("CALENDAR")} \`Start. \` ${formatDate( startDate.toDate(), )}, ${startDiff}`, - `🟢 \`Acc. PnL. \` ${utils.formatUsdPriceDigit( + `🟢 \`Acc. PnL. \` ${utils.formatUsdPriceDigit( account.accumulative_pnl, )} (${utils.formatPercentDigit(account.accumulative_pl * 100)})`, - `🏎️ \`Rounds. \` ${openRound.no}`, + `🏎️ \`Rounds. \` ${openRound.no}`, `🎫 \`Total fee. \` ${utils.formatUsdPriceDigit(openRound.fee)}`, ].join("\n") const vaultEquity = [ "**Vault equity**", - `${getEmoji("CHART")} \`Your share. \` 100%`, + `${getEmoji("CHART")} \`Your share. \` 100%`, `${getEmoji("MONEY")} \`Claimable amount. \` ${utils.formatUsdPriceDigit( account.claimable, )}`, @@ -246,9 +248,6 @@ export async function runGetVaultDetail( r.pnl_percentage >= 0 ? "green" : "red" }_circle: ${utils.formatPercentDigit(r.pnl_percentage)})`, ), - // `\`24.05.07\` ${getEmoji( - // "WAVING_HAND", - // )} Init: $10,653 💰 PnL: -$247 (:red_circle: -2.32%)`, ].join("\n") const address = [ @@ -261,12 +260,13 @@ export async function runGetVaultDetail( )}\``, ].join("\n") + const description = `${basicInfo}\n\n${vaultEquity}\n\n${address}\n\n${roundFields}\n\n${openTrades}\n\n${ + closedRounds.length ? closedTrades : "" + }` const embed = composeEmbedMessage2(interaction as any, { color: msgColors.BLUE, author: ["Trading vault info", getEmojiURL(emojis.ANIMATED_DIAMOND)], - description: `${basicInfo}\n\n${vaultEquity}\n\n${address}\n\n${roundFields}\n\n${openTrades}\n\n${ - closedTrades.length > 1 ? closedTrades : "" - }`, + description, }) return { diff --git a/src/commands/vault/list/processor.ts b/src/commands/vault/list/processor.ts index 87636fbaf..6b4b3a045 100644 --- a/src/commands/vault/list/processor.ts +++ b/src/commands/vault/list/processor.ts @@ -72,17 +72,17 @@ export async function runVaultList(interaction: CommandInteraction) { ? await config.vaultList(interaction.guildId) : await config.vaultList("", false, userProfile.id) - const tradingVaults = (await mochiPay.listEarningVaults(userProfile.id)).map( - (v: any) => ({ - id: v.id, - name: v.name, - wallet_address: v.evm_wallet_address, - total: utils.formatUsdPriceDigit(v.account.balance), - threshold: 100, - type: "trading", - discord_guild: { name: "" }, - }), - ) + const tradingVaults = ( + (await mochiPay.listEarningVaults(userProfile.id)) || [] + ).map((v: any) => ({ + id: v.id, + name: v.name, + wallet_address: v.evm_wallet_address, + total: utils.formatUsdPriceDigit(v.account.balance), + threshold: 100, + type: "trading", + discord_guild: { name: "" }, + })) const data = [...spotVaults, ...tradingVaults] @@ -111,13 +111,16 @@ export async function runVaultList(interaction: CommandInteraction) { data.filter((d) => d.type !== "trading"), interaction.guildId || "", ) - description += "\n\n" - description += "**Trading**\n" - description += formatVaults( - // @ts-ignore - data.filter((d) => d.type === "trading"), - interaction.guildId || "", - ) + + if (tradingVaults.length > 0) { + description += "\n\n" + description += "**Trading**\n" + description += formatVaults( + // @ts-ignore + data.filter((d) => d.type === "trading"), + interaction.guildId || "", + ) + } const embed = composeEmbedMessage(null, { title: `${getEmoji("MOCHI_CIRCLE")} Vault List`,