Skip to content

Commit

Permalink
Merge branch 'preview'
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnh12 committed Jul 10, 2024
2 parents cada463 + d3b38ee commit efd07e9
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [6.53.0-rc.1](https://github.com/consolelabs/mochi-discord/compare/v6.52.8...v6.53.0-rc.1) (2024-07-10)


### Features

* earning vault claim ([#1695](https://github.com/consolelabs/mochi-discord/issues/1695)) ([136cc58](https://github.com/consolelabs/mochi-discord/commit/136cc5830745890ef58f3eb1cf628b6a3df8cb37))

## [6.52.8](https://github.com/consolelabs/mochi-discord/compare/v6.52.7...v6.52.8) (2024-07-10)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@
"node": "18.x"
},
"name": "mochi-discord",
"version": "6.52.8"
"version": "6.53.0-rc.1"
}
5 changes: 4 additions & 1 deletion src/adapters/fetcher/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export function makeLog({

export function attachAuthorization(url: string, options: any) {
// only attach token for mochi-pay's request atm
if (url.startsWith(MOCHI_PAY_API_BASE_URL)) {
if (
url.startsWith(MOCHI_PAY_API_BASE_URL) &&
!options.headers["Authorization"]
) {
options.headers = {
...options.headers,
Authorization: `Basic ${MOCHI_API_KEY}`,
Expand Down
17 changes: 17 additions & 0 deletions src/adapters/mochi-pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import { Fetcher } from "./fetcher"
import fetch from "node-fetch"
import { getKrystalEarnPortfolioResponse } from "types/mochipay"
import { MOCHI_BOT_SECRET } from "env"

type KrystalStakeRequest = {
chain_id: number
Expand Down Expand Up @@ -403,6 +404,22 @@ class MochiPay extends Fetcher {
}
return data
}

async claimTradingVault({
profileId,
vaultId,
}: {
profileId: string
vaultId: string
}): Promise<any> {
return await this.jsonFetch(
`${MOCHI_PAY_API_BASE_URL}/profiles/${profileId}/syndicates/earning-vaults/${vaultId}/claim`,
{
method: "POST",
headers: { Authorization: `Bearer ${MOCHI_BOT_SECRET}` },
},
)
}
}

export default new MochiPay()
45 changes: 40 additions & 5 deletions src/commands/vault/info/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ export async function runGetVaultDetail({
value: Number(share),
fractionDigits: 4,
})}`,
`${getEmoji("GIFT")} \`Floating profit. \` ${utils.formatUsdPriceDigit({
value: Number(report.vault_equity.floating_profit ?? 0),
shorten: false,
})}`,
// `${getEmoji("GIFT")} \`Floating profit. \` ${utils.formatUsdPriceDigit({
// value: Number(report.vault_equity.floating_profit ?? 0),
// shorten: false,
// })}`,
`:tada: \`Claimable amount. \` ${claiambleInfo}`,
].join("\n")

Expand Down Expand Up @@ -437,6 +437,8 @@ export async function runGetVaultDetail({
},
vaultId: selectedVault,
report,
profileId,
vaultName: data.name,
},
msgOpts: {
embeds: [embed],
Expand All @@ -448,7 +450,7 @@ export async function runGetVaultDetail({
.setStyle("SECONDARY")
.setCustomId("claim")
.setEmoji("<:FeelsGood:1177549805048836126>")
.setDisabled(Number(report.vault_equity.claimable ?? 0) > 0),
.setDisabled(Number(report.member_equity?.claimable ?? 0) <= 0),
new MessageButton()
.setLabel("Report")
.setEmoji(getEmoji("CHART"))
Expand Down Expand Up @@ -803,3 +805,36 @@ function formatDateTime(s: string | undefined, timeOnly?: boolean) {
.toLocaleTimeString("en-US", { hour12: true, hour: "numeric" })
.replace(" ", "")}`
}

export async function vaultClaim({
interaction,
vaultId,
profileId,
vaultName,
}: {
interaction: ButtonInteraction
vaultId: string
profileId: string
vaultName: string
}) {
const { ok } = await mochiPay.claimTradingVault({ profileId, vaultId })
if (!ok) {
throw new InternalError({
msgOrInteraction: interaction,
title: "Failed to claim",
})
}

const embed = composeEmbedMessage2(interaction as any, {
title: vaultName,
description: "You have claimed successfully",
})

return {
msgOpts: {
embeds: [embed],
components: [],
attachments: [],
},
}
}
18 changes: 17 additions & 1 deletion src/commands/vault/info/slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { MachineConfig, route, RouterSpecialAction } from "utils/router"

import { SlashCommandSubcommandBuilder } from "@discordjs/builders"

import { handleVaultRounds, runGetVaultDetail, vaultReport } from "./processor"
import {
handleVaultRounds,
runGetVaultDetail,
vaultClaim,
vaultReport,
} from "./processor"
import profile from "adapters/profile"
import mochiPay from "adapters/mochi-pay"
import { runVaultList } from "commands/vault/list/processor"
Expand Down Expand Up @@ -44,6 +49,15 @@ export const machineConfig: (
return handleVaultRounds(vaultId, i)
},
vaultList: (i) => runVaultList(i),
vaultClaim: (i, _ev, ctx) => {
const { vaultId, profileId, vaultName } = ctx
return vaultClaim({
vaultName,
interaction: i,
vaultId,
profileId,
})
},
},
select: {
vaultInfo: async (i, _ev, ctx) => {
Expand Down Expand Up @@ -86,13 +100,15 @@ export const machineConfig: (
[RouterSpecialAction.BACK]: "vaultInfo",
},
},
vaultClaim: {},
vaultInfo: {
on: {
BACK: [
{ target: "vaultList", cond: (context) => !!context.fromVaultList },
],
ROUNDS: "vaultRounds",
REPORT: "vaultReport",
CLAIM: "vaultClaim",
DEPOSIT: {
target: "vaultInfo",
actions: {
Expand Down

0 comments on commit efd07e9

Please sign in to comment.