mirror of
https://github.com/Qortal/Q-Apps-Utils.git
synced 2025-01-30 14:52:18 +00:00
Added functions for getting wallet balance and user data
restructured project files to be easier to understand
This commit is contained in:
parent
c5adab5465
commit
808a6fa5d7
23
index.ts
23
index.ts
@ -1,10 +1,13 @@
|
||||
export * from "./src/Core/Interfaces";
|
||||
export * from "./src/Core/SendCoin";
|
||||
export * from "./src/Core/Types";
|
||||
export * from "./src/Core/API/Names";
|
||||
export * from "./src/Core/API/Transactions";
|
||||
export * from "./src/Numbers/Colors";
|
||||
export * from "./src/Numbers/NumberConversion";
|
||||
export * from "./src/Numbers/Numbers";
|
||||
export * from "./src/Numbers/StringNumbers";
|
||||
export * from "./src/Strings/printFunctions";
|
||||
export * from "./src/TypescriptUtils/Numbers/Colors";
|
||||
export * from "./src/TypescriptUtils/Numbers/NumberConversion";
|
||||
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/Types";
|
||||
|
||||
export * from "./src/QortalRequest/getFromAddress";
|
||||
export * from "./src/QortalRequest/getFromSelf";
|
||||
export * from "./src/QortalRequest/SendCoin";
|
||||
export * from "./src/QortalRequest/Transactions";
|
||||
|
69
package-lock.json
generated
69
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "qortal-app-utils",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "qortal-app-utils",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.11.1",
|
||||
"@emotion/styled": "^11.11.0",
|
||||
@ -22,7 +22,8 @@
|
||||
"react-intersection-observer": "^9.4.3",
|
||||
"react-quill": "^2.0.0",
|
||||
"react-rnd": "^10.4.1",
|
||||
"ts-key-enum": "^2.0.12"
|
||||
"ts-key-enum": "^2.0.12",
|
||||
"vite-tsconfig-paths": "^4.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.28",
|
||||
@ -1949,7 +1950,6 @@
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ms": "2.1.2"
|
||||
},
|
||||
@ -2050,7 +2050,7 @@
|
||||
"version": "0.18.20",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.20.tgz",
|
||||
"integrity": "sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"hasInstallScript": true,
|
||||
"bin": {
|
||||
"esbuild": "bin/esbuild"
|
||||
@ -2658,6 +2658,11 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/globrex": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz",
|
||||
"integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg=="
|
||||
},
|
||||
"node_modules/graphemer": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz",
|
||||
@ -3071,14 +3076,13 @@
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||
"dev": true
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"node_modules/nanoid": {
|
||||
"version": "3.3.6",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz",
|
||||
"integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
@ -3294,7 +3298,7 @@
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
|
||||
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==",
|
||||
"dev": true
|
||||
"devOptional": true
|
||||
},
|
||||
"node_modules/picomatch": {
|
||||
"version": "2.3.1",
|
||||
@ -3312,7 +3316,7 @@
|
||||
"version": "8.4.29",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.29.tgz",
|
||||
"integrity": "sha512-cbI+jaqIeu/VGqXEarWkRCCffhjgXc0qjBtXpqJhTBohMUjUQnbBr0xqX3vEKudc4iviTewcJo5ajcec5+wdJw==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "opencollective",
|
||||
@ -3646,7 +3650,7 @@
|
||||
"version": "3.28.1",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.28.1.tgz",
|
||||
"integrity": "sha512-R9OMQmIHJm9znrU3m3cpE8uhN0fGdXiawME7aZIpQqvpS/85+Vt1Hq1/yVIcYfOmaQiHjvXkQAoJukvLpau6Yw==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"bin": {
|
||||
"rollup": "dist/bin/rollup"
|
||||
},
|
||||
@ -3764,7 +3768,7 @@
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
|
||||
"integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
@ -3851,6 +3855,25 @@
|
||||
"resolved": "https://registry.npmjs.org/ts-key-enum/-/ts-key-enum-2.0.12.tgz",
|
||||
"integrity": "sha512-Ety4IvKMaeG34AyXMp5r11XiVZNDRL+XWxXbVVJjLvq2vxKRttEANBE7Za1bxCAZRdH2/sZT6jFyyTWxXz28hw=="
|
||||
},
|
||||
"node_modules/tsconfck": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/tsconfck/-/tsconfck-2.1.2.tgz",
|
||||
"integrity": "sha512-ghqN1b0puy3MhhviwO2kGF8SeMDNhEbnKxjK7h6+fvY9JAxqvXi8y5NAHSQv687OVboS2uZIByzGd45/YxrRHg==",
|
||||
"bin": {
|
||||
"tsconfck": "bin/tsconfck.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.13.1 || ^16 || >=18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^4.3.5 || ^5.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
|
||||
@ -3905,7 +3928,7 @@
|
||||
"version": "5.2.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
|
||||
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
@ -3962,7 +3985,7 @@
|
||||
"version": "4.4.9",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-4.4.9.tgz",
|
||||
"integrity": "sha512-2mbUn2LlUmNASWwSCNSJ/EG2HuSRTnVNaydp6vMCm5VIqJsjMfbIWtbH2kDuwUVW5mMUKKZvGPX/rqeqVvv1XA==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.18.10",
|
||||
"postcss": "^8.4.27",
|
||||
@ -4013,6 +4036,24 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/vite-tsconfig-paths": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/vite-tsconfig-paths/-/vite-tsconfig-paths-4.2.1.tgz",
|
||||
"integrity": "sha512-GNUI6ZgPqT3oervkvzU+qtys83+75N/OuDaQl7HmOqFTb0pjZsuARrRipsyJhJ3enqV8beI1xhGbToR4o78nSQ==",
|
||||
"dependencies": {
|
||||
"debug": "^4.1.1",
|
||||
"globrex": "^0.1.2",
|
||||
"tsconfck": "^2.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"vite": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
|
@ -36,7 +36,8 @@
|
||||
"react-intersection-observer": "^9.4.3",
|
||||
"react-quill": "^2.0.0",
|
||||
"react-rnd": "^10.4.1",
|
||||
"ts-key-enum": "^2.0.12"
|
||||
"ts-key-enum": "^2.0.12",
|
||||
"vite-tsconfig-paths": "^4.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.28",
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { CoinType } from "./Utils/Types";
|
||||
|
||||
export const sendCoin = async (
|
||||
address: string,
|
||||
amount: number,
|
||||
coin: string
|
||||
coin: CoinType
|
||||
) => {
|
||||
return qortalRequest({
|
||||
action: "SEND_COIN",
|
@ -1,7 +1,7 @@
|
||||
import {
|
||||
SearchTransactionResponse,
|
||||
TransactionSearchParams,
|
||||
} from "../Interfaces";
|
||||
} from "./Utils/Interfaces";
|
||||
|
||||
export const searchTransactions = async (params: TransactionSearchParams) => {
|
||||
return (await qortalRequest({
|
@ -1,4 +1,4 @@
|
||||
import { ConfirmationStatus, TransactionType } from ".//Types";
|
||||
import { ConfirmationStatus, TransactionType } from "./Types";
|
||||
|
||||
export interface GetRequestData {
|
||||
limit?: number;
|
@ -41,3 +41,5 @@ export type TransactionType =
|
||||
| "ACCOUNT_LEVEL"
|
||||
| "TRANSFER_PRIVS"
|
||||
| "PRESENCE";
|
||||
|
||||
export type CoinType = "QORT" | "BTC" | "LTC" | "DOGE" | "DGB" | "RVN" | "ARRR";
|
@ -1,5 +1,5 @@
|
||||
import { stringIsEmpty } from "../../Numbers/StringNumbers";
|
||||
import { GetRequestData } from "../Interfaces";
|
||||
import { stringIsEmpty } from "../TypescriptUtils/Numbers/StringNumbers";
|
||||
import { GetRequestData } from "./Utils/Interfaces";
|
||||
type AccountName = { name: string; owner: string };
|
||||
|
||||
export const getAccountNames = async (
|
||||
@ -19,3 +19,10 @@ export const getAccountNames = async (
|
||||
|
||||
return emptyNamesFilled.length > 0 ? emptyNamesFilled : [namelessAddress];
|
||||
};
|
||||
|
||||
export const getBalance = async (address: string) => {
|
||||
return (await qortalRequest({
|
||||
action: "GET_BALANCE",
|
||||
address,
|
||||
})) as number;
|
||||
};
|
22
src/QortalRequest/getFromSelf.ts
Normal file
22
src/QortalRequest/getFromSelf.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { getBalance } from "./getFromAddress";
|
||||
import { CoinType } from "./Utils/Types";
|
||||
|
||||
export const getWalletBalance = async (coin: CoinType) => {
|
||||
return (await qortalRequest({
|
||||
action: "GET_WALLET_BALANCE",
|
||||
coin,
|
||||
})) as number;
|
||||
};
|
||||
|
||||
export const getUserBalance = async () => {
|
||||
const accountInfo = await getUserAccount();
|
||||
return (await getBalance(accountInfo.address)) as number;
|
||||
};
|
||||
|
||||
export type AccountInfo = { address: string; publicKey: string };
|
||||
|
||||
export const getUserAccount = async () => {
|
||||
return (await qortalRequest({
|
||||
action: "GET_USER_ACCOUNT",
|
||||
})) as AccountInfo;
|
||||
};
|
2
src/global.d.ts
vendored
2
src/global.d.ts
vendored
@ -89,4 +89,4 @@ interface QortalRequestOptions {
|
||||
txGroupId?: number;
|
||||
}
|
||||
|
||||
declare function qortalRequest(options: QortalRequestOptions): Promise<object>;
|
||||
declare function qortalRequest(options: QortalRequestOptions): Promise<any>;
|
||||
|
@ -2,7 +2,11 @@
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"lib": [
|
||||
"DOM",
|
||||
"DOM.Iterable",
|
||||
"ESNext"
|
||||
],
|
||||
"skipLibCheck": true,
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
@ -26,6 +30,12 @@
|
||||
"esm": true
|
||||
},
|
||||
"experimentalSpecifierResolution": "node",
|
||||
"include": ["src/**/*"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
],
|
||||
"baseUrl": "./src",
|
||||
"include": ["src/**/*"],
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { resolve } from "path";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
build: {
|
||||
@ -10,5 +11,4 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
plugins: [react()],
|
||||
base: "",
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user