Skip to content

Commit

Permalink
feat: initialize wallets on plugin init
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed Oct 16, 2024
1 parent 084b032 commit d7f128f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/vue/src/composables/use-wallet-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAsyncAction } from "./use-async-action.js";
import { useWalletsObservable } from "./use-wallets.js";
import { connectWallet } from "@reactive-dot/core";
import type { Wallet } from "@reactive-dot/core/wallets.js";
import { lastValueFrom } from "rxjs";
import { firstValueFrom } from "rxjs";

/**
* Composable for connecting wallets
Expand All @@ -19,7 +19,7 @@ export function useWalletConnector(wallets?: Wallet | Wallet[]) {
const walletsToConnect =
wallets ??
composableWallets ??
(await lastValueFrom(walletsObservable.value));
(await firstValueFrom(walletsObservable.value));

await connectWallet(walletsToConnect);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/composables/use-wallet-disconnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAsyncAction } from "./use-async-action.js";
import { useConnectedWalletsObservable } from "./use-wallets.js";
import { disconnectWallet } from "@reactive-dot/core";
import type { Wallet } from "@reactive-dot/core/wallets.js";
import { lastValueFrom } from "rxjs";
import { firstValueFrom } from "rxjs";

/**
* Composable for disconnecting wallets
Expand All @@ -19,7 +19,7 @@ export function useWalletDisconnector(wallets?: Wallet | Wallet[]) {
const walletsToDisconnect =
wallets ??
composableWallets ??
(await lastValueFrom(connectedWalletsObservable.value));
(await firstValueFrom(connectedWalletsObservable.value));

await disconnectWallet(walletsToDisconnect);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/composables/use-wallets-initializer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAsyncAction } from "./use-async-action.js";
import { useWalletsObservable } from "./use-wallets.js";
import { initializeWallets } from "@reactive-dot/core/wallets.js";
import { lastValueFrom } from "rxjs";
import { firstValueFrom } from "rxjs";

/**
* Composable for initializing wallets.
Expand All @@ -12,6 +12,6 @@ export function useWalletsInitializer() {
const walletsObservable = useWalletsObservable();

return useAsyncAction(async () =>
initializeWallets(await lastValueFrom(walletsObservable.value)),
initializeWallets(await firstValueFrom(walletsObservable.value)),
);
}
4 changes: 4 additions & 0 deletions packages/vue/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useWalletsInitializer } from "./composables/use-wallets-initializer.js";
import { configKey, lazyValuesKey } from "./keys.js";
import type { Config } from "@reactive-dot/core";
import { type Plugin } from "vue";
Expand All @@ -7,5 +8,8 @@ export const ReactiveDotPlugin = {
app.provide("foo", "bar");
app.provide(configKey, config);
app.provide(lazyValuesKey, new Map());
app.runWithContext(() => {
useWalletsInitializer().execute();
});
},
} satisfies Plugin<[Config]>;
4 changes: 2 additions & 2 deletions packages/wallet-ledger/src/ledger-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
LocalWallet,
type PolkadotSignerAccount,
} from "@reactive-dot/core/wallets.js";
import { BehaviorSubject, lastValueFrom } from "rxjs";
import { BehaviorSubject, firstValueFrom } from "rxjs";
import { map, skip } from "rxjs/operators";

type LedgerAccount = {
Expand Down Expand Up @@ -111,7 +111,7 @@ export class LedgerWallet extends LocalWallet<LedgerAccount, "accounts"> {
}

getAccounts() {
return lastValueFrom(this.accounts$);
return firstValueFrom(this.accounts$);
}

accountStore = {
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet-walletconnect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
IUniversalProvider,
UniversalProviderOpts,
} from "@walletconnect/universal-provider";
import { BehaviorSubject, lastValueFrom } from "rxjs";
import { BehaviorSubject, firstValueFrom } from "rxjs";
import { map } from "rxjs/operators";

export class WalletConnect extends DeepLinkWallet {
Expand Down Expand Up @@ -217,7 +217,7 @@ export class WalletConnect extends DeepLinkWallet {
);

getAccounts() {
return lastValueFrom(this.accounts$);
return firstValueFrom(this.accounts$);
}

async #getModal() {
Expand Down

0 comments on commit d7f128f

Please sign in to comment.