Skip to content

Commit

Permalink
Merge pull request #11 from XP-NETWORK/fix/secret-token-id-conversion
Browse files Browse the repository at this point in the history
fix(secret): convert secret nft token id after lock event
  • Loading branch information
D4mph1r authored Nov 11, 2024
2 parents eb839b8 + 5da211c commit 7c17dbc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/factory/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { nearHandler } from "../handlers/near";
import { secretHandler } from "../handlers/secret";
import { tezosHandler } from "../handlers/tezos";
import { raise, tonHandler } from "../handlers/ton";
import { fetchHttpOrIpfs } from "../handlers/utils";
import {
convertNumbToHexToString,
convertStringToHexToNumb,
fetchHttpOrIpfs,
} from "../handlers/utils";
import { TChainParams } from "./config";

export namespace Chain {
Expand Down Expand Up @@ -152,12 +156,21 @@ export function ChainFactory(cp: Partial<TChainParams>): TChainFactory {
.toUpperCase()
.substring(0, 8);
}
let convertedTokenId = data.tokenId;
if (data.sourceChain === "SECRET") {
if (chain.identifier === "SECRET") {
convertedTokenId = convertStringToHexToNumb(data.tokenId);
} else if (data.destinationChain === "SECRET") {
convertedTokenId = convertNumbToHexToString(data.tokenId);
}
}
const metadata = ogNftData.metadata || data.metaDataUri;
const imgUri = (await fetchHttpOrIpfs(metadata)).image;
return {
...data,
...ogNftData,
metadata,
tokenId: convertedTokenId,
royalty: ogNftData.royalty.toString(),
royaltyReceiver: royaltyReceiver,
fee: fee.toString(),
Expand Down
11 changes: 10 additions & 1 deletion src/handlers/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { fetchHttpOrIpfs } from "./fetchHttpOrIpfs";
import retryFn from "./retryFn";
import {
convertNumbToHexToString,
convertStringToHexToNumb,
} from "./tokenIdConversion";

export { retryFn, fetchHttpOrIpfs };
export {
retryFn,
fetchHttpOrIpfs,
convertNumbToHexToString,
convertStringToHexToNumb,
};
15 changes: 15 additions & 0 deletions src/handlers/utils/tokenIdConversion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function convertStringToHexToNumb(str: string) {
const hex = Array.from(str)
.map((char) => char.charCodeAt(0).toString(16).padStart(2, "0"))
.join("");
const numb = BigInt(`0x${hex}`);
return numb.toString();
}
export function convertNumbToHexToString(num: string) {
const numberToBigInt = BigInt(num);
const hex = numberToBigInt.toString(16) as string;
const string = (hex.match(/.{1,2}/g) || [])
.map((byte) => String.fromCharCode(parseInt(byte, 16)))
.join("");
return string;
}

0 comments on commit 7c17dbc

Please sign in to comment.