Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP chore: update tip cross platform log #1405

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/adapters/mochi-pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class MochiPay extends Fetcher {
token: string
type: "paylink" | "payme"
note?: string
chain_id?: string
recipient_id?: string
}) {
return await this.jsonFetch(`${MOCHI_PAY_API_BASE_URL}/pay-requests`, {
Expand Down
7 changes: 7 additions & 0 deletions src/adapters/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ class Profile extends Fetcher {
return await res?.json()
}

public async getByTelegramUsername(username: string) {
const res = await fetch(
`${MOCHI_PROFILE_API_BASE_URL}/profiles/telegram/get-by-username/${username}`
)
return await res?.json()
}

public async getUserActivities(
profileId: string,
{
Expand Down
29 changes: 9 additions & 20 deletions src/commands/tip/telegram/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
parseMoniker,
parseTipAmount,
} from "utils/tip-bot"
import mochiTelegram from "../../../adapters/mochi-telegram"
import profile from "../../../adapters/profile"
import { InsufficientBalanceError } from "../../../errors/insufficient-balance"
import { UnsupportedTokenError } from "../../../errors/unsupported-token"
Expand All @@ -52,33 +51,19 @@ async function getRecipients(
const recipients: TelegramUser[] = []
for (const target of targets) {
// TODO: handle for case not have username telegram
const { data, ok, curl, error, log } = await mochiTelegram.getByUsername(
target
)
if (!ok) {
throw new APIError({ curl, error, description: log })
}

const recipientPf = await profile.getByTelegram(data.id)
if (recipientPf.status_code === 404) {
const recipientProfile = await profile.getByTelegramUsername(target)
if (recipientProfile.status_code === 400) {
throw new InternalError({
msgOrInteraction,
title: "Username not found",
description: `We couldn't find username \`${target}\`. Check the username you entered or try again.`,
})
}
if (recipientPf.err) {
throw new APIError({
msgOrInteraction,
description: `[getByTelegram] failed with status ${recipientPf.status_code}: ${recipientPf.err}`,
curl: "",
})
}

recipients.push({
id: data.id,
username: data.username,
profile_id: recipientPf.id,
id: recipientProfile.id,
username: target,
profile_id: recipientProfile.id,
})
}
return recipients
Expand All @@ -94,6 +79,7 @@ export async function execute(
amount: payload.originalAmount.toString(),
token: payload.token,
note: payload.note,
chain_id: payload.chain_id,
type: "paylink",
recipient_id: payload.tos[0].profile_global_id, // currently tip across platform have 1 recipient. If expand to tip many, need update api to receive list of recipients
})
Expand Down Expand Up @@ -268,6 +254,9 @@ async function validateAndTransfer(
payload: any,
balance: any
) {
console.log("in validateAndTransfer telegram")
console.log("check balance", balance)
console.log("check payload", payload)
const decimal = balance.token?.decimal ?? 0
const current = +balance.amount / Math.pow(10, decimal)

Expand Down
Loading