Skip to content

Commit

Permalink
feat(sdk): Add asset search by multi-location ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldev5 committed Nov 12, 2024
1 parent 7730776 commit e12327e
Show file tree
Hide file tree
Showing 71 changed files with 7,548 additions and 5,822 deletions.
2 changes: 1 addition & 1 deletion apps/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@tabler/icons-react": "^3.21.0",
"axios": "^1.7.7",
"ethers": "^6.13.4",
"polkadot-api": "^1.6.5",
"polkadot-api": "^1.7.3",
"react": "^18.3.1",
"react-confetti": "^6.1.0",
"react-dom": "^18.3.1",
Expand Down
20 changes: 18 additions & 2 deletions apps/playground/src/components/CurrencySelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,25 @@ const CurrencySelection: FC<Props> = ({ form, currencyOptions }) => {
{form.values.isCustomCurrency &&
form.values.customCurrencyType === "multilocation" && (
<JsonInput
placeholder="Enter Multi-Location JSON here"
placeholder="Input Multi-Location JSON or interior junctions JSON to search for and identify the asset"
formatOnBlur
autosize
minRows={10}
{...form.getInputProps("customCurrency")}
/>
)}

{form.values.isCustomCurrency &&
form.values.customCurrencyType === "overridenMultilocation" && (
<JsonInput
placeholder="Provide the XCM Multi-Location JSON to override the default configuration"
formatOnBlur
autosize
minRows={10}
{...form.getInputProps("customCurrency")}
/>
)}

{!form.values.isCustomCurrency && (
<Select
key={form.values.from + form.values.to}
Expand All @@ -71,7 +83,7 @@ const CurrencySelection: FC<Props> = ({ form, currencyOptions }) => {
<Group>
<Checkbox
size="xs"
label="Use Custom Currency"
label="Select custom asset"
{...form.getInputProps("isCustomCurrency", { type: "checkbox" })}
/>
{form.values.isCustomCurrency && (
Expand All @@ -81,6 +93,10 @@ const CurrencySelection: FC<Props> = ({ form, currencyOptions }) => {
{ label: "Asset ID", value: "id" },
{ label: "Symbol", value: "symbol" },
{ label: "Multi-location", value: "multilocation" },
{
label: "Override Multi-location",
value: "overridenMultilocation",
},
]}
{...form.getInputProps("customCurrencyType")}
/>
Expand Down
6 changes: 5 additions & 1 deletion apps/playground/src/components/TransferForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export type FormValues = {
amount: string;
useApi: boolean;
isCustomCurrency: boolean;
customCurrencyType?: "id" | "symbol" | "multilocation";
customCurrencyType?:
| "id"
| "symbol"
| "multilocation"
| "overridenMultilocation";
};

export type FormValuesTransformed = FormValues & {
Expand Down
7 changes: 6 additions & 1 deletion apps/playground/src/components/XcmTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TransferForm from "./TransferForm";
import { useDisclosure, useScrollIntoView } from "@mantine/hooks";
import {
isForeignAsset,
Override,
type Extrinsic,
type TCurrencyInput,
type TMultiLocation,
Expand Down Expand Up @@ -58,6 +59,10 @@ const XcmTransfer = () => {
return {
symbol: customCurrency,
};
} else if (customCurrencyType === "overridenMultilocation") {
return {
multilocation: Override(JSON.parse(customCurrency) as TMultiLocation),
};
} else {
return {
multilocation: JSON.parse(customCurrency) as TMultiLocation,
Expand All @@ -80,7 +85,7 @@ const XcmTransfer = () => {
return hasDuplicateIds
? { symbol: currency.symbol ?? "" }
: {
id: currency.assetId,
id: currency.assetId ?? "",
};
} else {
throw Error("Currency is required");
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/hooks/useCurrencyOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const useCurrencyOptions = (
() =>
Object.keys(currencyMap).map((key) => ({
value: key,
label: `${currencyMap[key].symbol} - ${isForeignAsset(currencyMap[key]) ? currencyMap[key].assetId : "Native"}`,
label: `${currencyMap[key].symbol} - ${isForeignAsset(currencyMap[key]) ? (currencyMap[key].assetId ?? "Multi-location") : "Native"}`,
})),
[currencyMap],
);
Expand Down
4 changes: 2 additions & 2 deletions apps/playground/src/routes/RouterTransferPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ const RouterTransferPage = () => {
.to(to)
.exchange(exchange)
.currencyFrom(
isForeignAsset(currencyFrom)
isForeignAsset(currencyFrom) && currencyFrom.assetId
? { id: currencyFrom.assetId }
: { symbol: currencyFrom.symbol ?? "" },
)
.currencyTo(
isForeignAsset(currencyTo)
isForeignAsset(currencyTo) && currencyTo.assetId
? { id: currencyTo.assetId }
: { symbol: currencyTo.symbol ?? "" },
)
Expand Down
2 changes: 1 addition & 1 deletion apps/xcm-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"mixpanel": "^0.18.0",
"nodemailer": "^6.9.16",
"pg": "^8.13.1",
"polkadot-api": "^1.6.5",
"polkadot-api": "^1.7.3",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"typeorm": "^0.3.20",
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/e2e/xcm-papi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const filteredNodes = NODE_NAMES_DOT_KSM.filter(

const findTransferableNodeAndAsset = (
from: TNode
): { nodeTo: TNode | undefined; asset: string | undefined; assetId: string | null } => {
): { nodeTo: TNode | undefined; asset: string | undefined; assetId: string | null | undefined } => {
const allFromAssets = getAssetsForNode(from)

const nodeTo = NODE_NAMES_DOT_KSM.filter(
Expand All @@ -83,7 +83,7 @@ const findTransferableNodeAndAsset = (

const filteredNodes =
node === 'AssetHubPolkadot' || node === 'AssetHubKusama'
? nodeAssets.filter(symbol => symbol !== 'DOT' && symbol !== 'KSM')
? nodeAssets.filter(symbol => symbol !== 'DOT' && symbol !== 'KSM' && symbol !== 'GLMR')
: nodeAssets

const commonAsset = filteredNodes.filter(asset => allFromAssets.includes(asset))[0]
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/e2e/xcm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const filteredNodes = NODE_NAMES_DOT_KSM.filter(

const findTransferableNodeAndAsset = (
from: TNode
): { nodeTo: TNode | undefined; asset: string | undefined; assetId: string | null } => {
): { nodeTo: TNode | undefined; asset: string | undefined; assetId: string | null | undefined } => {
const allFromAssets = getAssetsForNode(from)

const nodeTo = NODE_NAMES_DOT_KSM.filter(
Expand All @@ -62,7 +62,7 @@ const findTransferableNodeAndAsset = (

const filteredNodes =
node === 'AssetHubPolkadot' || node === 'AssetHubKusama'
? nodeAssets.filter(symbol => symbol !== 'DOT' && symbol !== 'KSM')
? nodeAssets.filter(symbol => symbol !== 'DOT' && symbol !== 'KSM' && symbol !== 'GLMR')
: nodeAssets

const commonAsset = filteredNodes.filter(asset => allFromAssets.includes(asset))[0]
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@polkadot/apps-config": ">= 0.145",
"@polkadot/types": ">= 12.4 < 13",
"@polkadot/util": ">= 13",
"polkadot-api": ">= 1.6.5 < 2"
"polkadot-api": ">= 1.7.3 < 2"
},
"peerDependenciesMeta": {
"@polkadot/api": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/scripts/assets/addAliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function addAliasesToDuplicateSymbols(assetsMap: TAssetJsonMap): TAssetJs

for (const asset of allAssets) {
if (asset.symbol === symbol && isForeignAsset(asset)) {
const aliasNumber = aliasNumbers[asset.assetId]
const aliasNumber = asset.assetId ? aliasNumbers[asset.assetId] : undefined
if (aliasNumber !== undefined) {
asset.alias = `${symbol}${aliasNumber}`
}
Expand Down
Loading

0 comments on commit e12327e

Please sign in to comment.