Skip to content

Commit

Permalink
fix(xcm-api): Remove old XCM API code 👴
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldev5 authored and dudo50 committed Nov 23, 2024
1 parent f072da7 commit 973dfde
Show file tree
Hide file tree
Showing 119 changed files with 1,162 additions and 1,803 deletions.
267 changes: 136 additions & 131 deletions apps/playground/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import {
IconRoute,
} from "@tabler/icons-react";
import {
BrowserRouter,
Navigate,
Route,
NavLink as RouterNavLink,
Routes,
useLocation,
} from "react-router-dom";
import "./App.css";
import { useWallet } from "./hooks/useWallet";
Expand All @@ -40,6 +41,7 @@ import {
import type { TApiType, WalletAccount } from "./types";
import PolkadotWalletSelectModal from "./components/PolkadotWalletSelectModal";
import { STORAGE_ADDRESS_KEY } from "./providers/WalletProvider";
import { useEffect } from "react";

const App = () => {
const [opened, { toggle }] = useDisclosure();
Expand Down Expand Up @@ -132,8 +134,15 @@ const App = () => {

const onChangeAccountClick = () => void changeAccount();

const location = useLocation();

useEffect(() => {
if (location.pathname === "/xcm-router" && apiType === "PAPI") {
handleApiSwitch("PJS");
}
}, [location.pathname, apiType]);

const handleApiSwitch = (value: string) => {
console.log("handleApiSwitch", value);
setApiType(value as TApiType);
setSelectedAccount(undefined);
setAccounts([]);
Expand Down Expand Up @@ -179,139 +188,135 @@ const App = () => {
};

return (
<BrowserRouter>
<MantineProvider theme={theme}>
<AccountsModal
isOpen={accountsModalOpened}
onClose={closeAccountsModal}
accounts={accounts}
onAccountSelect={onAccountSelect}
onDisconnect={selectedAccount ? onDisconnect : undefined}
/>
<PolkadotWalletSelectModal
isOpen={walletSelectModalOpened}
onClose={closeWalletSelectModal}
providers={extensions}
onProviderSelect={onWalletSelect}
/>
<AppShell
header={{ height: 60 }}
navbar={{
width: 300,
breakpoint: "sm",
collapsed: { mobile: !opened },
}}
>
<AppShell.Header>
<Group h="100%" px="md" justify="space-between">
<Burger
opened={opened}
onClick={toggle}
hiddenFrom="sm"
size="sm"
/>
<Image src="logo.png" h="100%" p={8} />
<MantineProvider theme={theme}>
<AccountsModal
isOpen={accountsModalOpened}
onClose={closeAccountsModal}
accounts={accounts}
onAccountSelect={onAccountSelect}
onDisconnect={selectedAccount ? onDisconnect : undefined}
/>
<PolkadotWalletSelectModal
isOpen={walletSelectModalOpened}
onClose={closeWalletSelectModal}
providers={extensions}
onProviderSelect={onWalletSelect}
/>
<AppShell
header={{ height: 60 }}
navbar={{
width: 300,
breakpoint: "sm",
collapsed: { mobile: !opened },
}}
>
<AppShell.Header>
<Group h="100%" px="md" justify="space-between">
<Burger
opened={opened}
onClick={toggle}
hiddenFrom="sm"
size="sm"
/>
<Image src="logo.png" h="100%" p={8} />
<Group>
<Group>
<Group>
<SegmentedControl
value={apiType}
onChange={handleApiSwitch}
disabled={!isInitialized}
data={[
{
value: "PJS",
label: (
<Center style={{ gap: 10 }}>
<IconCode
style={{ width: rem(16), height: rem(16) }}
/>
<span>PJS</span>
</Center>
),
},
{
value: "PAPI",
label: (
<Center style={{ gap: 10 }}>
<IconFileCode
style={{ width: rem(16), height: rem(16) }}
/>
<span>PAPI</span>
</Center>
),
},
]}
/>
</Group>
{selectedAccount ? (
<Button
onClick={onChangeAccountClick}
variant="outline"
loading={!isInitialized}
>{`${selectedAccount.meta.name} - (${selectedAccount.meta.source})`}</Button>
) : (
<Button
onClick={onConnectWalletClick}
data-testid="btn-connect-wallet"
loading={!isInitialized}
>
Connect wallet
</Button>
)}
</Group>
</Group>
</AppShell.Header>
<AppShell.Navbar p="md">
<RouterNavLink to="/" style={{ color: "black" }}>
{({ isActive }) => (
<NavLink
component="div"
active={isActive}
label="XCM Router Sandbox"
leftSection={<IconRoute size="1rem" stroke={1.5} />}
style={{ borderRadius: 4 }}
/>
)}
</RouterNavLink>
<RouterNavLink to="/xcm-sdk-sandbox" style={{ color: "black" }}>
{({ isActive }) => (
<NavLink
component="div"
active={isActive}
label="XCM SDK Sandbox"
leftSection={<IconBoxSeam size="1rem" stroke={1.5} />}
style={{ borderRadius: 4 }}
/>
)}
</RouterNavLink>
<RouterNavLink
to="/xcm-analyser-sandbox"
style={{ color: "black" }}
>
{({ isActive }) => (
<NavLink
component="div"
active={isActive}
label="XCM Analyser Sandbox"
leftSection={<IconAnalyze size="1rem" stroke={1.5} />}
style={{ borderRadius: 4 }}
<SegmentedControl
value={apiType}
onChange={handleApiSwitch}
disabled={!isInitialized}
data={[
{
value: "PJS",
label: (
<Center style={{ gap: 10 }}>
<IconCode
style={{ width: rem(16), height: rem(16) }}
/>
<span>PJS</span>
</Center>
),
},
{
value: "PAPI",
disabled:
location.pathname === "/xcm-router" || !isInitialized,
label: (
<Center style={{ gap: 10 }}>
<IconFileCode
style={{ width: rem(16), height: rem(16) }}
/>
<span>PAPI</span>
</Center>
),
},
]}
/>
</Group>
{selectedAccount ? (
<Button
onClick={onChangeAccountClick}
variant="outline"
loading={!isInitialized}
>{`${selectedAccount.meta.name} - (${selectedAccount.meta.source})`}</Button>
) : (
<Button
onClick={onConnectWalletClick}
data-testid="btn-connect-wallet"
loading={!isInitialized}
>
Connect wallet
</Button>
)}
</RouterNavLink>
</AppShell.Navbar>
<AppShell.Main>
<Routes>
<Route path="/" Component={RouterTransferPage} />
<Route path="/xcm-sdk-sandbox" Component={XcmSdkSandbox} />
<Route
path="/xcm-analyser-sandbox"
Component={XcmAnalyserSandbox}
</Group>
</Group>
</AppShell.Header>
<AppShell.Navbar p="md">
<RouterNavLink to="/xcm-sdk" style={{ color: "black" }}>
{({ isActive }) => (
<NavLink
component="div"
active={isActive}
label="XCM SDK Sandbox"
leftSection={<IconBoxSeam size="1rem" stroke={1.5} />}
style={{ borderRadius: 4 }}
/>
)}
</RouterNavLink>
<RouterNavLink to="/xcm-router" style={{ color: "black" }}>
{({ isActive }) => (
<NavLink
component="div"
active={isActive}
label="XCM Router Sandbox"
leftSection={<IconRoute size="1rem" stroke={1.5} />}
style={{ borderRadius: 4 }}
/>
)}
</RouterNavLink>

<RouterNavLink to="/xcm-analyser" style={{ color: "black" }}>
{({ isActive }) => (
<NavLink
component="div"
active={isActive}
label="XCM Analyser Sandbox"
leftSection={<IconAnalyze size="1rem" stroke={1.5} />}
style={{ borderRadius: 4 }}
/>
</Routes>
</AppShell.Main>
</AppShell>
</MantineProvider>
</BrowserRouter>
)}
</RouterNavLink>
</AppShell.Navbar>
<AppShell.Main>
<Routes>
<Route path="/" element={<Navigate to="/xcm-sdk" />} />
<Route path="/xcm-sdk" Component={XcmSdkSandbox} />
<Route path="/xcm-router" Component={RouterTransferPage} />
<Route path="/xcm-analyser" Component={XcmAnalyserSandbox} />
</Routes>
</AppShell.Main>
</AppShell>
</MantineProvider>
);
};

Expand Down
4 changes: 2 additions & 2 deletions apps/playground/src/components/TransferInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const TransferInfo = () => {
const originAddress = formValues.address;
const currency = resolveCurrency(formValues);
if (useApi) {
return await fetchFromApi(
return fetchFromApi(
{
origin: formValues.from,
destination: formValues.to,
Expand All @@ -72,7 +72,7 @@ const TransferInfo = () => {
? await import("@paraspell/sdk/papi")
: await import("@paraspell/sdk");

return await Sdk.getTransferInfo({
return Sdk.getTransferInfo({
origin: formValues.from,
destination: formValues.to,
accountOrigin: originAddress,
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/components/XcmTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const XcmTransfer = () => {
currency: determineCurrency(formValues),
},
api,
apiType === "PJS" ? "/x-transfer-hash" : "/x-transfer-papi",
apiType === "PJS" ? "/x-transfer" : "/x-transfer-papi",
selectedAccount.address,
apiType,
"POST",
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/components/asset-claim/AssetClaim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const AssetClaim = () => {
],
},
api,
apiType === "PJS" ? "/asset-claim-hash" : "/asset-claim-papi",
apiType === "PJS" ? "/asset-claim" : "/asset-claim-papi",
selectedAccount.address,
apiType,
"POST",
Expand Down
10 changes: 6 additions & 4 deletions apps/playground/src/components/assets/AssetsQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const AssetsQueries = () => {
case "HAS_SUPPORT":
return `/assets/${node}/has-support`;
case "PARA_ID":
return `/assets/${node}/para-id`;
return `/nodes/${node}/para-id`;
case "BALANCE_NATIVE":
return apiType === "PAPI"
? `/balance/${node}/native-papi`
Expand Down Expand Up @@ -147,10 +147,12 @@ const AssetsQueries = () => {
const getQueryResult = async (formValues: FormValues): Promise<unknown> => {
const { useApi, func, address } = formValues;
const isBalanceQuery =
func === "BALANCE_FOREIGN" || func === "BALANCE_NATIVE";
func === "BALANCE_FOREIGN" ||
func === "BALANCE_NATIVE" ||
func === "ASSET_BALANCE";
const resolvedCurrency = resolveCurrency(formValues);
if (useApi) {
return await fetchFromApi(
return fetchFromApi(
isBalanceQuery
? {
address,
Expand All @@ -162,7 +164,7 @@ const AssetsQueries = () => {
isBalanceQuery,
);
} else {
return await submitUsingSdk(formValues);
return submitUsingSdk(formValues);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const EthBridgeTransfer = () => {

const handleAccountsChanged = (accounts: string[]) => {
if (accounts.length === 0) {
console.log("Please connect to a wallet.");
setSelectedAccount(null);
setAccounts([]);
} else {
Expand Down Expand Up @@ -123,8 +122,6 @@ const EthBridgeTransfer = () => {
const onAccountSelect = (account: string) => {
setIsAccountModalOpen(false);
setSelectedAccount(account);

console.log("Account selected:", account);
};

useEffect(() => {
Expand Down
Loading

0 comments on commit 973dfde

Please sign in to comment.