forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[explorer] Implement go-to-definition within modules (MystenLabs#3930)
* Implement go-to-definition within explorer * Implement same-module go-to-definition * Add utils * lint + format
- Loading branch information
1 parent
c5cb2e6
commit 340f8a4
Showing
5 changed files
with
185 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { SuiAddress } from '@mysten/sui.js'; | ||
|
||
export const SUI_ADDRESS_LENGTH = 20; | ||
|
||
// TODO: Use version of this function from the SDK when it is exposed. | ||
export function normalizeSuiAddress( | ||
value: string, | ||
forceAdd0x: boolean = false | ||
): SuiAddress { | ||
let address = value.toLowerCase(); | ||
if (!forceAdd0x && address.startsWith('0x')) { | ||
address = address.slice(2); | ||
} | ||
const numMissingZeros = | ||
(SUI_ADDRESS_LENGTH - getHexByteLength(address)) * 2; | ||
if (numMissingZeros <= 0) { | ||
return '0x' + address; | ||
} | ||
return '0x' + '0'.repeat(numMissingZeros) + address; | ||
} | ||
|
||
function getHexByteLength(value: string): number { | ||
return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters