-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate more stacks-ui dependancies, remove stacks/ui-utils
- Loading branch information
1 parent
af69ad2
commit 0d92ad0
Showing
24 changed files
with
131 additions
and
25 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,48 @@ | ||
# Stacks UI Utils | ||
|
||
Legacy utils taken from [Stacks UI](https://github.com/hirosystems/ui). Moved here initially but can be moved to monorepo | ||
|
||
## Transactions | ||
|
||
### getContractName | ||
|
||
This will parse a string and return the contract name. | ||
|
||
```ts | ||
const contract = | ||
'ST12EY99GS4YKP0CP2CFW6SEPWQ2CGVRWK5GHKDRV.market' || | ||
'ST12EY99GS4YKP0CP2CFW6SEPWQ2CGVRWK5GHKDRV.market::asset-name'; | ||
|
||
const name = getContractName(contract); | ||
|
||
// market | ||
``` | ||
|
||
## Strings | ||
|
||
### truncateHex | ||
|
||
This will truncate a hex, keeping the 0x out of the offset amount. | ||
|
||
```ts | ||
const hex = `0x33cc9a437e704e790958f7bb66492f5ad3a863ab3bcbef47138069725549a353`; | ||
|
||
const shortened = truncateHex(hex, 4); | ||
// 0x33cc...a353 | ||
``` | ||
|
||
### truncateMiddle | ||
|
||
This will truncate any string in the middle, given an offset amount. | ||
|
||
```ts | ||
const hex = `0x33cc9a437e704e790958f7bb66492f5ad3a863ab3bcbef47138069725549a353`; | ||
|
||
const shortened = truncateHex(hex, 4); | ||
// 0x33cc...a353 | ||
|
||
const contract = 'ST12EY99GS4YKP0CP2CFW6SEPWQ2CGVRWK5GHKDRV.market'; | ||
|
||
const shortenedContract = truncateHex(contract, 4); | ||
// ST12...KDRV.market | ||
``` |
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,20 @@ | ||
/** | ||
* getContractName | ||
* | ||
* Gets the contract name of a string: contract_id or fully qualified asset name. | ||
* | ||
* @param value - the source string: [principal].[contract-name] or [principal].[contract-name]::[asset-name] | ||
*/ | ||
export const getContractName = (value: string): string => { | ||
if (value.includes('.')) { | ||
const parts = value?.split('.'); | ||
if (value.includes('::')) { | ||
return parts[1].split('::')[0]; | ||
} | ||
return parts[1]; | ||
} | ||
// console.warn('getContractName: does not contain a period, does not appear to be a contract_id.', { | ||
// value, | ||
// }); | ||
return value; | ||
}; |
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,40 @@ | ||
/** | ||
* truncateHex | ||
* | ||
* Truncates hex while keeping the 0x prefix. | ||
* | ||
* @param {string} hex - the hex to truncate | ||
* @param {number} offset - the number of chars to keep | ||
*/ | ||
function truncateHex(hex: string, offset = 5): string { | ||
return `${hex.substring(0, offset + 2)}…${hex.substring(hex.length - offset)}`; | ||
} | ||
|
||
/** | ||
* truncateMiddle | ||
* | ||
* If contract_id, it will truncate the principal, while keeping the contract name untouched. | ||
* If prefixed with '0x', will truncate everything after prefix. | ||
* | ||
* @param {string} input - the string to truncate | ||
* @param {number} offset - the number of chars to keep on either end | ||
*/ | ||
export function truncateMiddle(input: string, offset = 5): string { | ||
if (!input) return ''; | ||
// hex | ||
if (input.startsWith('0x')) { | ||
return truncateHex(input, offset); | ||
} | ||
// for contracts | ||
if (input.includes('.')) { | ||
const parts = input.split('.'); | ||
const start = parts[0]?.substr(0, offset); | ||
const end = parts[0]?.substr(parts[0].length - offset, parts[0].length); | ||
return `${start}…${end}.${parts[1]}`; | ||
} else { | ||
// everything else | ||
const start = input?.substr(0, offset); | ||
const end = input?.substr(input.length - offset, input.length); | ||
return `${start}…${end}`; | ||
} | ||
} |
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
3 changes: 1 addition & 2 deletions
3
...ponents/psbt-inputs-and-outputs/components/psbt-input-list/components/psbt-input-item.tsx
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
3 changes: 1 addition & 2 deletions
3
...nents/psbt-inputs-and-outputs/components/psbt-output-list/components/psbt-output-item.tsx
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
3 changes: 1 addition & 2 deletions
3
...t-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx
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
3 changes: 1 addition & 2 deletions
3
...-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx
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
2 changes: 1 addition & 1 deletion
2
src/app/features/stacks-transaction-request/contract-preview.tsx
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
2 changes: 1 addition & 1 deletion
2
src/app/features/stacks-transaction-request/post-conditions/stx-post-condition.tsx
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
2 changes: 1 addition & 1 deletion
2
...tcoin-contract-request/components/bitcoin-contract-offer/bitcoin-contract-offer-input.tsx
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
3 changes: 2 additions & 1 deletion
3
src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx
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
3 changes: 1 addition & 2 deletions
3
src/app/pages/rpc-sign-bip322-message/rpc-sign-bip322-message.tsx
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