Skip to content

Commit

Permalink
fix: transfer request - adopt new endpoints (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnh12 authored Jan 9, 2024
1 parent b42dac2 commit e2b6517
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/adapters/mochi-pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,17 @@ class MochiPay extends Fetcher {

async approveTransferRequest({
headers,
profileId,
requestCode,
appId = "1",
}: {
headers: Record<string, string>
profileId: string
requestCode: string
appId?: string
}) {
return await this.jsonFetch(
`${MOCHI_PAY_API_BASE_URL}/applications/${appId}/requests/${requestCode}/approved`,
`${MOCHI_PAY_API_BASE_URL}/profiles/${profileId}/applications/${appId}/requests/${requestCode}/approved`,
{
method: "POST",
headers,
Expand All @@ -275,15 +277,17 @@ class MochiPay extends Fetcher {

async rejectTransferRequest({
headers,
profileId,
requestCode,
appId = "1",
}: {
headers: Record<string, string>
profileId: string
requestCode: string
appId?: string
}) {
return await this.jsonFetch(
`${MOCHI_PAY_API_BASE_URL}/applications/${appId}/requests/${requestCode}/rejected`,
`${MOCHI_PAY_API_BASE_URL}/profiles/${profileId}/applications/${appId}/requests/${requestCode}/rejected`,
{
method: "POST",
headers,
Expand Down
5 changes: 5 additions & 0 deletions src/commands/transfer_request/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as ed25519 from "@noble/ed25519"
import { sha512 } from "@noble/hashes/sha512"
import { MOCHI_APP_PRIVATE_KEY } from "env"
import { composeEmbedMessage, composeEmbedMessage2 } from "ui/discord/embed"
import { getProfileIdByDiscord } from "utils/profile"
ed25519.etc.sha512Async = (...m) =>
Promise.resolve(sha512(ed25519.etc.concatBytes(...m)))

Expand All @@ -29,9 +30,11 @@ export async function approveTransferReq(i: ButtonInteraction) {
return
}

const profileId = await getProfileIdByDiscord(i.user.id)
const appHeaders = await getMochiApplicationHeaders()
const { ok, status } = await mochiPay.approveTransferRequest({
headers: appHeaders,
profileId,
appId,
requestCode,
})
Expand All @@ -56,9 +59,11 @@ export async function rejectTransferReq(i: ButtonInteraction) {
return
}

const profileId = await getProfileIdByDiscord(i.user.id)
const appHeaders = await getMochiApplicationHeaders()
const { ok, status } = await mochiPay.rejectTransferRequest({
headers: appHeaders,
profileId,
appId,
requestCode,
})
Expand Down

0 comments on commit e2b6517

Please sign in to comment.