-
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.
- Loading branch information
1 parent
0c6c4d1
commit a6246b5
Showing
6 changed files
with
106 additions
and
58 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
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,14 @@ | ||
/** | ||
* getAssetContractAddress | ||
* | ||
* Gets the assets contract address 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 function getAssetContractAddress(value: string): string { | ||
if (value.includes('.')) { | ||
return value.split('.')[0]; | ||
} | ||
|
||
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
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,24 @@ | ||
import { getAssetContractAddress } from './get-asset-contract-address'; | ||
|
||
const fullyQualifiedName = 'SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C.btc-monkeys-bananas::BANANA'; | ||
const contractId = 'SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C.btc-monkeys-bananas'; | ||
|
||
const contractAddress = 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQW2S7D0'; | ||
|
||
describe('getAssetContractAddress', () => { | ||
test('should return the contract address from a fully qualified asset name', () => { | ||
const assetContractAddress = getAssetContractAddress(fullyQualifiedName); | ||
|
||
expect(assetContractAddress).toBe(contractAddress); | ||
Check failure on line 12 in src/app/ui/utils/stacks-ft-utils.spec.ts GitHub Actions / test-unitsrc/app/ui/utils/stacks-ft-utils.spec.ts > getAssetContractAddress > should return the contract address from a fully qualified asset name
|
||
}); | ||
|
||
test('should return the contract address from a contract id', () => { | ||
const assetContractAddress = getAssetContractAddress(contractId); | ||
return expect(assetContractAddress).toBe(contractAddress); | ||
Check failure on line 17 in src/app/ui/utils/stacks-ft-utils.spec.ts GitHub Actions / test-unitsrc/app/ui/utils/stacks-ft-utils.spec.ts > getAssetContractAddress > should return the contract address from a contract id
|
||
}); | ||
|
||
test('should return the contract address from a contract address', () => { | ||
const assetContractAddress = getAssetContractAddress(contractAddress); | ||
expect(assetContractAddress).toBe(contractAddress); | ||
}); | ||
}); |