From 933af432f5ba788cd11d567a9bb1448aeb9a8627 Mon Sep 17 00:00:00 2001 From: jonty007 Date: Tue, 17 Sep 2024 12:51:44 +0530 Subject: [PATCH] Fixed build for nft-vite, explorer-vite, and wallet-vite --- packages/TBC20/src/token.ts | 1 - packages/TBC20/tsconfig.release.json | 1 + packages/explorer-vite/src/utils.ts | 38 ++++----- packages/nft-vite/src/components/Gallery.tsx | 84 +++++++++++++++----- packages/swap/build/src/buy.d.ts | 2 - packages/swap/build/src/buy.js | 1 - packages/swap/src/buy.ts | 2 - packages/wallet-vite/src/config.ts | 3 + 8 files changed, 88 insertions(+), 44 deletions(-) create mode 100644 packages/wallet-vite/src/config.ts diff --git a/packages/TBC20/src/token.ts b/packages/TBC20/src/token.ts index 0439c765c..c14f56adb 100644 --- a/packages/TBC20/src/token.ts +++ b/packages/TBC20/src/token.ts @@ -1,5 +1,4 @@ /* eslint-disable max-classes-per-file */ -const { Contract } = await import('@bitcoin-computer/lib') export class Token extends Contract { amount: number diff --git a/packages/TBC20/tsconfig.release.json b/packages/TBC20/tsconfig.release.json index 736826cab..e79aa7711 100644 --- a/packages/TBC20/tsconfig.release.json +++ b/packages/TBC20/tsconfig.release.json @@ -3,6 +3,7 @@ "compilerOptions": { "rootDir": ".", "outDir": "build", + "types": ["node", "@bitcoin-computer/lib"], "removeComments": true, "declaration": true }, diff --git a/packages/explorer-vite/src/utils.ts b/packages/explorer-vite/src/utils.ts index 3390dcfef..c3662d183 100644 --- a/packages/explorer-vite/src/utils.ts +++ b/packages/explorer-vite/src/utils.ts @@ -1,6 +1,6 @@ export const getFnParamNames = function (fn: string) { const match = fn.toString().match(/\(.*?\)/) - return match ? match[0].replace(/[()]/gi, '').replace(/\s/gi, '').split(',') : [] + return match ? match[0].replace(/[()]/gi, "").replace(/\s/gi, "").split(",") : [] } export function isValidRevString(outId: string): boolean { @@ -8,7 +8,7 @@ export function isValidRevString(outId: string): boolean { } export function isValidRev(value: any): boolean { - return typeof value === 'string' && isValidRevString(value) + return typeof value === "string" && isValidRevString(value) } // eslint-disable-next-line @@ -20,13 +20,13 @@ type JBasic = undefined | null | boolean | number | string | symbol | bigint type JArray = Json[] type JObject = { [x: string]: Json } -const isJUndefined = (a: any): a is undefined => typeof a === 'undefined' +const isJUndefined = (a: any): a is undefined => typeof a === "undefined" const isJNull = (a: any): a is null => a === null -const isJBoolean = (a: any): a is boolean => typeof a === 'boolean' -const isJNumber = (a: any): a is number => typeof a === 'number' -const isJString = (a: any): a is string => typeof a === 'string' -const isJSymbol = (a: any): a is symbol => typeof a === 'symbol' -const isJBigInt = (a: any): a is bigint => typeof a === 'bigint' +const isJBoolean = (a: any): a is boolean => typeof a === "boolean" +const isJNumber = (a: any): a is number => typeof a === "number" +const isJString = (a: any): a is string => typeof a === "string" +const isJSymbol = (a: any): a is symbol => typeof a === "symbol" +const isJBigInt = (a: any): a is bigint => typeof a === "bigint" const isJBasic = (a: any): a is JBasic => isJNull(a) || isJUndefined(a) || @@ -54,7 +54,7 @@ export const jsonMap = if (isJBasic(json)) return g(json) if (isJArray(json)) return g(json.map(jsonMap(g))) if (isJObject(json)) return g(objectMap(jsonMap(g))(json)) - throw new Error('Unsupported type') + throw new Error("Unsupported type") } export const strip = (value: Json): Json => { @@ -75,17 +75,17 @@ export const chunk = (arr: string[], chunkSize = 4): string[][] => { export const getValueForType = (type: string, stringValue: string) => { switch (type) { - case 'number': + case "number": return Number(stringValue) - case 'string': + case "string": return stringValue - case 'boolean': + case "boolean": return true // make this dynamic - case 'undefined': + case "undefined": return undefined - case 'null': + case "null": return null - case 'object': + case "object": return stringValue default: return Number(stringValue) @@ -104,18 +104,18 @@ export const isValidHexadecimalPublicKey = (publicKey: string): boolean => { export const getErrorMessage = (error: any): string => { if ( error?.response?.data?.error === - 'mandatory-script-verify-flag-failed (Operation not valid with the current stack size)' + "mandatory-script-verify-flag-failed (Operation not valid with the current stack size)" ) { - return 'You are not authorised to make changes to this smart object' + return "You are not authorised to make changes to this smart object" } if (error?.response?.data?.error) { return error?.response?.data?.error } - return error.message ? error.message : 'Error occurred' + return error.message ? error.message : "Error occurred" } // https://github.com/GoogleChromeLabs/jsbi/issues/30 export const toObject = (obj: any) => - JSON.stringify(obj, (key, value) => (typeof value === 'bigint' ? value.toString() : value), 2) + JSON.stringify(obj, (_, value) => (typeof value === "bigint" ? value.toString() : value), 2) diff --git a/packages/nft-vite/src/components/Gallery.tsx b/packages/nft-vite/src/components/Gallery.tsx index cc0aeff8d..a4abac745 100644 --- a/packages/nft-vite/src/components/Gallery.tsx +++ b/packages/nft-vite/src/components/Gallery.tsx @@ -22,30 +22,25 @@ export type UserQuery = Partial<{ function NFTCard({ nft }: { nft: NFT }) { return ( -
- -
- -
-
+ <> +
+ +
{nft.name}

{nft.artist}

- -
+
+ ) } @@ -112,14 +107,65 @@ function ValueComponent({ rev, computer }: { rev: string; computer: Computer }) } function FromRevs({ revs, computer }: { revs: string[]; computer: any }) { + const cols: string[][] = [[], [], [], []] + + revs.forEach((rev, index) => { + const colNumber = index % 4 + cols[colNumber].push(rev) + }) return ( -
- {revs.map((rev) => ( -
- + <> +
+
+ {cols[0].map((rev) => ( +
+ + + +
+ ))}
- ))} -
+
+ {cols[1].map((rev) => ( +
+ + + +
+ ))} +
+
+ {cols[2].map((rev) => ( +
+ + + +
+ ))} +
+
+ {cols[3].map((rev) => ( +
+ + + +
+ ))} +
+
+ ) } diff --git a/packages/swap/build/src/buy.d.ts b/packages/swap/build/src/buy.d.ts index 9954e9015..6f33a8e3c 100644 --- a/packages/swap/build/src/buy.d.ts +++ b/packages/swap/build/src/buy.d.ts @@ -1,6 +1,5 @@ import { Transaction } from '@bitcoin-computer/nakamotojs'; import { StaticSwapHelper } from './static-swap.js'; -declare const Contract: typeof import("@bitcoin-computer/lib/computer.js").Contract; export declare class Buy extends Contract { amount: number; constructor(price: number, amount: number, tokenRoot: string); @@ -24,4 +23,3 @@ export declare class BuyHelper { isOpen(buy: Buy): Promise; settleBuyOrder(swapTx: Transaction): Promise; } -export {}; diff --git a/packages/swap/build/src/buy.js b/packages/swap/build/src/buy.js index f0c318110..a482d156a 100644 --- a/packages/swap/build/src/buy.js +++ b/packages/swap/build/src/buy.js @@ -1,5 +1,4 @@ import { StaticSwapHelper } from './static-swap.js'; -const { Contract } = await import('@bitcoin-computer/lib'); export class Buy extends Contract { constructor(price, amount, tokenRoot) { super({ _amount: price, amount, tokenRoot }); diff --git a/packages/swap/src/buy.ts b/packages/swap/src/buy.ts index 1101cce28..33a0274e1 100644 --- a/packages/swap/src/buy.ts +++ b/packages/swap/src/buy.ts @@ -2,8 +2,6 @@ import { Transaction } from '@bitcoin-computer/nakamotojs' import { StaticSwapHelper } from './static-swap.js' -const { Contract } = await import('@bitcoin-computer/lib') - export class Buy extends Contract { amount: number diff --git a/packages/wallet-vite/src/config.ts b/packages/wallet-vite/src/config.ts new file mode 100644 index 000000000..5beb2005d --- /dev/null +++ b/packages/wallet-vite/src/config.ts @@ -0,0 +1,3 @@ +export const explorerURL = import.meta.env.VITE_EXPLORER_URL + ? import.meta.env.VITE_EXPLORER_URL + : ""