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 44a9f32 commit 33b5dc9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 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]>;

0 comments on commit 33b5dc9

Please sign in to comment.