mirror of https://github.com/Qortal/Q-Apps-Utils
Browse Source
restructured project files to be easier to understand Vite dts plugin is used to provide type support Added functions for the following: Getting wallet balance Getting/setting profile data Sending all supported coins Getting day summary Getting the price ratio between QORT and all supported coins Conversions from blocks to time and time to blockspull/1/head
Qortal Dev
10 months ago
17 changed files with 814 additions and 189 deletions
@ -0,0 +1,16 @@ |
|||||||
|
export * from "./dist/src/TypescriptUtils/Numbers/Colors"; |
||||||
|
export * from "./dist/src/TypescriptUtils/Numbers/NumberConversion"; |
||||||
|
export * from "./dist/src/TypescriptUtils/Numbers/Numbers"; |
||||||
|
export * from "./dist/src/TypescriptUtils/Numbers/StringNumbers"; |
||||||
|
export * from "./dist/src/TypescriptUtils/Strings/printFunctions"; |
||||||
|
|
||||||
|
export * from "./dist/src/QortalRequest/Utils/Interfaces/Responses"; |
||||||
|
export * from "./dist/src/QortalRequest/Utils/Interfaces/Parameters"; |
||||||
|
export * from "./dist/src/QortalRequest/Utils/Types"; |
||||||
|
|
||||||
|
export * from "./dist/src/QortalRequest/getFromAddress"; |
||||||
|
export * from "./dist/src/QortalRequest/getFromSelf"; |
||||||
|
export * from "./dist/src/QortalRequest/setFromSelf"; |
||||||
|
export * from "./dist/src/QortalRequest/SendCoin"; |
||||||
|
export * from "./dist/src/QortalRequest/Transactions"; |
||||||
|
export * from "./dist/src/QortalRequest/general" |
@ -0,0 +1,35 @@ |
|||||||
|
export interface SearchTransactionResponse { |
||||||
|
type: string; |
||||||
|
timestamp: number; |
||||||
|
reference: string; |
||||||
|
fee: string; |
||||||
|
signature: string; |
||||||
|
txGroupId: number; |
||||||
|
blockHeight: number; |
||||||
|
approvalStatus: string; |
||||||
|
creatorAddress: string; |
||||||
|
senderPublicKey: string; |
||||||
|
recipient: string; |
||||||
|
amount: string; |
||||||
|
} |
||||||
|
|
||||||
|
export interface SummaryTransactionCounts { |
||||||
|
arbitrary: number; |
||||||
|
AT: number; |
||||||
|
deployAt: number; |
||||||
|
groupInvite: number; |
||||||
|
joinGroup: number; |
||||||
|
message: number; |
||||||
|
payment: number; |
||||||
|
registerName: number; |
||||||
|
rewardShare: number; |
||||||
|
updateName: number; |
||||||
|
voteOnPoll: number; |
||||||
|
} |
||||||
|
export interface DaySummaryResponse { |
||||||
|
assetsIssued: number; |
||||||
|
blockCount: number; |
||||||
|
namesRegistered: number; |
||||||
|
totalTransactionCount: number; |
||||||
|
transactionCountByType: SummaryTransactionCounts; |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
import { DaySummaryResponse } from "./Utils/Interfaces/Responses.ts"; |
||||||
|
import { BlockchainType } from "./Utils/Types.ts"; |
||||||
|
import { truncateNumber } from "../TypescriptUtils/Numbers/StringNumbers.ts"; |
||||||
|
|
||||||
|
export const getDaySummary = async () => { |
||||||
|
return (await qortalRequest({ |
||||||
|
action: "GET_DAY_SUMMARY", |
||||||
|
})) as DaySummaryResponse; |
||||||
|
}; |
||||||
|
|
||||||
|
export const getBlocksInDuration = async (minutes: number) => { |
||||||
|
return getDaySummary().then(response => { |
||||||
|
const minutesPerDay = 60 * 24; |
||||||
|
const blocksPerMinute = response.blockCount / minutesPerDay; |
||||||
|
const blocksInDuration = minutes * blocksPerMinute; |
||||||
|
return +truncateNumber(Math.abs(blocksInDuration), 0); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
export type DayTime = { days: number; hours: number; minutes: number }; |
||||||
|
export const getDurationFromBlocks = async (blocks: number) => { |
||||||
|
return getDaySummary().then(response => { |
||||||
|
const minutesPerDay = 60 * 24; |
||||||
|
const blocksPerMinute = response.blockCount / minutesPerDay; |
||||||
|
const duration = blocks / blocksPerMinute; |
||||||
|
|
||||||
|
const days = Math.floor(duration / minutesPerDay); |
||||||
|
const hours = Math.floor((duration % minutesPerDay) / 60); |
||||||
|
const minutes = Math.floor(duration % 60); |
||||||
|
|
||||||
|
return { days, hours, minutes } as DayTime; |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
export const getPrice = async ( |
||||||
|
blockchainName: BlockchainType, |
||||||
|
tradesToInclude = 10, |
||||||
|
isQortRatio = true |
||||||
|
) => { |
||||||
|
const response = (await qortalRequest({ |
||||||
|
action: "GET_PRICE", |
||||||
|
blockchain: blockchainName, |
||||||
|
maxTrades: tradesToInclude, |
||||||
|
inverse: isQortRatio, |
||||||
|
})) as number; |
||||||
|
return response / 1e8; |
||||||
|
}; |
@ -0,0 +1,12 @@ |
|||||||
|
export const setProfileData = async ( |
||||||
|
property: string, |
||||||
|
data: object, |
||||||
|
encrypt = false |
||||||
|
) => { |
||||||
|
if (encrypt) property += "-private"; |
||||||
|
return (await qortalRequest({ |
||||||
|
action: "SET_PROFILE_DATA", |
||||||
|
property, |
||||||
|
data: { customData: data }, |
||||||
|
})) as string; |
||||||
|
}; |
@ -1,14 +1,16 @@ |
|||||||
import { defineConfig } from "vite"; |
import { defineConfig } from "vite"; |
||||||
import react from "@vitejs/plugin-react"; |
import react from "@vitejs/plugin-react"; |
||||||
import { resolve } from "path"; |
import { resolve } from "path"; |
||||||
|
import dts from "vite-plugin-dts"; |
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({ |
export default defineConfig({ |
||||||
|
optimizeDeps: { include: ["src"] }, |
||||||
build: { |
build: { |
||||||
lib: { |
lib: { |
||||||
entry: resolve(__dirname, "index.ts"), |
entry: resolve(__dirname, "index.ts"), |
||||||
name: "QortalUtils", |
formats: ["es"], |
||||||
}, |
}, |
||||||
}, |
}, |
||||||
plugins: [react()], |
plugins: [react(), dts()], |
||||||
}); |
}); |
||||||
|
Loading…
Reference in new issue