generated from well-known-components/base-ts-project
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add utils functions to handle ERC-721 URNs (#172)
- Loading branch information
Showing
5 changed files
with
44 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { DecentralandAssetIdentifier } from './types' | ||
|
||
/** | ||
* Checks if the URN follows the standard ERC-721 by having the tokenId identifier at the end | ||
* @public | ||
*/ | ||
export function isExtendedUrn(asset: DecentralandAssetIdentifier): boolean { | ||
return ['blockchain-collection-v1-item', 'blockchain-collection-v2-item'].includes(asset.type) | ||
} | ||
|
||
/** | ||
* Takes an URN adhering to the ERC-721 standard and resolves both its asset URN and token identity | ||
* WARNING: it assumes the URN received follows the ERC-721 standard and that its last part refers to the token id | ||
* @public | ||
*/ | ||
export function getTokenIdAndAssetUrn(completeUrn: string): { assetUrn: string; tokenId: string } { | ||
const lastColonIndex = completeUrn.lastIndexOf(':') | ||
const urnValue = completeUrn.slice(0, lastColonIndex) | ||
return { assetUrn: urnValue, tokenId: completeUrn.slice(lastColonIndex + 1) } | ||
} |
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