Skip to content

Commit

Permalink
Merge branch 'develop' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnh12 committed Jun 3, 2024
2 parents 67bdd64 + 99d3c64 commit 1b4fc3e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/adapters/mochi-pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ class MochiPay extends Fetcher {
`${MOCHI_PAY_API_BASE_URL}/profiles/${profileId}/syndicates/earning-vaults/${vaultId}/trade-rounds`,
)
}

async getEarningVaultConfigs(
profileId: string,
vaultId: string,
): Promise<any> {
const { ok, data: res } = await this.jsonFetch(
`${MOCHI_PAY_API_BASE_URL}/profiles/${profileId}/syndicates/earning-vaults/${vaultId}/configs`,
)
let data = null
if (ok) {
data = res as any
}
return data
}
}

export default new MochiPay()
34 changes: 34 additions & 0 deletions src/commands/vault/view/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,48 @@ import { GuildIdNotFoundError } from "errors"
import { composeEmbedMessage } from "ui/discord/embed"
import { getEmoji, msgColors } from "utils/common"
import { buildTreasurerFields } from "../info/processor"
import mochiPay from "adapters/mochi-pay"
import { getDiscordIdByProfileId, getProfileIdByDiscord } from "utils/profile"

export async function run({
i,
guildId,
vaultId,
vaultType,
}: {
i: CommandInteraction
guildId?: string | null
vaultId: string
vaultType: string
}) {
if (vaultType === "trading") {
const profileId = await getProfileIdByDiscord(i.user.id)
const data = await mochiPay.getEarningVaultConfigs(profileId, vaultId)
const { name, api_key, secret_key, thresh_hold } = data
const basicInfo = [
`${getEmoji("ANIMATED_VAULT", true)}\`Name. ${name}\``,
`${getEmoji("ANIMATED_VAULT_KEY")}\`API Key. \` ${api_key}`,
`${getEmoji("ANIMATED_VAULT_KEY")}\`Secret Key. \` ${secret_key}`,
`${getEmoji("APPROVE")}\`Threshold. \` ${thresh_hold}%`,
// `${getEmoji("NEWS")}\`Channel. \` <#1019524376527372288>`,
].join("\n")

const treasurers = await Promise.all(
data.treasurers.map(async (t: any) => {
const discordId = await getDiscordIdByProfileId(t.profile_id)
return { user_discord_id: discordId, role: t.role }
}),
)

const treasurersFields = buildTreasurerFields({ treasurer: treasurers })
const embed = composeEmbedMessage(null, {
title: `${getEmoji("ANIMATED_DIAMOND")} Vault config`,
description: basicInfo,
color: msgColors.BLUE,
}).addFields(treasurersFields)

return { messageOptions: { embeds: [embed] } }
}
if (!guildId) {
throw new GuildIdNotFoundError({ message: i })
}
Expand Down
8 changes: 6 additions & 2 deletions src/commands/vault/view/slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import mochiPay from "adapters/mochi-pay"
const command: SlashCommand = {
name: "view",
category: "Config",
onlyAdministrator: true,
// onlyAdministrator: true,
prepare: () => {
return new SlashCommandSubcommandBuilder()
.setName("view")
Expand Down Expand Up @@ -43,7 +43,7 @@ const command: SlashCommand = {
.filter((d: any) =>
d.name.toLowerCase().includes(focusedValue.toLowerCase()),
)
.map((d: any) => ({ name: d.name, value: `spot_${d.name}` })),
.map((d: any) => ({ name: d.name, value: `spot_${d.id}` })),
...tradingVaults
.filter((v: any) =>
v.name.toLowerCase().includes(focusedValue.toLowerCase()),
Expand All @@ -54,9 +54,13 @@ const command: SlashCommand = {
await i.respond(options)
},
run: async function (interaction: CommandInteraction) {
const arg = interaction.options.getString("name", true)
const [vaultType, vaultId] = arg.split("_", 2)
return run({
i: interaction,
guildId: interaction.guildId ?? undefined,
vaultId,
vaultType,
})
},
help: async (interaction: CommandInteraction) => ({
Expand Down
20 changes: 20 additions & 0 deletions src/utils/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,23 @@ export async function getDiscordRenderableByProfileId(profileId: string) {

return `<@${discord.platform_identifier}>`
}

export async function getDiscordIdByProfileId(profileId: string) {
const pf = await profile.getById(profileId)
if (pf.err) {
throw new APIError({
description: `[getDiscordIdByProfileId] API error with status ${pf.status_code}`,
curl: "",
status: pf.status ?? 500,
error: pf.error,
})
}

const discord = pf.associated_accounts.find((aa: any) =>
equalIgnoreCase(aa.platform, "discord"),
)

if (!discord) return pf.profile_name

return discord.platform_identifier
}

0 comments on commit 1b4fc3e

Please sign in to comment.