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

Add Sui binary version to NetworkSelect #12290

Merged
merged 3 commits into from
Jun 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/core/src/hooks/useGetBinaryVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useRpcClient } from '../api/RpcClientContext';
import { useQuery } from '@tanstack/react-query';

// Current API version is the same as the binary version
export function useGetBinaryVersion() {
const rpc = useRpcClient();
return useQuery({
queryKey: ['binary-version'],
queryFn: () => rpc.getRpcApiVersion(),
});
}
1 change: 1 addition & 0 deletions apps/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ export * from './hooks/useGetCoinBalance';
export * from './utils/hasDisplayData';
export * from './hooks/useMultiGetObjects';
export * from './utils/persistableStorage';
export * from './hooks/useGetBinaryVersion';
4 changes: 3 additions & 1 deletion apps/explorer/src/components/network/Network.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useGetSystemState } from '@mysten/core';
import { useGetSystemState, useGetBinaryVersion } from '@mysten/core';
import { useContext } from 'react';

import { NetworkContext } from '../../context';
Expand All @@ -12,6 +12,7 @@ import { NetworkSelect, type NetworkOption } from '~/ui/header/NetworkSelect';
export default function WrappedNetworkSelect() {
const [network, setNetwork] = useContext(NetworkContext);
const { data } = useGetSystemState();
const { data: binaryVersion } = useGetBinaryVersion();

const networks = [
{ id: Network.MAINNET, label: 'Mainnet' },
Expand All @@ -26,6 +27,7 @@ export default function WrappedNetworkSelect() {
onChange={setNetwork}
networks={networks}
version={data?.protocolVersion}
binaryVersion={binaryVersion}
/>
);
}
11 changes: 8 additions & 3 deletions apps/explorer/src/ui/header/NetworkSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface NetworkSelectProps {
networks: NetworkOption[];
value: string;
version?: number | string;
binaryVersion?: string;
onChange(networkId: string): void;
}

Expand Down Expand Up @@ -141,17 +142,19 @@ function CustomRPCInput({
function NetworkVersion({
label,
version,
binaryVersion,
}: {
label: string;
version: number | string;
binaryVersion: string;
}) {
return (
<div className="flex justify-between px-4 py-2">
<div className="flex flex-col justify-between px-4 py-2">
<Text variant="subtitle/normal" color="steel">
Sui {label}
</Text>
<Text variant="subtitle/normal" color="steel">
v{version}
v{binaryVersion} (Protocol {version})
</Text>
</div>
);
Expand Down Expand Up @@ -224,6 +227,7 @@ export function NetworkSelect({
networks,
value,
version,
binaryVersion,
onChange,
}: NetworkSelectProps) {
const { x, y, reference, floating, strategy } = useFloating({
Expand Down Expand Up @@ -282,13 +286,14 @@ export function NetworkSelect({
close();
}}
/>
{!!value && version ? (
{!!value && version && binaryVersion ? (
<div className="-mx-3 -mb-4 mt-2 rounded-b-lg bg-gray-40">
<NetworkVersion
label={
selected?.label ??
'Custom RPC'
}
binaryVersion={binaryVersion}
version={version}
/>
</div>
Expand Down