-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use alchemy transport in createConfig
- Loading branch information
Showing
25 changed files
with
431 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
**/dist/* | ||
examples/**/* | ||
site/.vitepress/cache/**/* | ||
.nx/* | ||
.github/* | ||
/.nx/cache | ||
/.nx/cache | ||
|
||
/examples/* | ||
!/examples/ui-demo | ||
/examples/ui-demo/.next/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import type { AlchemyTransport } from "@account-kit/infra"; | ||
import { alchemy, type AlchemyTransport } from "@account-kit/infra"; | ||
import { ChainNotFoundError } from "../errors.js"; | ||
import type { AlchemyAccountsConfig } from "../types"; | ||
|
||
export function getAlchemyTransport( | ||
config: AlchemyAccountsConfig | ||
): AlchemyTransport { | ||
return config.store.getState().transport; | ||
const { chain, connections } = config.store.getState(); | ||
if (!connections.has(chain.id)) { | ||
throw new ChainNotFoundError(chain); | ||
} | ||
|
||
return alchemy(connections.get(chain.id)!.transport); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { alchemy, arbitrumSepolia, sepolia } from "@account-kit/infra"; | ||
import { AlchemySignerStatus } from "@account-kit/signer"; | ||
import { createConfig } from "../createConfig.js"; | ||
import { | ||
convertSignerStatusToState, | ||
createDefaultAccountState, | ||
} from "../store/store.js"; | ||
import { setChain } from "./setChain.js"; | ||
import { watchBundlerClient } from "./watchBundlerClient.js"; | ||
|
||
describe("watchBundlerClient", () => { | ||
it("should not fire the callback if transport or chain didn't change", () => { | ||
const config = givenConfig(); | ||
const onChange = vi.fn(); | ||
|
||
watchBundlerClient(config)(onChange); | ||
|
||
config.store.setState({ | ||
signerStatus: convertSignerStatusToState( | ||
AlchemySignerStatus.AWAITING_EMAIL_AUTH | ||
), | ||
}); | ||
|
||
expect(onChange).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should fire the callback if chain changed", async () => { | ||
const config = givenConfig(); | ||
const onChange = vi.fn(); | ||
|
||
watchBundlerClient(config)(onChange); | ||
|
||
await setChain(config, arbitrumSepolia); | ||
|
||
expect(onChange).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should not fire if the chain id is the same", async () => { | ||
const config = givenConfig(); | ||
const onChange = vi.fn(); | ||
|
||
watchBundlerClient(config)(onChange); | ||
|
||
await setChain(config, sepolia); | ||
|
||
expect(onChange).not.toHaveBeenCalled(); | ||
}); | ||
|
||
const givenConfig = () => { | ||
const config = createConfig({ | ||
chain: sepolia, | ||
chains: [{ chain: sepolia }, { chain: arbitrumSepolia }], | ||
transport: alchemy({ apiKey: "AN_API_KEY" }), | ||
}); | ||
|
||
config.store.setState({ | ||
accounts: createDefaultAccountState([sepolia, arbitrumSepolia]), | ||
}); | ||
|
||
return config; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.