Skip to content

Commit

Permalink
Merge pull request #1349 from galacticcouncil/enable-pendulum
Browse files Browse the repository at this point in the history
Enable Pendulum chain
  • Loading branch information
vkulinich-cl authored Jun 6, 2024
2 parents 8a59922 + df28470 commit 72d1ef1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 38 deletions.
13 changes: 8 additions & 5 deletions src/api/externalAssetRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ export const getPedulumAssets = async () => {
const data = dataRaw.unwrap()
const location = data.location.unwrap()

if (location.isV2 && location.asV2.interior.toString() !== "Here") {
if (location) {
const type = location.type.toString()
const interior = location[`as${type}`].interior.toString()

const id = getPendulumAssetId(idRaw)
if (id)
if (interior !== "Here" && id)
acc.push({
id,
// @ts-ignore
Expand All @@ -95,7 +98,7 @@ export const getPedulumAssets = async () => {
symbol: data.symbol.toHuman() as string,
// @ts-ignore
name: data.name.toHuman() as string,
location: location.asV2 as HydradxRuntimeXcmAssetLocation,
location: location[`as${type}`] as HydradxRuntimeXcmAssetLocation,
origin: PENDULUM_ID,
})
}
Expand All @@ -111,11 +114,11 @@ export const getPedulumAssets = async () => {
*/
export const useExternalAssetRegistry = () => {
const assetHub = useAssetHubAssetRegistry()
//const pendulum = usePendulumAssetRegistry()
const pendulum = usePendulumAssetRegistry()

return {
[ASSET_HUB_ID as number]: assetHub,
// [PENDULUM_ID as number]: pendulum,
[PENDULUM_ID as number]: pendulum,
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/sections/wallet/addToken/AddToken.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TOAST_MESSAGES } from "state/toasts"
import { Trans, useTranslation } from "react-i18next"
import {
ASSET_HUB_ID,
PENDULUM_ID,
useExternalAssetRegistry,
} from "api/externalAssetRegistry"
import { useProviderRpcUrlStore } from "api/provider"
Expand Down Expand Up @@ -157,7 +158,7 @@ const internalIds = new Map([
["2230", "1000073"],
])

export const SELECTABLE_PARACHAINS_IDS = [ASSET_HUB_ID /*PENDULUM_ID*/]
export const SELECTABLE_PARACHAINS_IDS = [ASSET_HUB_ID, PENDULUM_ID]

export const PARACHAIN_CONFIG: {
[x: number]: {
Expand Down
33 changes: 1 addition & 32 deletions src/utils/externalAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,13 @@ import { PENDULUM_ID } from "api/externalAssetRegistry"
import { Buffer } from "buffer"
import {
InteriorProp,
isGeneralKey,
TExternalAssetInput,
} from "sections/wallet/addToken/AddToken.utils"
import { Option } from "@polkadot/types"

export const getPendulumInputData = (
location: HydradxRuntimeXcmAssetLocation,
): TExternalAssetInput => {
const formatGeneralKey = (key: string) => {
const isHex = key.startsWith("0x")
const bytes = Buffer.from(
isHex ? key.slice(2) : key,
isHex ? "hex" : "ascii",
)

const length = bytes.buffer.byteLength
const data = Buffer.concat([bytes, Buffer.alloc(32 - length)]).toString(
"hex",
)

return {
length: length.toString(),
data: `0x${data}`,
}
}

const interiorType = location.interior.type

if (interiorType !== "Here") {
Expand All @@ -38,22 +19,10 @@ export const getPendulumInputData = (

const newInteriorType = `X${Number(interiorType.slice(1)) + 1}`

const props = (Array.isArray(interior) ? interior : [interior]).map(
(interiorProp) => {
const formatedProp = isGeneralKey(interiorProp)
? {
GeneralKey: formatGeneralKey(interiorProp["GeneralKey"]),
}
: interiorProp

return formatedProp
},
)

return {
parents: "1",
interior: {
[newInteriorType]: [{ Parachain: PENDULUM_ID.toString() }, ...props],
[newInteriorType]: [{ Parachain: PENDULUM_ID.toString() }, ...interior],
},
}
} else {
Expand Down

0 comments on commit 72d1ef1

Please sign in to comment.