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

hotfix(website): use builder provided rpcs for registry requests #1476

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 .github/workflows/commitlint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
validateSingleCommit: false
types: |
hotfix
feat
fix
chore
docs
test
1 change: 1 addition & 0 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"react-syntax-highlighter": "^15.5.0",
"remark-gfm": "^3.0.1",
"simple-url": "^1.1.8",
"solc": "^0.8.17",
"styled-components": "^6.0.7",
"viem": "^2.21.15",
"wagmi": "^2.5.13",
Expand Down
38 changes: 18 additions & 20 deletions packages/website/src/features/Deploy/PublishUtility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { useMutation } from '@tanstack/react-query';
import {
CannonStorage,
DEFAULT_REGISTRY_ADDRESS,
DEFAULT_REGISTRY_CONFIG,
FallbackRegistry,
InMemoryRegistry,
OnChainRegistry,
Expand Down Expand Up @@ -81,7 +81,7 @@ export default function PublishUtility(props: {
viem.isAddressEqual(publisher, wc.data?.account.address)
);

const { transports, getExplorerUrl } = useCannonChains();
const { getChainById, transports, getExplorerUrl } = useCannonChains();

const prepareAndPublishPackage = async (publishChainId: number) => {
if (!wc.data) {
Expand All @@ -90,25 +90,23 @@ export default function PublishUtility(props: {

const [walletAddress] = await wc.data.getAddresses();

const targetRegistry = new FallbackRegistry(
[
new OnChainRegistry({
signer: { address: walletAddress, wallet: wc.data as any },
address: DEFAULT_REGISTRY_ADDRESS,
provider: viem.createPublicClient({
chain: optimism,
transport: transports[optimism.id] || viem.http(),
}) as any, // TODO: fix type
}),
new OnChainRegistry({
signer: { address: walletAddress, wallet: wc.data as any },
address: DEFAULT_REGISTRY_ADDRESS,
provider: viem.createPublicClient({
chain: mainnet,
transport: transports[mainnet.id] || viem.http(),
}) as any, // TODO: fix type
const onChainRegistries = DEFAULT_REGISTRY_CONFIG.map((config) => {
const rpcUrl = config.rpcUrl.find(
(url) => url.startsWith('https://') || url.startsWith('wss://')
);

return new OnChainRegistry({
signer: { address: walletAddress, wallet: wc.data as any },
address: config.address,
provider: viem.createPublicClient({
chain: getChainById(config.chainId),
transport: transports[config.chainId] || viem.http(rpcUrl),
}),
],
});
});

const targetRegistry = new FallbackRegistry(
onChainRegistries,
publishChainId === 10 ? 0 : 1
);

Expand Down
12 changes: 7 additions & 5 deletions packages/website/src/hooks/registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCannonChains } from '@/providers/CannonProvidersProvider';
import { DEFAULT_REGISTRY_ADDRESS, DEFAULT_REGISTRY_CONFIG, OnChainRegistry } from '@usecannon/builder';
import { DEFAULT_REGISTRY_CONFIG, OnChainRegistry } from '@usecannon/builder';
import { useEffect, useState } from 'react';
import * as viem from 'viem';

Expand All @@ -11,18 +11,20 @@ type Publishers = {

export function useCannonPackagePublishers(packageName?: string) {
const [publishers, setPublishers] = useState<Publishers[]>([]);
const { getChainById } = useCannonChains();
const { getChainById, transports } = useCannonChains();

useEffect(() => {
if (!packageName) return setPublishers([]);

const onChainRegistries = DEFAULT_REGISTRY_CONFIG.map((config) => {
const rpcUrl = config.rpcUrl.find((url) => url.startsWith('https://') || url.startsWith('wss://'));

return new OnChainRegistry({
address: DEFAULT_REGISTRY_ADDRESS,
address: config.address,
provider: viem.createPublicClient({
chain: getChainById(config.chainId),
transport: viem.http(),
}) as any, // TODO: fix type
transport: transports[config.chainId] || viem.http(rpcUrl),
}),
});
});

Expand Down
16 changes: 8 additions & 8 deletions packages/website/src/providers/CannonRegistryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { inMemoryRegistry } from '@/helpers/cannon';
import { useCannonChains } from '@/providers/CannonProvidersProvider';
import {
DEFAULT_REGISTRY_ADDRESS,
DEFAULT_REGISTRY_CONFIG,
FallbackRegistry,
OnChainRegistry,
Expand All @@ -21,16 +20,17 @@ type Props = {
};
export const CannonRegistryProvider: React.FC<Props> = ({ children }) => {
const { getChainById, transports } = useCannonChains();
const onChainRegistries = DEFAULT_REGISTRY_CONFIG.map(
(registry) => registry.chainId
).map((chainId: number) => {
const chain = getChainById(chainId);

const onChainRegistries = DEFAULT_REGISTRY_CONFIG.map((config) => {
const rpcUrl = config.rpcUrl.find(
(url) => url.startsWith('https://') || url.startsWith('wss://')
);

return new OnChainRegistry({
address: DEFAULT_REGISTRY_ADDRESS,
address: config.address,
provider: createPublicClient({
chain,
transport: transports[chainId] || http(),
chain: getChainById(config.chainId),
transport: transports[config.chainId] || http(rpcUrl),
}),
});
});
Expand Down
37 changes: 20 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading