Skip to content

Commit

Permalink
Shorten symbols for delegation/unbonding tokens (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepinho authored Mar 6, 2024
1 parent 1a2a191 commit f217415
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/extension/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PRAX=lkpmkhpnhknhmibgnmmhdhgdilepfghe
IDB_VERSION=24
IDB_VERSION=25
USDC_ASSET_ID="reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg="
MINIFRONT_URL=https://app.testnet.penumbra.zone/
PENUMBRA_NODE_PD_URL=https://grpc.testnet.penumbra.zone/
6 changes: 2 additions & 4 deletions packages/types/src/customize-symbol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Customizing metadata', () => {
'delegation_penumbravalid1fjuj67ayaqueqxg03d65ps5aah6m39u39qeacu3zv2cw3dzxssyq3yrcez',
});

expect(customizeSymbol(metadata).symbol).toBe('Delegated UM (fjuj67ayaqueqxg03d65ps5aa...)');
expect(customizeSymbol(metadata).symbol).toBe('delUM(fjuj67ay…)');
});

test('should work for unbonding token', () => {
Expand All @@ -18,9 +18,7 @@ describe('Customizing metadata', () => {
'uunbonding_epoch_29_penumbravalid1fjuj67ayaqueqxg03d65ps5aah6m39u39qeacu3zv2cw3dzxssyq3yrcez',
});

expect(customizeSymbol(metadata).symbol).toBe(
'Unbonding UM, epoch 29 (fjuj67ayaqueqxg03d65ps5aa...)',
);
expect(customizeSymbol(metadata).symbol).toBe('unbondUMe29(fjuj67ay…)');
});

test('should do nothing if no matches', () => {
Expand Down
11 changes: 5 additions & 6 deletions packages/types/src/customize-symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ import {
UnbondingCaptureGroups,
} from '@penumbra-zone/constants';

const DELEGATION_SYMBOL_LENGTH = 50 - 'delegation_penumbravalid1'.length;
const UNBONDING_SYMBOL_LENGTH = 41 - 'unbonding_epoch_'.length;
const SHORTENED_ID_LENGTH = 8;

// If the metadata is for a delegation or unbonding tokens, customize its symbol.
// We can't trust the validator's self-described name, so use their validator ID (in metadata.display).
export const customizeSymbol = (metadata: Metadata) => {
const delegationMatch = assetPatterns.delegationToken.exec(metadata.display);
if (delegationMatch) {
const { id } = delegationMatch.groups as unknown as DelegationCaptureGroups;
const shortenedId = id.slice(0, DELEGATION_SYMBOL_LENGTH);
const shortenedId = id.slice(0, SHORTENED_ID_LENGTH);
const customized = metadata.clone();
customized.symbol = `Delegated UM (${shortenedId}...)`;
customized.symbol = `delUM(${shortenedId})`;
return customized;
}

const unbondingMatch = assetPatterns.unbondingToken.exec(metadata.display);
if (unbondingMatch) {
const { id, epoch } = unbondingMatch.groups as unknown as UnbondingCaptureGroups;
const shortenedId = id.slice(0, UNBONDING_SYMBOL_LENGTH);
const shortenedId = id.slice(0, SHORTENED_ID_LENGTH);
const customized = metadata.clone();
customized.symbol = `Unbonding UM, epoch ${epoch} (${shortenedId}...)`;
customized.symbol = `unbondUMe${epoch}(${shortenedId})`;
return customized;
}

Expand Down

0 comments on commit f217415

Please sign in to comment.