Skip to content

Commit

Permalink
Merge branch 'preview'
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnh12 committed Mar 27, 2024
2 parents 826d690 + 70877ad commit c0c01b5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [6.46.3-rc.1](https://github.com/consolelabs/mochi-discord/compare/v6.46.2...v6.46.3-rc.1) (2024-03-27)


### Bug Fixes

* ticker - update format ([#1640](https://github.com/consolelabs/mochi-discord/issues/1640)) ([5f13ebb](https://github.com/consolelabs/mochi-discord/commit/5f13ebbf1d731ca75f56644e5c441e6926364537))

## [6.46.2](https://github.com/consolelabs/mochi-discord/compare/v6.46.1...v6.46.2) (2024-03-27)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@
"node": "18.x"
},
"name": "mochi-discord",
"version": "6.46.2"
"version": "6.46.3-rc.1"
}
78 changes: 54 additions & 24 deletions src/commands/ticker/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getEmojiToken,
TokenEmojiKey,
getEmojiURL,
shortenHashOrAddress,
} from "utils/common"
import {
renderCompareTokenChart,
Expand All @@ -34,6 +35,7 @@ import { getProfileIdByDiscord } from "../../../utils/profile"
import { utils } from "@consolelabs/mochi-formatter"
import moment from "moment-timezone"
import { formatBigNumber } from "utils/convert"
import { uniqBy } from "lodash"

const CURRENCY = "usd"
const DIVIDER = getEmoji("LINE").repeat(5)
Expand Down Expand Up @@ -158,13 +160,36 @@ export async function renderSingle(
total_supply,
} = coin.market_data

let icoDate = (coin as any)?.ico_data?.ico_start_date

const maxSupply = max_supply || total_supply
const fdv = maxSupply
? `$${formatBigNumber((current_price?.[CURRENCY] ?? 0) * maxSupply)}`
: "N/A"

// if price is x thousands (e.g. 3.5k), show without shorten format
const isPriceThousands =
current_price?.[CURRENCY] >= 1000 && current_price?.[CURRENCY] < 1000000
const currentPrice = isPriceThousands
? utils.formatUsdPriceDigit({
value: current_price[CURRENCY],
shorten: false,
})
: utils.formatUsdPriceDigit({
value: current_price?.[CURRENCY] ?? 0,
subscript: true,
})

// ath price
const isAthThousands = ath?.[CURRENCY] >= 1000 && ath?.[CURRENCY] < 1000000
const athPrice = isAthThousands
? utils.formatUsdPriceDigit({
value: ath[CURRENCY],
shorten: false,
})
: utils.formatUsdPriceDigit({
value: ath?.[CURRENCY] ?? 0,
subscript: true,
})

const current =
type === ChartType.Dominance
? utils.formatPercentDigit(
Expand All @@ -173,10 +198,7 @@ export async function renderSingle(
(total_market_cap?.[CURRENCY] ?? 0),
),
)
: utils.formatUsdPriceDigit({
value: current_price?.[CURRENCY] ?? 0,
subscript: true,
})
: currentPrice

// dexscreener data
const { data: dexScreenerData }: any = await defi.searchDexScreenerPairs({
Expand All @@ -187,16 +209,29 @@ export async function renderSingle(

// exchange platforms
const tickers = [
...(pair
? [{ market: { name: "Dex Screener" }, trade_url: pair.url.dexscreener }]
: []),
...(coin.tickers || []),
...(coin.tickers || []).map((ticker: any) => ({
...ticker,
volume_usd_24h: ticker?.converted_volume?.[CURRENCY],
})),
]
const exchangePlats = tickers.map(
(ticker: any) => `[${ticker.market.name}](${ticker.trade_url})`,
)
const exchangePlats = uniqBy(
[
...(pair
? [
{
market: { name: "Dex Screener" },
trade_url: pair.url.dexscreener,
volume_usd_24h: pair.volume_usd_24h,
},
]
: []),
...tickers.sort((a, b) => b.volume_usd_24h - a.volume_usd_24h),
],
(ticker: any) => ticker.market.name,
).map((ticker) => `[${ticker.market.name}](${ticker.trade_url})`)

// age
const icoDate = (coin as any)?.ico_data?.ico_start_date
const diff = moment.duration(
moment(moment.now()).diff(moment(icoDate || pair?.created_at)),
)
Expand Down Expand Up @@ -230,18 +265,13 @@ export async function renderSingle(
},
{
name: `${getEmoji("ANIMATED_FLASH")} ATH`,
value: ath
? `${utils.formatUsdPriceDigit({
value: ath[CURRENCY] ?? 0,
subscript: true,
})}`
: "N/A",
value: ath ? athPrice : "N/A",
inline: true,
},
{
name: `${getEmoji("ANIMATED_FLASH")} Volume (24h)`,
value: total_volume
? `${utils.formatUsdDigit(total_volume[CURRENCY])}`
? `$${formatBigNumber(total_volume[CURRENCY])}`
: "N/A",
inline: true,
},
Expand Down Expand Up @@ -285,8 +315,10 @@ export async function renderSingle(
? [
{
name: "Address",
value: `\`${coin.platforms?.[coin.asset_platform_id]}\``,
inline: false,
value: shortenHashOrAddress(
coin.platforms?.[coin.asset_platform_id],
),
inline: true,
},
]
: []),
Expand All @@ -308,9 +340,7 @@ export async function renderSingle(
color: getChartColorConfig(coin.id).borderColor as HexColorString,
author: [
`${coin.name} (${
// coin.asset_platform
coin.asset_platform?.name || coin.asset_platform?.shortname || coin.name
// : ""
})`,
coin.image.small,
],
Expand Down
1 change: 0 additions & 1 deletion src/ui/discord/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ export function justifyEmbedFields(embed: MessageEmbed, cols: number) {
if (nrOfInlineFields % cols === 0) {
return embed
}
embed.addFields(Array(cols - (nrOfInlineFields % cols)).fill(EMPTY_FIELD))
embed.fields = [
...embed.fields.slice(0, nrOfInlineFields),
...Array(cols - (nrOfInlineFields % cols)).fill(EMPTY_FIELD),
Expand Down

0 comments on commit c0c01b5

Please sign in to comment.