mirror of
https://github.com/Qortal/Q-Apps-Utils.git
synced 2025-01-28 22:02:18 +00:00
Added qortalRequest functions
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 blocks
This commit is contained in:
parent
33f75721fe
commit
1ffbd743c5
@ -10,5 +10,6 @@ module.exports = {
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'react-refresh/only-export-components': 'warn',
|
||||
'@typescript-eslint/no-explicit-any': 0,
|
||||
},
|
||||
}
|
||||
|
4
.npmignore
Normal file
4
.npmignore
Normal file
@ -0,0 +1,4 @@
|
||||
/.idea
|
||||
.gitignore
|
||||
Empty Q-App.zip
|
||||
|
16
index.d.ts
vendored
Normal file
16
index.d.ts
vendored
Normal file
@ -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"
|
5
index.ts
5
index.ts
@ -4,10 +4,13 @@ export * from "./src/TypescriptUtils/Numbers/Numbers";
|
||||
export * from "./src/TypescriptUtils/Numbers/StringNumbers";
|
||||
export * from "./src/TypescriptUtils/Strings/printFunctions";
|
||||
|
||||
export * from "./src/QortalRequest/Utils/Interfaces";
|
||||
export * from "./src/QortalRequest/Utils/Interfaces/Responses";
|
||||
export * from "./src/QortalRequest/Utils/Interfaces/Parameters";
|
||||
export * from "./src/QortalRequest/Utils/Types";
|
||||
|
||||
export * from "./src/QortalRequest/getFromAddress";
|
||||
export * from "./src/QortalRequest/getFromSelf";
|
||||
export * from "./src/QortalRequest/setFromSelf";
|
||||
export * from "./src/QortalRequest/SendCoin";
|
||||
export * from "./src/QortalRequest/Transactions";
|
||||
export * from "./src/QortalRequest/general";
|
||||
|
778
package-lock.json
generated
778
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "qortal-app-utils",
|
||||
"version": "1.2.0",
|
||||
"version": "1.4.0",
|
||||
"description": "A series of convenience functions that perform common tasks, especially those that interact with the Qortal blockchain",
|
||||
"keywords": [
|
||||
"Qortal",
|
||||
@ -37,6 +37,7 @@
|
||||
"react-quill": "^2.0.0",
|
||||
"react-rnd": "^10.4.1",
|
||||
"ts-key-enum": "^2.0.12",
|
||||
"vite-plugin-dts": "^3.6.2",
|
||||
"vite-tsconfig-paths": "^4.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -44,12 +45,12 @@
|
||||
"@types/react-dom": "^18.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"@vitejs/plugin-react": "^4.0.0",
|
||||
"@vitejs/plugin-react": "^4.2.0",
|
||||
"eslint": "^8.51.0",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.3.4",
|
||||
"prettier": "^3.0.3",
|
||||
"typescript": "^5.0.2",
|
||||
"vite": "^4.3.2"
|
||||
"vite": "^4.5.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
import {
|
||||
SearchTransactionResponse,
|
||||
TransactionSearchParams,
|
||||
} from "./Utils/Interfaces";
|
||||
import { SearchTransactionResponse } from "./Utils/Interfaces/Responses.ts";
|
||||
import { TransactionSearchParams } from "./Utils/Interfaces/Parameters.ts";
|
||||
|
||||
export const searchTransactions = async (params: TransactionSearchParams) => {
|
||||
return (await qortalRequest({
|
||||
|
@ -1,35 +1,10 @@
|
||||
import { ConfirmationStatus, TransactionType } from "./Types";
|
||||
import { ConfirmationStatus, TransactionType } from "../Types.ts";
|
||||
|
||||
export interface GetRequestData {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
reverse?: boolean;
|
||||
}
|
||||
|
||||
export interface TransactionSearchParams extends GetRequestData {
|
||||
startBlock?: number;
|
||||
blockLimit?: number;
|
||||
txGroupId?: number;
|
||||
txType: TransactionType[];
|
||||
address: string;
|
||||
confirmationStatus: ConfirmationStatus;
|
||||
}
|
||||
|
||||
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 QortalRequestOptions {
|
||||
action: string;
|
||||
name?: string;
|
||||
@ -77,3 +52,11 @@ export interface QortalRequestOptions {
|
||||
blockLimit?: number;
|
||||
txGroupId?: number;
|
||||
}
|
||||
export interface TransactionSearchParams extends GetRequestData {
|
||||
startBlock?: number;
|
||||
blockLimit?: number;
|
||||
txGroupId?: number;
|
||||
txType: TransactionType[];
|
||||
address: string;
|
||||
confirmationStatus: ConfirmationStatus;
|
||||
}
|
35
src/QortalRequest/Utils/Interfaces/Responses.ts
Normal file
35
src/QortalRequest/Utils/Interfaces/Responses.ts
Normal file
@ -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;
|
||||
}
|
@ -43,3 +43,11 @@ export type TransactionType =
|
||||
| "PRESENCE";
|
||||
|
||||
export type CoinType = "QORT" | "BTC" | "LTC" | "DOGE" | "DGB" | "RVN" | "ARRR";
|
||||
|
||||
export type BlockchainType =
|
||||
| "BITCOIN"
|
||||
| "LITECOIN"
|
||||
| "DODGECOIN"
|
||||
| "DIGIBYTE"
|
||||
| "RAVENCOIN"
|
||||
| "PIRATECHAIN";
|
||||
|
47
src/QortalRequest/general.ts
Normal file
47
src/QortalRequest/general.ts
Normal file
@ -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;
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
import { stringIsEmpty } from "../TypescriptUtils/Numbers/StringNumbers";
|
||||
import { GetRequestData } from "./Utils/Interfaces";
|
||||
import { GetRequestData } from "./Utils/Interfaces/Parameters.ts";
|
||||
type AccountName = { name: string; owner: string };
|
||||
|
||||
export const getAccountNames = async (
|
||||
|
@ -15,8 +15,22 @@ export const getUserBalance = async () => {
|
||||
|
||||
export type AccountInfo = { address: string; publicKey: string };
|
||||
|
||||
export const getForeignWallet = async (coin: CoinType) => {
|
||||
return (await qortalRequest({
|
||||
action: "GET_USER_WALLET",
|
||||
coin,
|
||||
})) as AccountInfo;
|
||||
};
|
||||
export const getUserAccount = async () => {
|
||||
return (await qortalRequest({
|
||||
action: "GET_USER_ACCOUNT",
|
||||
})) as AccountInfo;
|
||||
};
|
||||
|
||||
// returns {error: "Cannot find requested data"} if data isn't found
|
||||
export const getProfileData = async (property: string) => {
|
||||
return (await qortalRequest({
|
||||
action: "GET_PROFILE_DATA",
|
||||
property,
|
||||
})) as string | object;
|
||||
};
|
||||
|
12
src/QortalRequest/setFromSelf.ts
Normal file
12
src/QortalRequest/setFromSelf.ts
Normal file
@ -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;
|
||||
};
|
14
src/global.d.ts
vendored
14
src/global.d.ts
vendored
@ -1,3 +1,11 @@
|
||||
type BlockchainType =
|
||||
| "BITCOIN"
|
||||
| "LITECOIN"
|
||||
| "DODGECOIN"
|
||||
| "DIGIBYTE"
|
||||
| "RAVENCOIN"
|
||||
| "PIRATECHAIN";
|
||||
|
||||
type TransactionType =
|
||||
| "GENESIS"
|
||||
| "PAYMENT"
|
||||
@ -87,6 +95,10 @@ interface QortalRequestOptions {
|
||||
startBlock?: number;
|
||||
blockLimit?: number;
|
||||
txGroupId?: number;
|
||||
blockchain?: BlockChainType;
|
||||
maxTrades?: number;
|
||||
inverse?: boolean;
|
||||
property?: string;
|
||||
data?: { customData: object };
|
||||
}
|
||||
|
||||
declare function qortalRequest(options: QortalRequestOptions): Promise<any>;
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"lib": [
|
||||
@ -7,11 +8,14 @@
|
||||
"DOM.Iterable",
|
||||
"ESNext"
|
||||
],
|
||||
"skipLibCheck": true,
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"declaration": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "Node",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
@ -20,7 +24,7 @@
|
||||
"jsx": "react-jsx",
|
||||
"noImplicitAny": false,
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
@ -35,7 +39,6 @@
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
],
|
||||
"baseUrl": "./src",
|
||||
"include": ["src/**/*"],
|
||||
"include": ["src"],
|
||||
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { resolve } from "path";
|
||||
import dts from "vite-plugin-dts";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
optimizeDeps: { include: ["src"] },
|
||||
build: {
|
||||
lib: {
|
||||
entry: resolve(__dirname, "index.ts"),
|
||||
name: "QortalUtils",
|
||||
formats: ["es"],
|
||||
},
|
||||
},
|
||||
plugins: [react()],
|
||||
plugins: [react(), dts()],
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user