Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
chiliec committed Sep 15, 2024
1 parent ec3b306 commit da13dd0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/bot/features/admin/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { randomAttributes } from "#root/bot/helpers/attributes.js"
import { countUsers, findUserById } from "#root/bot/models/user.js"
import { ChatGPTAPI } from "chatgpt"
import { logger } from "#root/logger"
import { sleep } from "#root/bot/helpers/ton"
import { sleep } from "#root/bot/helpers/time.js"
import {
adminIndex,
sendPostToChannels,
Expand Down
3 changes: 1 addition & 2 deletions src/bot/features/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Composer, InlineKeyboard } from "grammy"
import type { Context } from "#root/bot/context.js"
import { logHandle } from "#root/bot/helpers/logging.js"
import { logger } from "#root/logger"
import { sleep } from "#root/bot/helpers/ton.js"
import { timeUnitsBetween } from "#root/bot/helpers/time.js"
import { sleep, timeUnitsBetween } from "#root/bot/helpers/time.js"
import { sendMessageToAdmins, sendPlaceInLine } from "#root/bot/helpers/telegram.js"
import { UserState, addPoints } from "#root/bot/models/user.js"
import { generateRandomString } from "#root/bot/helpers/text.js"
Expand Down
2 changes: 1 addition & 1 deletion src/bot/helpers/account-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/* eslint-disable no-param-reassign */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { logger } from "#root/logger"
import { sleep } from "#root/bot/helpers/ton"
import TonWeb from "tonweb"
import { sleep } from "#root/bot/helpers/time.js"

export class AccountSubscription {
tonweb: TonWeb
Expand Down
3 changes: 2 additions & 1 deletion src/bot/helpers/nft-collection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Address, Cell, internal, beginCell, contractAddress, StateInit, SendMode } from "@ton/core"
import { encodeOffChainContent, sleep, tonClient } from "#root/bot/helpers/ton.js"
import { encodeOffChainContent, tonClient } from "#root/bot/helpers/ton.js"
import { config } from "#root/config.js"
import { logger } from "#root/logger"
import { OpenedWallet } from "#root/bot/helpers/wallet.js"
import { sleep } from "#root/bot/helpers/time.js"

export type collectionData = {
ownerAddress: Address
Expand Down
3 changes: 2 additions & 1 deletion src/bot/helpers/nft-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { OpenedWallet } from "#root/bot/helpers/wallet.js"
import { config } from "#root/config.js"
import { logger } from "#root/logger.js"
import { NftCollection } from "#root/bot/helpers/nft-collection.js"
import { openWallet, sleep, waitSeqno } from "#root/bot/helpers/ton.js"
import { openWallet, waitSeqno } from "#root/bot/helpers/ton.js"
import { sleep } from "./time"

export type NFTMintParameters = {
queryId: number
Expand Down
6 changes: 6 additions & 0 deletions src/bot/helpers/time.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export function sleep(ms: number): Promise<void> {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}

export function timeUnitsBetween(startDate: Date, endDate: Date) {
let delta = Math.abs(endDate.getTime() - startDate.getTime()) / 1000
const isNegative = startDate > endDate ? -1 : 1
Expand Down
7 changes: 1 addition & 6 deletions src/bot/helpers/ton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { mnemonicToPrivateKey } from "@ton/crypto"
import { Address, beginCell, Cell, internal, SendMode, TonClient, WalletContractV4 } from "@ton/ton"
import { config } from "#root/config.js"
import { OpenedWallet } from "./wallet"
import { sleep } from "./time"

const toncenterBaseEndpoint: string = config.TESTNET
? "https://testnet.toncenter.com"
Expand Down Expand Up @@ -108,12 +109,6 @@ export async function waitSeqno(seqno: number, wallet: OpenedWallet, maxAttempts
throw new Error(`Seqno wait failed. Check https://tonviewer.com/${config.COLLECTION_OWNER}`)
}

export function sleep(ms: number): Promise<void> {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}

const stopList = new Set([
"EQA2JYPGPywx6Sn590nUd06B2HgOkFvJ-cCnTO6yTEdacbUG", // @wallet
"UQBX63RAdgShn34EAFMV73Cut7Z15lUZd1hnVva68SEl7pGn", // MEXC
Expand Down
8 changes: 2 additions & 6 deletions src/frontend/src/components/CNFT.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { useUserStore } from "../stores/userStore.js";
import { Address, Cell, beginCell } from "@ton/core";
import { TonConnectUI } from "@tonconnect/ui";
import { ElLoading, ElMessage } from "element-plus";
import { sleep } from "../../../bot/helpers/time";
const loadingInstance = ElLoading.service({ fullscreen: true, visible: false });
Expand Down Expand Up @@ -72,17 +73,12 @@ onMounted(async () => {
loadingInstance.visible.value = true;
try {
await parseNftData(hexAddress);
loadingInstance.visible.value = false;
} catch (error) {
await showError(error);
}
});
function sleep(ms: number): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function tapButton() {
if (cnftExists.value) {
if (!cnftAddress) {
Expand Down

0 comments on commit da13dd0

Please sign in to comment.