diff --git a/.changeset/brown-suns-tickle.md b/.changeset/brown-suns-tickle.md new file mode 100644 index 0000000000..ab13c8fc43 --- /dev/null +++ b/.changeset/brown-suns-tickle.md @@ -0,0 +1,5 @@ +--- +'@penumbra-zone/types': minor +--- + +Fix pnum parsing ValueView diff --git a/packages/types/src/pnum.test.ts b/packages/types/src/pnum.test.ts index 5356fa78b2..964a187e8a 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({ diff --git a/packages/types/src/pnum.ts b/packages/types/src/pnum.ts index 527907bfae..760de4f74f 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.js similarity index 86% rename from scripts/link-externally.js rename to scripts/link.js index f1e8df0698..fc72b06ed1 100644 --- a/scripts/link-externally.js +++ b/scripts/link.js @@ -6,11 +6,20 @@ 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|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 + * + * // watch inside packages + * cd packages/ui && pnpm dev:pack + * cd packages/types && pnpm dev:pack */ // Base directory for packages in the monorepo @@ -19,8 +28,8 @@ 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'; +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 0000000000..2191598411 --- /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()); +});