mirror of
https://github.com/Qortal/Q-Apps-Utils.git
synced 2025-01-30 06:42:19 +00:00
First Commit
This commit is contained in:
commit
6a971fbfdb
BIN
Empty Q-App.zip
Normal file
BIN
Empty Q-App.zip
Normal file
Binary file not shown.
7
Numbers/Colors.ts
Normal file
7
Numbers/Colors.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import * as colorsys from "colorsys";
|
||||||
|
|
||||||
|
export const changeLightness = (hexColor: string, amount: number) => {
|
||||||
|
const hsl = colorsys.hex2Hsl(hexColor);
|
||||||
|
hsl.l += amount;
|
||||||
|
return colorsys.hsl2Hex(hsl);
|
||||||
|
};
|
18
Numbers/NumberConversion.ts
Normal file
18
Numbers/NumberConversion.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
export function uint8ArrayToBase64(byteArray: Uint8Array): string {
|
||||||
|
const chars: string[] = Array.from(byteArray).map(byte =>
|
||||||
|
String.fromCharCode(byte)
|
||||||
|
);
|
||||||
|
return btoa(chars.join(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function base64ToUint8Array(base64) {
|
||||||
|
const binary_string = atob(base64);
|
||||||
|
const len = binary_string.length;
|
||||||
|
const bytes = new Uint8Array(len);
|
||||||
|
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
bytes[i] = binary_string.charCodeAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
9
Numbers/Numbers.ts
Normal file
9
Numbers/Numbers.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export const setNumberWithinBounds = (
|
||||||
|
num: number,
|
||||||
|
minValue: number,
|
||||||
|
maxValue: number
|
||||||
|
) => {
|
||||||
|
if (num > maxValue) return maxValue;
|
||||||
|
if (num < minValue) return minValue;
|
||||||
|
return num;
|
||||||
|
};
|
56
Numbers/StringNumbers.ts
Normal file
56
Numbers/StringNumbers.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
export const isIntegerNum = /^-?[0-9]+$/;
|
||||||
|
export const isFloatNum = /^-?[0-9]*\.?[0-9]*$/;
|
||||||
|
export const isAllZerosNum = /^0*\.?0*$/;
|
||||||
|
|
||||||
|
export const getSigDigits = (number: string) => {
|
||||||
|
if (isIntegerNum.test(number)) return 0;
|
||||||
|
const decimalSplit = number.split(".");
|
||||||
|
return decimalSplit[decimalSplit.length - 1].length;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sigDigitsExceeded = (number: string, sigDigits: number) => {
|
||||||
|
return getSigDigits(number) > sigDigits;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const removeTrailingZeros = (s: string) => {
|
||||||
|
return Number(s).toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mathOnStringNumbers = (
|
||||||
|
s1: string,
|
||||||
|
s2: string,
|
||||||
|
operation: (n1: number, n2: number) => number
|
||||||
|
) => {
|
||||||
|
const n1 = Number(s1);
|
||||||
|
const n2 = Number(s2);
|
||||||
|
if (isNaN(n1) || isNaN(n2)) throw TypeError("String is not a Number!");
|
||||||
|
return operation(n1, n2).toString();
|
||||||
|
};
|
||||||
|
export const addStringNumbers = (s1: string, s2: string) => {
|
||||||
|
return mathOnStringNumbers(s1, s2, (n1, n2) => {
|
||||||
|
return n1 + n2;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const stringIsEmpty = (value: string) => {
|
||||||
|
return value === "";
|
||||||
|
};
|
||||||
|
|
||||||
|
export const stringIsNaN = (value: string) => {
|
||||||
|
return Number.isNaN(Number(value));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const stringIsNumber = (value: string) => {
|
||||||
|
return !stringIsNaN(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const toNumber = (value: string | number) => {
|
||||||
|
return Number(value);
|
||||||
|
};
|
||||||
|
export const toString = (value: string | number) => {
|
||||||
|
return value.toString();
|
||||||
|
};
|
||||||
|
export const truncateNumber = (value: string | number, sigDigits: number) => {
|
||||||
|
const valueNum = toNumber(value);
|
||||||
|
return valueNum.toFixed(sigDigits);
|
||||||
|
};
|
14
QortalCore/Fetch.ts
Normal file
14
QortalCore/Fetch.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const assembleURLParams = (params: object) => {
|
||||||
|
let finalUrl = "";
|
||||||
|
const urls: string[] = [];
|
||||||
|
|
||||||
|
Object.entries(params).map(([key, value]) => {
|
||||||
|
urls.push(`${key}=${value.toString()}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
urls.map((url, index) => {
|
||||||
|
if (index > 0) finalUrl += "&";
|
||||||
|
finalUrl += url;
|
||||||
|
});
|
||||||
|
return finalUrl;
|
||||||
|
};
|
79
QortalCore/Interfaces.ts
Normal file
79
QortalCore/Interfaces.ts
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import { ConfirmationStatus, TransactionType } from "./Types";
|
||||||
|
|
||||||
|
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;
|
||||||
|
service?: string;
|
||||||
|
data64?: string;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
category?: string;
|
||||||
|
tags?: string[] | string;
|
||||||
|
identifier?: string;
|
||||||
|
address?: string;
|
||||||
|
metaData?: string;
|
||||||
|
encoding?: string;
|
||||||
|
includeMetadata?: boolean;
|
||||||
|
limit?: number;
|
||||||
|
offset?: number;
|
||||||
|
reverse?: boolean;
|
||||||
|
resources?: any[];
|
||||||
|
filename?: string;
|
||||||
|
list_name?: string;
|
||||||
|
item?: string;
|
||||||
|
items?: string[];
|
||||||
|
tag1?: string;
|
||||||
|
tag2?: string;
|
||||||
|
tag3?: string;
|
||||||
|
tag4?: string;
|
||||||
|
tag5?: string;
|
||||||
|
coin?: string;
|
||||||
|
destinationAddress?: string;
|
||||||
|
amount?: number;
|
||||||
|
blob?: Blob;
|
||||||
|
mimeType?: string;
|
||||||
|
file?: File;
|
||||||
|
encryptedData?: string;
|
||||||
|
mode?: string;
|
||||||
|
query?: string;
|
||||||
|
excludeBlocked?: boolean;
|
||||||
|
exactMatchNames?: boolean;
|
||||||
|
creationBytes?: string;
|
||||||
|
type?: string;
|
||||||
|
assetId?: number;
|
||||||
|
txType?: TransactionType[];
|
||||||
|
confirmationStatus?: string;
|
||||||
|
startBlock?: number;
|
||||||
|
blockLimit?: number;
|
||||||
|
txGroupId?: number;
|
||||||
|
}
|
33
QortalCore/QortalRequest.ts
Normal file
33
QortalCore/QortalRequest.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import {
|
||||||
|
GetRequestData,
|
||||||
|
SearchTransactionResponse,
|
||||||
|
TransactionSearchParams,
|
||||||
|
} from "./Interfaces";
|
||||||
|
import { stringIsEmpty } from "../Numbers/StringNumbers";
|
||||||
|
|
||||||
|
export const searchTransactions = async (params: TransactionSearchParams) => {
|
||||||
|
return (await qortalRequest({
|
||||||
|
action: "SEARCH_TRANSACTIONS",
|
||||||
|
...params,
|
||||||
|
})) as SearchTransactionResponse[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type AccountName = { name: string; owner: string };
|
||||||
|
|
||||||
|
export const getAccountNames = async (
|
||||||
|
address: string,
|
||||||
|
params?: GetRequestData
|
||||||
|
) => {
|
||||||
|
const names = (await qortalRequest({
|
||||||
|
action: "GET_ACCOUNT_NAMES",
|
||||||
|
address,
|
||||||
|
...params,
|
||||||
|
})) as AccountName[];
|
||||||
|
|
||||||
|
const namelessAddress = { name: "", owner: address };
|
||||||
|
const emptyNamesFilled = names.map(({ name, owner }) => {
|
||||||
|
return stringIsEmpty(name) ? namelessAddress : { name, owner };
|
||||||
|
});
|
||||||
|
|
||||||
|
return emptyNamesFilled.length > 0 ? emptyNamesFilled : [namelessAddress];
|
||||||
|
};
|
40
QortalCore/SendCoin.ts
Normal file
40
QortalCore/SendCoin.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
export const sendCoin = async (
|
||||||
|
address: string,
|
||||||
|
amount: number,
|
||||||
|
coin: string
|
||||||
|
) => {
|
||||||
|
return qortalRequest({
|
||||||
|
action: "SEND_COIN",
|
||||||
|
coin,
|
||||||
|
destinationAddress: address,
|
||||||
|
amount,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendQORT = async (address: string, amount: number) => {
|
||||||
|
return await sendCoin(address, amount, "QORT");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendBitCoin = async (address: string, amount: number) => {
|
||||||
|
return await sendCoin(address, amount, "BTC");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendLiteCoin = async (address: string, amount: number) => {
|
||||||
|
return await sendCoin(address, amount, "LTC");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendDogeCoin = async (address: string, amount: number) => {
|
||||||
|
return await sendCoin(address, amount, "DOGE");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendDigiByte = async (address: string, amount: number) => {
|
||||||
|
return await sendCoin(address, amount, "DGB");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendRavenCoin = async (address: string, amount: number) => {
|
||||||
|
return await sendCoin(address, amount, "RVN");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendPirateChain = async (address: string, amount: number) => {
|
||||||
|
return await sendCoin(address, amount, "ARRR");
|
||||||
|
};
|
43
QortalCore/Types.ts
Normal file
43
QortalCore/Types.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
export type ConfirmationStatus = "CONFIRMED" | "UNCONFIRMED" | "BOTH";
|
||||||
|
export type TransactionType =
|
||||||
|
| "GENESIS"
|
||||||
|
| "PAYMENT"
|
||||||
|
| "REGISTER_NAME"
|
||||||
|
| "UPDATE_NAME"
|
||||||
|
| "SELL_NAME"
|
||||||
|
| "CANCEL_SELL_NAME"
|
||||||
|
| "BUY_NAME"
|
||||||
|
| "CREATE_POLL"
|
||||||
|
| "VOTE_ON_POLL"
|
||||||
|
| "ARBITRARY"
|
||||||
|
| "ISSUE_ASSET"
|
||||||
|
| "TRANSFER_ASSET"
|
||||||
|
| "CREATE_ASSET_ORDER"
|
||||||
|
| "CANCEL_ASSET_ORDER"
|
||||||
|
| "MULTI_PAYMENT"
|
||||||
|
| "DEPLOY_AT"
|
||||||
|
| "MESSAGE"
|
||||||
|
| "CHAT"
|
||||||
|
| "PUBLICIZE"
|
||||||
|
| "AIRDROP"
|
||||||
|
| "AT"
|
||||||
|
| "CREATE_GROUP"
|
||||||
|
| "UPDATE_GROUP"
|
||||||
|
| "ADD_GROUP_ADMIN"
|
||||||
|
| "REMOVE_GROUP_ADMIN"
|
||||||
|
| "GROUP_BAN"
|
||||||
|
| "CANCEL_GROUP_BAN"
|
||||||
|
| "GROUP_KICK"
|
||||||
|
| "GROUP_INVITE"
|
||||||
|
| "CANCEL_GROUP_INVITE"
|
||||||
|
| "JOIN_GROUP"
|
||||||
|
| "LEAVE_GROUP"
|
||||||
|
| "GROUP_APPROVAL"
|
||||||
|
| "SET_GROUP"
|
||||||
|
| "UPDATE_ASSET"
|
||||||
|
| "ACCOUNT_FLAGS"
|
||||||
|
| "ENABLE_FORGING"
|
||||||
|
| "REWARD_SHARE"
|
||||||
|
| "ACCOUNT_LEVEL"
|
||||||
|
| "TRANSFER_PRIVS"
|
||||||
|
| "PRESENCE";
|
4
Strings/printFunctions.ts
Normal file
4
Strings/printFunctions.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export const printVar = (variable: object) => {
|
||||||
|
const [key, value] = Object.entries(variable)[0];
|
||||||
|
console.log(key, " is: ", value);
|
||||||
|
};
|
92
global.d.ts
vendored
Normal file
92
global.d.ts
vendored
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
type TransactionType =
|
||||||
|
| "GENESIS"
|
||||||
|
| "PAYMENT"
|
||||||
|
| "REGISTER_NAME"
|
||||||
|
| "UPDATE_NAME"
|
||||||
|
| "SELL_NAME"
|
||||||
|
| "CANCEL_SELL_NAME"
|
||||||
|
| "BUY_NAME"
|
||||||
|
| "CREATE_POLL"
|
||||||
|
| "VOTE_ON_POLL"
|
||||||
|
| "ARBITRARY"
|
||||||
|
| "ISSUE_ASSET"
|
||||||
|
| "TRANSFER_ASSET"
|
||||||
|
| "CREATE_ASSET_ORDER"
|
||||||
|
| "CANCEL_ASSET_ORDER"
|
||||||
|
| "MULTI_PAYMENT"
|
||||||
|
| "DEPLOY_AT"
|
||||||
|
| "MESSAGE"
|
||||||
|
| "CHAT"
|
||||||
|
| "PUBLICIZE"
|
||||||
|
| "AIRDROP"
|
||||||
|
| "AT"
|
||||||
|
| "CREATE_GROUP"
|
||||||
|
| "UPDATE_GROUP"
|
||||||
|
| "ADD_GROUP_ADMIN"
|
||||||
|
| "REMOVE_GROUP_ADMIN"
|
||||||
|
| "GROUP_BAN"
|
||||||
|
| "CANCEL_GROUP_BAN"
|
||||||
|
| "GROUP_KICK"
|
||||||
|
| "GROUP_INVITE"
|
||||||
|
| "CANCEL_GROUP_INVITE"
|
||||||
|
| "JOIN_GROUP"
|
||||||
|
| "LEAVE_GROUP"
|
||||||
|
| "GROUP_APPROVAL"
|
||||||
|
| "SET_GROUP"
|
||||||
|
| "UPDATE_ASSET"
|
||||||
|
| "ACCOUNT_FLAGS"
|
||||||
|
| "ENABLE_FORGING"
|
||||||
|
| "REWARD_SHARE"
|
||||||
|
| "ACCOUNT_LEVEL"
|
||||||
|
| "TRANSFER_PRIVS"
|
||||||
|
| "PRESENCE";
|
||||||
|
|
||||||
|
interface QortalRequestOptions {
|
||||||
|
action: string;
|
||||||
|
name?: string;
|
||||||
|
service?: string;
|
||||||
|
data64?: string;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
category?: string;
|
||||||
|
tags?: string[] | string;
|
||||||
|
identifier?: string;
|
||||||
|
address?: string;
|
||||||
|
metaData?: string;
|
||||||
|
encoding?: string;
|
||||||
|
includeMetadata?: boolean;
|
||||||
|
limit?: number;
|
||||||
|
offset?: number;
|
||||||
|
reverse?: boolean;
|
||||||
|
resources?: any[];
|
||||||
|
filename?: string;
|
||||||
|
list_name?: string;
|
||||||
|
item?: string;
|
||||||
|
items?: string[];
|
||||||
|
tag1?: string;
|
||||||
|
tag2?: string;
|
||||||
|
tag3?: string;
|
||||||
|
tag4?: string;
|
||||||
|
tag5?: string;
|
||||||
|
coin?: string;
|
||||||
|
destinationAddress?: string;
|
||||||
|
amount?: number;
|
||||||
|
blob?: Blob;
|
||||||
|
mimeType?: string;
|
||||||
|
file?: File;
|
||||||
|
encryptedData?: string;
|
||||||
|
mode?: string;
|
||||||
|
query?: string;
|
||||||
|
excludeBlocked?: boolean;
|
||||||
|
exactMatchNames?: boolean;
|
||||||
|
creationBytes?: string;
|
||||||
|
type?: string;
|
||||||
|
assetId?: number;
|
||||||
|
txType?: TransactionType[];
|
||||||
|
confirmationStatus?: string;
|
||||||
|
startBlock?: number;
|
||||||
|
blockLimit?: number;
|
||||||
|
txGroupId?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare function qortalRequest(options: QortalRequestOptions): Promise<object>;
|
4029
package-lock.json
generated
Normal file
4029
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
package.json
Normal file
40
package.json
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"name": "q-utils",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc && vite build",
|
||||||
|
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@emotion/react": "^11.11.1",
|
||||||
|
"@emotion/styled": "^11.11.0",
|
||||||
|
"@mui/icons-material": "^5.11.11",
|
||||||
|
"@mui/material": "^5.11.13",
|
||||||
|
"@mui/system": "^5.14.5",
|
||||||
|
"colorsys": "github:netbeast/colorsys",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0",
|
||||||
|
"react-dropzone": "^14.2.3",
|
||||||
|
"react-intersection-observer": "^9.4.3",
|
||||||
|
"react-quill": "^2.0.0",
|
||||||
|
"react-rnd": "^10.4.1",
|
||||||
|
"ts-key-enum": "^2.0.12"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "^18.0.28",
|
||||||
|
"@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",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
26
tsconfig.json
Normal file
26
tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"noImplicitAny": false,
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"noUnusedParameters": false,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"allowSyntheticDefaultImports": true
|
||||||
|
},
|
||||||
|
"include": ["**/*"],
|
||||||
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user