Skip to content

Commit

Permalink
style: run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala committed May 7, 2024
1 parent 09f88c4 commit 44f7187
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 101 deletions.
4 changes: 2 additions & 2 deletions docs/components/KeyPoint.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, PropsWithChildren } from "react";
import { FC, PropsWithChildren } from "react"

export const KeyPoint: FC<PropsWithChildren<{ title: string }>> = ({
title,
Expand All @@ -10,4 +10,4 @@ export const KeyPoint: FC<PropsWithChildren<{ title: string }>> = ({
</div>
<div>{children}</div>
</div>
);
)
11 changes: 5 additions & 6 deletions docs/components/Tabs.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

@media screen and (max-width: 720px) {
.Tabs__root {
border-radius: 0;
margin-left: calc(-1* var(--vocs-space_16));
margin-right: calc(-1* var(--vocs-space_16));
margin-left: calc(-1 * var(--vocs-space_16));
margin-right: calc(-1 * var(--vocs-space_16));
padding-left: var(--vocs-space_16);
padding-right: var(--vocs-space_16);
}

.Tabs__list {
margin-left: calc(-1* var(--vocs-space_16));
margin-right: calc(-1* var(--vocs-space_16));
margin-left: calc(-1 * var(--vocs-space_16));
margin-right: calc(-1 * var(--vocs-space_16));
}
}
}
12 changes: 6 additions & 6 deletions docs/components/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as Tabs from "@radix-ui/react-tabs";
import { PropsWithChildren } from "react";
import "./Tabs.css";
import * as Tabs from "@radix-ui/react-tabs"
import { PropsWithChildren } from "react"
import "./Tabs.css"

export const Root = ({
options,
children,
}: PropsWithChildren<{
options: Record<string, string>;
options: Record<string, string>
}>) => (
<Tabs.Root
className="Tabs__root border rounded bg-[--vocs-color_codeBlockBackground] border-[--vocs-color_codeInlineBorder]"
Expand All @@ -25,7 +25,7 @@ export const Root = ({
</Tabs.List>
{children}
</Tabs.Root>
);
)
export const Content = (props: Tabs.TabsContentProps) => (
<Tabs.Content {...props} />
);
)
26 changes: 10 additions & 16 deletions docs/pages/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,35 +85,29 @@ import {
XcmVersionedXcm,
XcmV2Instruction,
XcmV2MultilocationJunctions,
} from '@polkadot-api/descriptors';
} from "@polkadot-api/descriptors"

// ...

const dotClient = createClient(
scProvider(WellKnownChain.polkadot).relayChain
)
const ksmClient = createClient(
scProvider(WellKnownChain.ksmcc3).relayChain
)
const dotClient = createClient(scProvider(WellKnownChain.polkadot).relayChain)
const ksmClient = createClient(scProvider(WellKnownChain.ksmcc3).relayChain)

const dotApi = dotClient.getTypedApi(dot);
const ksmApi = ksmClient.getTypedApi(ksm);
const dotApi = dotClient.getTypedApi(dot)
const ksmApi = ksmClient.getTypedApi(ksm)

const xcmSendTx = dotApi.tx.XcmPallet.send({
dest: XcmVersionedMultiLocation.V2({
parents: 0,
interior: XcmV2MultilocationJunctions.Here(),
}),
message: XcmVersionedXcm.V2([
XcmV2Instruction.ClearOrigin()
]),
});
message: XcmVersionedXcm.V2([XcmV2Instruction.ClearOrigin()]),
})

const encodedData = await xcmSendTx.getEncodedData();
const encodedData = await xcmSendTx.getEncodedData()

const finalizedCall = await xcmSendTx.signAndSubmit(signer);
const finalizedCall = await xcmSendTx.signAndSubmit(signer)
```

:::info
`getTypedApi` has nearly no cost at runtime, so it can be safely called many times.
:::
:::
6 changes: 5 additions & 1 deletion docs/pages/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Tabs from '../components/Tabs';
import * as Tabs from "../components/Tabs"

# Getting Started

Expand Down Expand Up @@ -49,6 +49,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int

// [!include ~/snippets/gettingStarted.ts:usage]
```

</Tabs.Content>
<Tabs.Content value="sm">
```ts
Expand All @@ -67,6 +68,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int
// [!include ~/snippets/gettingStarted.ts:usage]
```

</Tabs.Content>
<Tabs.Content value="web">
```ts
Expand All @@ -80,6 +82,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int
// [!include ~/snippets/gettingStarted.ts:usage]
```

</Tabs.Content>
<Tabs.Content value="node">
```ts
Expand All @@ -93,5 +96,6 @@ Now you can create a PolkadotClient with a provider of your choice and start int
// [!include ~/snippets/gettingStarted.ts:usage]
```

</Tabs.Content>
</Tabs.Root>
10 changes: 6 additions & 4 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
layout: landing
content:
content:
width: 60rem
---

import { HomePage } from 'vocs/components'
import { KeyPoint } from '../components/KeyPoint';
import { HomePage } from "vocs/components"
import { KeyPoint } from "../components/KeyPoint"

<HomePage.Root>
<div className="flex justify-between w-full flex-col md:flex-row gap-4">
Expand All @@ -19,6 +19,7 @@ import { KeyPoint } from '../components/KeyPoint';
</div>

<HomePage.InstallPackage name="polkadot-api" type="i" />

</div>

<div className="flex gap-2 flex-col md:flex-row mt-8">
Expand Down Expand Up @@ -47,5 +48,6 @@ import { KeyPoint } from '../components/KeyPoint';
-**Promise-based and Observable-based APIs**: use the one that best suit your needs and/or coding style.
- 🔑 Use **signers** from your browser extension, or from a private key.
- 🧩 Easy integration with **PJS-based extensions**.

</div>
</HomePage.Root>
</HomePage.Root>
22 changes: 11 additions & 11 deletions docs/pages/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ Polkadot-API has a subpackage `polkadot-api/logs-provider` that can be used to c

```ts
// 1. recording logs
import { createClient } from 'polkadot-api';
import { withLogsRecorder } from 'polkadot-api/logs-provider';
import { WebSocketProvider } from 'polkadot-api/ws-provider/node';
import { createClient } from "polkadot-api"
import { withLogsRecorder } from "polkadot-api/logs-provider"
import { WebSocketProvider } from "polkadot-api/ws-provider/node"

const wsProvider = WebSocketProvider("wss://example.url");
const wsProvider = WebSocketProvider("wss://example.url")
// Using console.log to output each line, but you could e.g. write it directly to a
// file or push into an array
const provider = withLogsRecorder(line => console.log(line), wsProvider);
const client = createClient(provider);
const provider = withLogsRecorder((line) => console.log(line), wsProvider)
const client = createClient(provider)
```

```ts
// 2. replaying logs
import { createClient } from 'polkadot-api';
import { logsProvider } from 'polkadot-api/logs-provider';
import logs from './readLogs';
import { createClient } from "polkadot-api"
import { logsProvider } from "polkadot-api/logs-provider"
import logs from "./readLogs"

const provider = logsProvider(logs);
const client = createClient(provider);
const provider = logsProvider(logs)
const client = createClient(provider)
```

This can be useful to debug specific scenarios without needing to depend on an external source.
24 changes: 12 additions & 12 deletions docs/pages/recipes/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ Now on the code you can create two typed APIs for the same chain, and then use t
To make it clear, the `client` is connected to one chain that's using one specific version of the runtime. You can create multiple typedApis for that connection, which just give you the types for each possible version of the runtime. Then you can use runtime compatibility checks to perform the operation on the correct descriptor.

```ts
import { createClient } from 'polkadot-api';
import { dot, nextDot, MultiAddress } from '@polkadot-api/descriptors';
import { chainSpec } from "polkadot-api/chains/polkadot";
import { startFromWorker } from "polkadot-api/smoldot/from-worker";
import SmWorker from "polkadot-api/smoldot/worker?worker";
import { createClient } from "polkadot-api"
import { dot, nextDot, MultiAddress } from "@polkadot-api/descriptors"
import { chainSpec } from "polkadot-api/chains/polkadot"
import { startFromWorker } from "polkadot-api/smoldot/from-worker"
import SmWorker from "polkadot-api/smoldot/worker?worker"

const smoldot = startFromWorker(new SmWorker());
const chain = await smoldot.addChain({ chainSpec });
const client = createClient(getSmProvider(chain));
const smoldot = startFromWorker(new SmWorker())
const chain = await smoldot.addChain({ chainSpec })
const client = createClient(getSmProvider(chain))

const dotApi = client.getTypedApi(dot);
const nextApi = client.getTypedApi(nextDot);
const dotApi = client.getTypedApi(dot)
const nextApi = client.getTypedApi(nextDot)

function performTransfer() {
// check if we're running on the next version to run that first
if (await nextApi.tx.Balances.new_fancy_transfer.isCompatible()) {
nextApi.tx.Balances.new_fancy_transfer({
dest: MultiAddress.Id("addr"),
value: 5n
value: 5n,
})
} else {
// Otherwise perform the transfer the old way with the old descriptors
dotApi.tx.Balances.transfer_keep_alive({
dest: MultiAddress.Id("addr"),
value: 5n
value: 5n,
})
}
}
Expand Down
26 changes: 14 additions & 12 deletions docs/pages/signers.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ This interface is generic to signing transactions for the chain.
If you want to use a compatible extension as a signer, Polkadot-API has a subpath with a couple of utilities to help with this: `polkadot-api/pjs-signer`.

```ts
import { getInjectedExtensions, connectInjectedExtension } from 'polkadot-api/pjs-signer';
import {
getInjectedExtensions,
connectInjectedExtension,
} from "polkadot-api/pjs-signer"

// Get the list of installed extensions
const extensions: string[] = getInjectedExtensions();
const extensions: string[] = getInjectedExtensions()

// Connect to an extension
const selectedExtension: InjectedExtension = await connectInjectedExtension(extensions[0]);
const selectedExtension: InjectedExtension = await connectInjectedExtension(
extensions[0],
)

// Get accounts registered in the extension
const accounts: InjectedPolkadotAccount[] = selectedExtension.getAccounts();
const accounts: InjectedPolkadotAccount[] = selectedExtension.getAccounts()

// The signer for each account is in the `polkadotSigner` property of `InjectedPolkadotAccount`
const polkadotSigner = accounts[0].polkadotSigner;
const polkadotSigner = accounts[0].polkadotSigner
```

## `PolkadotSigner` from generic signing function
Expand Down Expand Up @@ -75,11 +80,8 @@ const derive = sr25519CreateDerive(miniSecret)
const keypair = derive("//Alice")
const polkadotSigner = getPolkadotSigner(
hdkdKeyPair.publicKey,
"Sr25519",
hdkdKeyPair.sign
);
hdkdKeyPair.publicKey,
"Sr25519",
hdkdKeyPair.sign,
)
```



Loading

0 comments on commit 44f7187

Please sign in to comment.