Skip to content

Commit

Permalink
fix: replace is evm by chain type (#1507)
Browse files Browse the repository at this point in the history
Co-authored-by: sp.bean <[email protected]>
  • Loading branch information
baenv and sp.bean authored Oct 3, 2023
1 parent d7e00d6 commit 6ecd39a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/commands/balances/index/processor.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import profile from "adapters/profile"
import { CommandInteraction } from "discord.js"
import { composeEmbedMessage, justifyEmbedFields } from "ui/discord/embed"
import { chainTypes } from "utils/chain"
import { getSlashCommand } from "utils/commands"
import { emojis, getEmoji, getEmojiURL } from "utils/common"

import mockdc from "../../../../tests/mocks/discord"
import mochiPay from "../../../adapters/mochi-pay"
import { BalanceType, renderBalances } from "./processor"
Expand Down Expand Up @@ -40,7 +42,7 @@ describe("balances", () => {
rpc: "https://polygon.llamarpc.com",
explorer: "https://polygonscan.com",
icon: "https://cdn.discordapp.com/emojis/928216430535671818.png?size=240&quality=lossless",
is_evm: true,
type: chainTypes.EVM,
},
},
other_profile: null,
Expand Down
9 changes: 5 additions & 4 deletions src/commands/deposit/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { APIError, InternalError } from "errors"
import qrcode from "qrcode"
import { composeEmbedMessage, formatDataTable } from "ui/discord/embed"
import { isEvm } from "utils/chain"
import {
emojis,
getAuthor,
Expand Down Expand Up @@ -69,7 +70,7 @@ export async function deposit(
decimal: a.token.decimal,
chainId: Number(a.token.chain_id ?? 1),
tokenAddress: a.token.address,
isEVM: a.contract.chain.is_evm,
chainType: a.contract.chain.type,
isNative: a.token.native,
explorer: a.contract.chain.explorer,
}))
Expand Down Expand Up @@ -102,7 +103,7 @@ export function renderListDepositAddress({
}

const dataRows = addresses.map((a) => {
const link = a.isEVM
const link = isEvm(a.chainType)
? toMetamaskDeeplink(
a.address,
amount,
Expand Down Expand Up @@ -201,7 +202,7 @@ export async function depositDetail(
) {
let link
// create QR code image
if (depositObj.isEVM) {
if (isEvm(depositObj.chainType)) {
link = toMetamaskDeeplink(
i.values.at(0) ?? "",
amount,
Expand All @@ -225,7 +226,7 @@ export async function depositDetail(
"ANIMATED_POINTING_RIGHT",
true,
)} Transactions take up to 5 minutes to process.`,
...(depositObj.isEVM
...(isEvm(depositObj.chainType)
? [`${getEmoji("METAMASK")} Scan QR to auto-fill in Metamask.`]
: []),
getEmoji("LINE").repeat(5),
Expand Down
23 changes: 12 additions & 11 deletions src/commands/pay/me/processor.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
import mochiPay from "adapters/mochi-pay"
import profile from "adapters/profile"
import { utils } from "@consolelabs/mochi-ui"
import { CommandInteraction } from "discord.js"
import { APIError, InternalError, OriginalMessage } from "errors"
import { composeEmbedMessage } from "ui/discord/embed"
import { UnsupportedTokenError } from "errors/unsupported-token"
import { isTokenSupported, parseMoniker } from "utils/tip-bot"
import { parseUnits } from "ethers/lib/utils"
import { embedsColors } from "types/common"
import { composeButtonLink } from "ui/discord/button"

import { composeEmbedMessage } from "ui/discord/embed"
import { isEvm } from "utils/chain"
import {
TokenEmojiKey,
emojis,
equalIgnoreCase,
getAuthor,
getEmoji,
getEmojiToken,
getEmojiURL,
TokenEmojiKey,
} from "utils/common"
import {
MOCHI_ACTION_PAY_ME,
MOCHI_PLATFORM_DISCORD,
PREFIX_EMAIL_HANDLER,
PREFIX_DISCORD_HANDLER,
PREFIX_EMAIL_HANDLER,
PREFIX_TELEGRAM_HANDLER,
SPACES_REGEX,
} from "utils/constants"
import { reply } from "utils/discord"
import { sendNotificationMsg } from "utils/kafka"
import { isTokenSupported, parseMoniker } from "utils/tip-bot"

import { utils } from "@consolelabs/mochi-ui"

import { parseDiscordToken } from "../../../utils/commands"
import { dmUser } from "../../../utils/dm"
import { parseUnits } from "ethers/lib/utils"
import { getToken } from "../../../utils/tip-bot"
import { parseDiscordToken } from "../../../utils/commands"
import { Message } from "@solana/web3.js"

const typePayRequest = 16
export async function run({
Expand Down Expand Up @@ -70,7 +71,7 @@ export async function run({
if (!mochiWalletResOk) throw new Error()
inAppWallets ||= []
inAppWallets = inAppWallets.filter((w: any) => {
if (t?.chain?.is_evm) {
if (t?.chain?.type && isEvm(t?.chain?.type)) {
return equalIgnoreCase(w.chain.symbol, "evm")
}
return equalIgnoreCase(w.chain.symbol, t?.chain?.symbol ?? "")
Expand All @@ -96,7 +97,7 @@ export async function run({
}
})
.filter((w: any) => {
if (t?.chain?.is_evm) {
if (t?.chain?.type && isEvm(t?.chain?.type)) {
return equalIgnoreCase(w.chain.symbol, "evm")
}
return equalIgnoreCase(w.chain.symbol, t?.chain?.symbol ?? "")
Expand Down
23 changes: 13 additions & 10 deletions src/commands/vault/info/slash.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { CommandInteraction, Message } from "discord.js"
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"
import { composeEmbedMessage } from "ui/discord/embed"
import { GM_GITBOOK, SLASH_PREFIX } from "utils/constants"
import { SlashCommand } from "types/common"
import { runGetVaultDetail } from "./processor"
import config from "adapters/config"
import { MachineConfig, route } from "utils/router"
import {
renderListDepositAddress,
depositDetail,
renderListDepositAddress,
} from "commands/deposit/index/processor"
import { CommandInteraction, Message } from "discord.js"
import { SlashCommand } from "types/common"
import { composeEmbedMessage } from "ui/discord/embed"
import { chainTypes } from "utils/chain"
import { equalIgnoreCase } from "utils/common"
import { GM_GITBOOK, SLASH_PREFIX } from "utils/constants"
import { MachineConfig, route } from "utils/router"

import { SlashCommandSubcommandBuilder } from "@discordjs/builders"

import { runGetVaultDetail } from "./processor"

const machineConfig: MachineConfig = {
id: "vault-info",
Expand Down Expand Up @@ -89,15 +92,15 @@ const command: SlashCommand = {
address: context.deposit.evm,
decimal: 18,
chainId: 1,
isEVM: true,
chainType: chainTypes.EVM,
isNative: true,
},
{
symbol: "SOL",
address: context.deposit.sol,
decimal: 18,
chainId: 1,
isEVM: false,
chainType: chainTypes.SOL,
isNative: true,
},
]
Expand Down
28 changes: 28 additions & 0 deletions src/utils/chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export function isEvm(chainType: string): boolean {
return chainType === chainTypes.EVM
}

export function isSolana(chainType: string): boolean {
return chainType === chainTypes.SOL
}

export function isTon(chainType: string): boolean {
return chainType === chainTypes.TON
}

export function isBitcoin(chainType: string): boolean {
return chainType === chainTypes.BTC
}

export function isRonin(chainType: string): boolean {
return chainType === chainTypes.RON
}

// TODO: check other locations where change type is defined, replace by this
export const chainTypes = {
EVM: "evm",
SOL: "solana",
TON: "ton",
BTC: "bitcoin",
RON: "ronin",
}

0 comments on commit 6ecd39a

Please sign in to comment.