Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: rename "aggregator" to "provider" #293

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/curly-tigers-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@reactive-dot/react": minor
"@reactive-dot/core": minor
"@reactive-dot/vue": minor
---

BREAKING: renamed "aggregator" to "provider".
4 changes: 2 additions & 2 deletions apps/docs/docs/getting-started/connect-wallets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ Additional dependencies are required if you use any of be bellow wallet type.

```ts title="config.ts"
import { defineConfig } from "@reactive-dot/core";
import { InjectedWalletAggregator } from "@reactive-dot/core/wallets.js";
import { InjectedWalletProvider } from "@reactive-dot/core/wallets.js";
import { LedgerWallet } from "@reactive-dot/wallet-ledger";
import { WalletConnect } from "@reactive-dot/wallet-walletconnect";

export const config = defineConfig({
// ...
wallets: [
new InjectedWalletAggregator(),
new InjectedWalletProvider(),
new LedgerWalet(),
new WalletConnect({
projectId: "WALLET_CONNECT_PROJECT_ID",
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/docs/getting-started/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ For more information on metadata syncing and type generation, please refer to th
// `dot` is the name we gave to `npx papi add`
import { dot } from "@polkadot-api/descriptors";
import { defineConfig } from "@reactive-dot/core";
import { InjectedWalletAggregator } from "@reactive-dot/core/wallets.js";
import { InjectedWalletProvider } from "@reactive-dot/core/wallets.js";
import { chainSpec } from "polkadot-api/chains/polkadot";
import { getSmProvider } from "polkadot-api/sm-provider";
import { startFromWorker } from "polkadot-api/smoldot/from-worker";
Expand All @@ -91,7 +91,7 @@ export const config = defineConfig({
provider: getSmProvider(smoldot.addChain({ chainSpec })),
},
},
wallets: [new InjectedWalletAggregator()],
wallets: [new InjectedWalletProvider()],
});
```

Expand All @@ -106,7 +106,7 @@ export const config = defineConfig({
import { dot } from "@polkadot-api/descriptors";
import { getWsProvider } from "@polkadot-api/ws-provider/web";
import { defineConfig } from "@reactive-dot/core";
import { InjectedWalletAggregator } from "@reactive-dot/core/wallets.js";
import { InjectedWalletProvider } from "@reactive-dot/core/wallets.js";

export const config = defineConfig({
chains: {
Expand All @@ -115,7 +115,7 @@ export const config = defineConfig({
provider: getWsProvider("wss://polkadot-rpc.publicnode.com"),
},
},
wallets: [new InjectedWalletAggregator()],
wallets: [new InjectedWalletProvider()],
});
```

Expand Down
4 changes: 2 additions & 2 deletions examples/react/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { kusama, polkadot, westend } from "@polkadot-api/descriptors";
import { defineConfig } from "@reactive-dot/core";
import { InjectedWalletAggregator } from "@reactive-dot/core/wallets.js";
import { InjectedWalletProvider } from "@reactive-dot/core/wallets.js";
import { LedgerWallet } from "@reactive-dot/wallet-ledger";
import { WalletConnect } from "@reactive-dot/wallet-walletconnect";
import { getSmProvider } from "polkadot-api/sm-provider";
Expand Down Expand Up @@ -40,7 +40,7 @@ export const config = defineConfig({
},
},
wallets: [
new InjectedWalletAggregator({ originName: "ReactiveDOT React Example" }),
new InjectedWalletProvider({ originName: "ReactiveDOT React Example" }),
new LedgerWallet(),
new WalletConnect({
projectId: "68f5b7e972a51cf379b127f51a791c34",
Expand Down
4 changes: 2 additions & 2 deletions examples/vue/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { kusama, polkadot, westend } from "@polkadot-api/descriptors";
import { defineConfig } from "@reactive-dot/core";
import { InjectedWalletAggregator } from "@reactive-dot/core/wallets.js";
import { InjectedWalletProvider } from "@reactive-dot/core/wallets.js";
import { getSmProvider } from "polkadot-api/sm-provider";
import { startFromWorker } from "polkadot-api/smoldot/from-worker";

Expand Down Expand Up @@ -38,6 +38,6 @@ export const config = defineConfig({
},
},
wallets: [
new InjectedWalletAggregator({ originName: "ReactiveDOT Vue Example" }),
new InjectedWalletProvider({ originName: "ReactiveDOT Vue Example" }),
],
});
20 changes: 10 additions & 10 deletions packages/core/src/actions/aggregate-wallets.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import type { MaybeAsync } from "../types.js";
import { toObservable } from "../utils/to-observable.js";
import type { WalletAggregator } from "../wallets/index.js";
import type { WalletProvider } from "../wallets/index.js";
import { combineLatest, from, of } from "rxjs";
import { map, switchMap } from "rxjs/operators";

export function aggregateWallets(aggregators: MaybeAsync<WalletAggregator[]>) {
return toObservable(aggregators).pipe(
switchMap((aggregators) => {
if (aggregators.length === 0) {
export function aggregateWallets(providers: MaybeAsync<WalletProvider[]>) {
return toObservable(providers).pipe(
switchMap((providers) => {
if (providers.length === 0) {
return of([]);
}

return from(
Promise.all(
aggregators.map(async (aggregator) => {
await aggregator.scan();
return aggregator;
providers.map(async (provider) => {
await provider.scan();
return provider;
}),
),
);
}),
switchMap((aggregators) =>
combineLatest(aggregators.map((aggregator) => aggregator.wallets$)),
switchMap((providers) =>
combineLatest(providers.map((provider) => provider.wallets$)),
),
map((wallets) => wallets.flat()),
);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Gettable } from "./types.js";
import type { Wallet, WalletAggregator } from "./wallets/index.js";
import type { Wallet, WalletProvider } from "./wallets/index.js";
import type { JsonRpcProvider } from "@polkadot-api/json-rpc-provider";
import type { ChainDefinition } from "polkadot-api";

Expand All @@ -18,7 +18,7 @@ export type Config<
> = {
readonly chains: TChains;
readonly targetChains?: TTargetChainIds;
readonly wallets?: ReadonlyArray<WalletAggregator | Wallet>;
readonly wallets?: ReadonlyArray<WalletProvider | Wallet>;
};

export function defineConfig<
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/wallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ export type {
PolkadotSignerAccount,
WalletAccount,
} from "./account.js";
export { WalletAggregator } from "./aggregator.js";
export { WalletProvider } from "./provider.js";
export { DeepLinkWallet } from "./deep-link-wallet.js";
export { initializeWallets } from "./initialize-wallets.js";
export { InjectedWalletAggregator } from "./injected/aggregator.js";
export { InjectedWalletProvider } from "./injected/provider.js";
export { InjectedWallet } from "./injected/wallet.js";
export { LocalWallet } from "./local-wallet.js";
export { Wallet, type WalletOptions } from "./wallet.js";
12 changes: 6 additions & 6 deletions packages/core/src/wallets/initialize-wallets.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { WalletAggregator } from "./aggregator.js";
import { WalletProvider } from "./provider.js";
import type { Wallet } from "./wallet.js";

export async function initializeWallets(
walletsOrAggregators: Array<Wallet | WalletAggregator>,
walletsOrProviders: Array<Wallet | WalletProvider>,
) {
const wallets = (
await Promise.all(
walletsOrAggregators.map((walletOrAggregator) =>
walletOrAggregator instanceof WalletAggregator
? walletOrAggregator.scan()
: [walletOrAggregator],
walletsOrProviders.map((walletOrProvider) =>
walletOrProvider instanceof WalletProvider
? walletOrProvider.scan()
: [walletOrProvider],
),
)
).flat();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { WalletAggregator } from "../aggregator.js";
import { WalletProvider } from "../provider.js";
import { InjectedWallet, type InjectedWalletOptions } from "./wallet.js";
import { getInjectedExtensions } from "polkadot-api/pjs-signer";
import { BehaviorSubject } from "rxjs";
import { map } from "rxjs/operators";

export class InjectedWalletAggregator extends WalletAggregator {
export class InjectedWalletProvider extends WalletProvider {
constructor(private readonly options?: InjectedWalletOptions) {
super();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Wallet } from "./wallet.js";
import type { Observable } from "rxjs";

export abstract class WalletAggregator {
export abstract class WalletProvider {
abstract scan(): Wallet[] | Promise<Wallet[]>;

abstract readonly wallets$: Observable<Wallet[]>;
Expand Down
11 changes: 5 additions & 6 deletions packages/react/src/hooks/use-wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type Config,
getConnectedWallets,
} from "@reactive-dot/core";
import { Wallet, WalletAggregator } from "@reactive-dot/core/wallets.js";
import { Wallet, WalletProvider } from "@reactive-dot/core/wallets.js";
import { atom, useAtomValue } from "jotai";
import { atomWithObservable } from "jotai/utils";

Expand All @@ -27,13 +27,12 @@ export function useConnectedWallets() {
return useAtomValue(connectedWalletsAtom(useConfig()));
}

const aggregatorWalletsAtom = atomFamilyWithErrorCatcher(
const providerWalletsAtom = atomFamilyWithErrorCatcher(
(config: Config, withErrorCatcher) =>
withErrorCatcher(atomWithObservable)(() =>
aggregateWallets(
config.wallets?.filter(
(walletOrAggregator) =>
walletOrAggregator instanceof WalletAggregator,
(walletOrProvider) => walletOrProvider instanceof WalletProvider,
) ?? [],
),
),
Expand All @@ -46,9 +45,9 @@ export const walletsAtom = atomFamilyWithErrorCatcher(
(config: Config, withErrorCatcher) =>
withErrorCatcher(atom)(async (get) => [
...(config.wallets?.filter(
(walletOrAggregator) => walletOrAggregator instanceof Wallet,
(walletOrProvider) => walletOrProvider instanceof Wallet,
) ?? []),
...(await get(aggregatorWalletsAtom(config))),
...(await get(providerWalletsAtom(config))),
]),
);

Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/composables/use-wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAsyncData } from "./use-async-data.js";
import { useConfig } from "./use-config.js";
import { useLazyValue } from "./use-lazy-value.js";
import { aggregateWallets, getConnectedWallets } from "@reactive-dot/core";
import { Wallet, WalletAggregator } from "@reactive-dot/core/wallets.js";
import { Wallet, WalletProvider } from "@reactive-dot/core/wallets.js";
import { map } from "rxjs/operators";

/**
Expand All @@ -23,7 +23,7 @@ export function useWalletsObservable() {
return useLazyValue(["wallets"], () =>
aggregateWallets(
config.value.wallets?.filter(
(wallet) => wallet instanceof WalletAggregator,
(wallet) => wallet instanceof WalletProvider,
) ?? [],
).pipe(
map((aggregatedWallets) => [
Expand Down