From 2603045c0ec38fd24eba4c401e13a022660df42a Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Thu, 19 Dec 2024 18:13:00 +0400 Subject: [PATCH 1/6] Fix pnum parsing valueviews --- packages/types/src/pnum.ts | 6 +++++- scripts/link-externally.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/types/src/pnum.ts b/packages/types/src/pnum.ts index 527907bfa..760de4f74 100644 --- a/packages/types/src/pnum.ts +++ b/packages/types/src/pnum.ts @@ -35,7 +35,11 @@ function pnum( value = new BigNumber(input).shiftedBy(exponent); } else if (typeof input === 'bigint') { value = new BigNumber(input.toString()); - } else if (input instanceof ValueView) { + } else if ( + typeof input === 'object' && + 'valueView' in input && + typeof input.valueView === 'object' + ) { const amount = getAmount(input); value = new BigNumber(joinLoHi(amount.lo, amount.hi).toString()); exponent = diff --git a/scripts/link-externally.js b/scripts/link-externally.js index f1e8df069..d43c3695b 100644 --- a/scripts/link-externally.js +++ b/scripts/link-externally.js @@ -11,6 +11,10 @@ import { fileURLToPath } from 'url'; * * // when enabled, you can link the package to another repo like this: * cd other/repo && pnpm link ../penumbra-zone/web/packages/ui + * + * // watch inside packages + * cd packages/ui && pnpm dev:pack + * cd packages/types && pnpm dev:pack */ // Base directory for packages in the monorepo From 1a60d42268975cdf406a958e3c5611402979561e Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Thu, 19 Dec 2024 18:16:56 +0400 Subject: [PATCH 2/6] Add test for parsing ValueView --- packages/types/src/pnum.test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/types/src/pnum.test.ts b/packages/types/src/pnum.test.ts index 5356fa78b..964a187e8 100644 --- a/packages/types/src/pnum.test.ts +++ b/packages/types/src/pnum.test.ts @@ -142,6 +142,34 @@ describe('pnum', () => { expect(result3.toString()).toBe('12345.5678'); }); + it('should correctly parse ViewView', () => { + const result = pnum( + new ValueView({ + valueView: { + case: 'knownAssetId', + value: { + amount: new Amount({ + lo: 123455678n, + hi: 0n, + }), + metadata: new Metadata({ + base: 'UM', + display: 'penumbra', + denomUnits: [ + new DenomUnit({ + exponent: 4, + denom: 'penumbra', + }), + ], + }), + }, + }, + }), + ); + + expect(result.toString()).toBe('12345.5678'); + }); + it('should correctly convert to ValueView', () => { const unknown = pnum(12345.5678, { exponent: 4 }).toValueView(); const metadata = new Metadata({ From 53b72964e3cd14caeed5e9e123321b649c1004b4 Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Thu, 19 Dec 2024 18:17:31 +0400 Subject: [PATCH 3/6] Add changeset --- .changeset/brown-suns-tickle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brown-suns-tickle.md diff --git a/.changeset/brown-suns-tickle.md b/.changeset/brown-suns-tickle.md new file mode 100644 index 000000000..ab13c8fc4 --- /dev/null +++ b/.changeset/brown-suns-tickle.md @@ -0,0 +1,5 @@ +--- +'@penumbra-zone/types': minor +--- + +Fix pnum parsing ValueView From 1c9295f8f60cf21845111b64c3428b4112ff55a4 Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Thu, 19 Dec 2024 18:26:23 +0400 Subject: [PATCH 4/6] Improve linking scripts --- scripts/{link-externally.js => link.js} | 9 +++++---- scripts/unlink.js | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) rename scripts/{link-externally.js => link.js} (90%) create mode 100644 scripts/unlink.js diff --git a/scripts/link-externally.js b/scripts/link.js similarity index 90% rename from scripts/link-externally.js rename to scripts/link.js index d43c3695b..457a90682 100644 --- a/scripts/link-externally.js +++ b/scripts/link.js @@ -6,8 +6,8 @@ import { fileURLToPath } from 'url'; * This script is used to link dependencies from this monorepo to other repos. * * @usage: - * node scripts/link-externally.js enable - * node scripts/link-externally.js disable + * node scripts/link 1|true|enable|link + * node scripts/link 0|false|disable|unlink * * // when enabled, you can link the package to another repo like this: * cd other/repo && pnpm link ../penumbra-zone/web/packages/ui @@ -23,8 +23,9 @@ const packagesDir = path.join(path.dirname(__filename), '..', 'packages'); // Get the command-line argument to determine action const action = process.argv[2]; -const enableLinking = action === 'enable'; -const disableLinking = action === 'disable'; +console.log('TCL: action', action, typeof action); +const enableLinking = ['enable', 'link', '1', 'true', undefined].includes(action); +const disableLinking = ['disable', 'unlink', '0', 'false'].includes(action); // Helper function to enable linked exports function enableLinkedExports(packageJsonPath) { diff --git a/scripts/unlink.js b/scripts/unlink.js new file mode 100644 index 000000000..219159841 --- /dev/null +++ b/scripts/unlink.js @@ -0,0 +1,9 @@ +/* eslint-disable no-console -- disable console.log */ +import { spawn } from 'child_process'; + +const child = spawn('node', ['scripts/link', 'unlink']); + +child.stdout.on('data', data => { + // eslint-disable-next-line no-undef -- disable no-undef + console.log(data.toString()); +}); From ccb679768050728cba345c8d130af740c57b6b62 Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Thu, 19 Dec 2024 18:27:00 +0400 Subject: [PATCH 5/6] Update link comment --- scripts/link.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/link.js b/scripts/link.js index 457a90682..1bca135e3 100644 --- a/scripts/link.js +++ b/scripts/link.js @@ -6,9 +6,14 @@ import { fileURLToPath } from 'url'; * This script is used to link dependencies from this monorepo to other repos. * * @usage: - * node scripts/link 1|true|enable|link + * node scripts/link 1|true|enable|link|undefined * node scripts/link 0|false|disable|unlink * + * or + * + * node scripts/link + * node scripts/unlink + * * // when enabled, you can link the package to another repo like this: * cd other/repo && pnpm link ../penumbra-zone/web/packages/ui * From 4e1af09783b3ac85e143f6e07c81946d98982f8e Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Thu, 19 Dec 2024 18:27:41 +0400 Subject: [PATCH 6/6] Remove console log --- scripts/link.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/link.js b/scripts/link.js index 1bca135e3..fc72b06ed 100644 --- a/scripts/link.js +++ b/scripts/link.js @@ -28,7 +28,6 @@ const packagesDir = path.join(path.dirname(__filename), '..', 'packages'); // Get the command-line argument to determine action const action = process.argv[2]; -console.log('TCL: action', action, typeof action); const enableLinking = ['enable', 'link', '1', 'true', undefined].includes(action); const disableLinking = ['disable', 'unlink', '0', 'false'].includes(action);