Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion src/components/cards/NavMenuCard/NavMenuCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ function NavMenuCard() {
// const arBalance = await queryClient.fetchQuery(
// buildARBalanceQuery({
// address: walletAddress,
// provider: arweaveDataProvider,
// meta: [gateway],
// }),
// );
Expand Down
29 changes: 12 additions & 17 deletions src/components/devtools/ArNSRegistrySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
ARIO_MAINNET_PROCESS_ID,
ARIO_TESTNET_PROCESS_ID,
} from '@ar.io/sdk/web';
import { ArweaveCompositeDataProvider } from '@src/services/arweave/ArweaveCompositeDataProvider';
import { SimpleArweaveDataProvider } from '@src/services/arweave/SimpleArweaveDataProvider';
import { useGlobalState } from '@src/state/contexts/GlobalState';
import { useWalletState } from '@src/state/contexts/WalletState';
import { VALIDATION_INPUT_TYPES } from '@src/types';
import { isArweaveTransactionID } from '@src/utils';
import {
isArweaveTransactionID,
validateArweaveAddress,
validateArweaveId,
} from '@src/utils';
import { Collapse, Space } from 'antd';
import Arweave from 'arweave';
import { useEffect, useState } from 'react';
Expand All @@ -22,7 +24,7 @@ const Panel = Collapse.Panel;

function ArNSRegistrySettings() {
const [
{ arweaveDataProvider, arioProcessId, aoClient, gateway, turboNetwork },
{ arioProcessId, aoClient, gateway, turboNetwork },
dispatchGlobalState,
] = useGlobalState();
const [{ wallet }] = useWalletState();
Expand All @@ -35,7 +37,7 @@ function ArNSRegistrySettings() {
setRegistryAddress(arioProcessId?.toString());
}, [arioProcessId]);

function confirmSetting(id: string) {
async function confirmSetting(id: string) {
if (isArweaveTransactionID(id)) {
dispatchGlobalState({
type: 'setIoProcessId',
Expand All @@ -59,16 +61,11 @@ function ArNSRegistrySettings() {
host: gateway,
protocol: 'https',
});
const arweaveDataProvider = new SimpleArweaveDataProvider(arweave);

const provider = new ArweaveCompositeDataProvider({
contract: arIOContract,
arweave: arweaveDataProvider,
});

const blockHeight = (await arweave.blocks.getCurrent()).height;
Copy link
Contributor Author

@dtfiedler dtfiedler Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use useArweaveBlockHeight

dispatchGlobalState({ type: 'setBlockHeight', payload: blockHeight });
dispatchGlobalState({
type: 'setGateway',
payload: { gateway, provider },
payload: { gateway },
});
}
}
Expand Down Expand Up @@ -165,12 +162,10 @@ function ArNSRegistrySettings() {
}
validationPredicates={{
[VALIDATION_INPUT_TYPES.ARWEAVE_ID]: {
fn: (id: string) =>
arweaveDataProvider.validateArweaveId(id),
fn: (id: string) => validateArweaveId(id),
},
[VALIDATION_INPUT_TYPES.ARWEAVE_ADDRESS]: {
fn: (id: string) =>
arweaveDataProvider.validateArweaveAddress(id),
fn: (id: string) => validateArweaveAddress(id),
required: false,
},
}}
Expand Down
6 changes: 2 additions & 4 deletions src/components/forms/DomainSettings/DescriptionRow.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ValidationInput from '@src/components/inputs/text/ValidationInput/ValidationInput';
import ConfirmTransactionModal from '@src/components/modals/ConfirmTransactionModal/ConfirmTransactionModal';
import { useGlobalState } from '@src/state/contexts/GlobalState';
import {
ANT_INTERACTION_TYPES,
ContractInteraction,
VALIDATION_INPUT_TYPES,
} from '@src/types';
import { validateArweaveId } from '@src/utils';
import eventEmitter from '@src/utils/events';
import { Skeleton } from 'antd';
import { useEffect, useState } from 'react';
Expand All @@ -25,7 +25,6 @@ export default function DescriptionRow({
const [newDescription, setNewDescription] = useState<string>(
description ?? '',
);
const [{ arweaveDataProvider }] = useGlobalState();
const [showModal, setShowModal] = useState<boolean>(false);

useEffect(() => {
Expand Down Expand Up @@ -76,8 +75,7 @@ export default function DescriptionRow({
setValue={(e) => setNewDescription(e)}
validationPredicates={{
[VALIDATION_INPUT_TYPES.ARWEAVE_ID]: {
fn: (id: string) =>
arweaveDataProvider.validateArweaveId(id),
fn: (id: string) => validateArweaveId(id),
},
}}
maxCharLength={(str) => str.length <= 512}
Expand Down
6 changes: 2 additions & 4 deletions src/components/forms/DomainSettings/LogoRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import ArweaveID, {
} from '@src/components/layout/ArweaveID/ArweaveID';
import ConfirmTransactionModal from '@src/components/modals/ConfirmTransactionModal/ConfirmTransactionModal';
import { ArweaveTransactionID } from '@src/services/arweave/ArweaveTransactionID';
import { useGlobalState } from '@src/state/contexts/GlobalState';
import {
ANT_INTERACTION_TYPES,
ContractInteraction,
VALIDATION_INPUT_TYPES,
} from '@src/types';
import { validateArweaveId } from '@src/utils';
import { isArweaveTransactionID } from '@src/utils';
import { ARNS_TX_ID_ENTRY_REGEX } from '@src/utils/constants';
import eventEmitter from '@src/utils/events';
Expand All @@ -29,7 +29,6 @@ export default function LogoRow({
}) {
const [editing, setEditing] = useState<boolean>(false);
const [newLogoTxId, setNewLogoTxId] = useState<string>(logoTxId ?? '');
const [{ arweaveDataProvider }] = useGlobalState();
const [showModal, setShowModal] = useState<boolean>(false);

useEffect(() => {
Expand Down Expand Up @@ -86,8 +85,7 @@ export default function LogoRow({
setValue={(e) => setNewLogoTxId(e)}
validationPredicates={{
[VALIDATION_INPUT_TYPES.ARWEAVE_ID]: {
fn: (id: string) =>
arweaveDataProvider.validateArweaveId(id),
fn: (id: string) => validateArweaveId(id),
},
}}
maxCharLength={(str) => str.length <= 43}
Expand Down
6 changes: 2 additions & 4 deletions src/components/forms/DomainSettings/TargetIDRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import ArweaveID, {
} from '@src/components/layout/ArweaveID/ArweaveID';
import ConfirmTransactionModal from '@src/components/modals/ConfirmTransactionModal/ConfirmTransactionModal';
import { ArweaveTransactionID } from '@src/services/arweave/ArweaveTransactionID';
import { useGlobalState } from '@src/state/contexts/GlobalState';
import {
ANT_INTERACTION_TYPES,
ContractInteraction,
VALIDATION_INPUT_TYPES,
} from '@src/types';
import { validateArweaveId } from '@src/utils';
import { isArweaveTransactionID } from '@src/utils';
import { ARNS_TX_ID_ENTRY_REGEX } from '@src/utils/constants';
import eventEmitter from '@src/utils/events';
Expand All @@ -29,7 +29,6 @@ export default function TargetIDRow({
}) {
const [editing, setEditing] = useState<boolean>(false);
const [newTargetId, setNewTargetId] = useState<string>(targetId ?? '');
const [{ arweaveDataProvider }] = useGlobalState();
const [showModal, setShowModal] = useState<boolean>(false);

useEffect(() => {
Expand Down Expand Up @@ -86,8 +85,7 @@ export default function TargetIDRow({
setValue={(e) => setNewTargetId(e)}
validationPredicates={{
[VALIDATION_INPUT_TYPES.ARWEAVE_ID]: {
fn: (id: string) =>
arweaveDataProvider.validateArweaveId(id),
fn: (id: string) => validateArweaveId(id),
},
}}
maxCharLength={(str) => str.length <= 43}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ANT, AOProcess, AoArNSNameData } from '@ar.io/sdk/web';
import Tooltip from '@src/components/Tooltips/Tooltip';
import { validateArweaveId } from '@src/utils';
import { buildArNSRecordsQuery, queryClient } from '@src/utils/network';
import { Pagination, PaginationProps } from 'antd';
import { useEffect, useRef, useState } from 'react';

Expand Down Expand Up @@ -31,7 +33,7 @@
}: {
selectedTokenCallback: (id: ArweaveTransactionID | undefined) => void;
}) {
const [{ arweaveDataProvider, antAoClient, hyperbeamUrl }] = useGlobalState();

Check failure on line 36 in src/components/inputs/text/NameTokenSelector/NameTokenSelector.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'arweaveDataProvider' is assigned a value but never used

Check failure on line 36 in src/components/inputs/text/NameTokenSelector/NameTokenSelector.tsx

View workflow job for this annotation

GitHub Actions / build_and_test / lint_test_build

'arweaveDataProvider' is assigned a value but never used
const [{ walletAddress }] = useWalletState();

const [searchText, setSearchText] = useState<string>();
Expand Down Expand Up @@ -146,11 +148,12 @@
}

const processIds = fetchedprocessIds.concat(validImports);
const associatedRecords = await arweaveDataProvider.getRecords({
filters: {
processId: processIds,
},
});
const associatedRecords = await queryClient.fetchQuery(
buildArNSRecordsQuery({
arioContract,
meta: [arioProcessId.toString()],
}),
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: revert this change back


const contracts: {
processId: ArweaveTransactionID;
Expand Down Expand Up @@ -377,7 +380,7 @@
validationPredicates={{
[VALIDATION_INPUT_TYPES.ARWEAVE_ID]: {
fn: (id: string) => {
return arweaveDataProvider.validateArweaveId(id);
return validateArweaveId(id);
},
},
}}
Expand Down
26 changes: 7 additions & 19 deletions src/components/layout/ArPrice/ArPrice.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
import { useEffect, useState } from 'react';
import { useArPrice } from '@src/hooks';
import { useEffect } from 'react';

import { useGlobalState } from '../../../state/contexts/GlobalState';
import eventEmitter from '../../../utils/events';

function ArPrice({ dataSize }: { dataSize: number }) {
const [{ arweaveDataProvider }] = useGlobalState();
const { data, error } = useArPrice(dataSize);

const [price, setPrice] = useState(0);
useEffect(() => {
getPrice();
}, [dataSize]);

async function getPrice() {
const result = await arweaveDataProvider.getArPrice(dataSize);
try {
if (!result) {
throw new Error('Could not get price on gas fee');
}
setPrice(result);
} catch (error: any) {
eventEmitter.emit(error);
setPrice(0);
if (error) {
eventEmitter.emit('error', error);
}
}
}, [error]);

return <>{`${price.toPrecision(8)} AR`}</>;
return <>{`${(data ?? 0).toPrecision(8)} AR`}</>;
}

export default ArPrice;
16 changes: 10 additions & 6 deletions src/components/layout/BlockHeightCounter/BlockHeightCounter.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useArweaveBlockHeight } from '@src/hooks';
import Countdown from 'antd/lib/statistic/Countdown';
import { ReactNode, useEffect, useState } from 'react';

Expand All @@ -10,17 +11,20 @@ const BlockHeightCounter = ({
}: {
prefixText?: ReactNode;
}) => {
const [
{ blockHeight, lastBlockUpdateTimestamp, arweaveDataProvider },
dispatchGlobalState,
] = useGlobalState();
const [{ blockHeight, lastBlockUpdateTimestamp }, dispatchGlobalState] =
useGlobalState();
const { refetch } = useArweaveBlockHeight();

const [timeUntilUpdate, setTimeUntilUpdate] = useState<number>(0);

const updateBlockHeight = async () => {
try {
const blockHeight = await arweaveDataProvider.getCurrentBlockHeight();
dispatchGlobalState({ type: 'setBlockHeight', payload: blockHeight });
const blockHeight = await refetch();
if (blockHeight.data)
dispatchGlobalState({
type: 'setBlockHeight',
payload: blockHeight.data,
});
} catch (error) {
eventEmitter.emit('error', error);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ANT, AOProcess, AoANTRecord } from '@ar.io/sdk/web';
import { validateArweaveId } from '@src/utils';
import { clamp } from 'lodash';
import { useEffect, useRef, useState } from 'react';

Expand Down Expand Up @@ -32,7 +33,7 @@
closeModal: () => void;
payloadCallback: (payload: SetRecordPayload) => void;
}) {
const [{ arweaveDataProvider, antAoClient, hyperbeamUrl }] = useGlobalState();

Check failure on line 36 in src/components/modals/ant-management/EditUndernameModal/EditUndernameModal.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'arweaveDataProvider' is assigned a value but never used

Check failure on line 36 in src/components/modals/ant-management/EditUndernameModal/EditUndernameModal.tsx

View workflow job for this annotation

GitHub Actions / build_and_test / lint_test_build

'arweaveDataProvider' is assigned a value but never used
const isMobile = useIsMobile();
const targetIdRef = useRef<HTMLInputElement>(null);
const ttlRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -126,8 +127,7 @@
customPattern={ARNS_TX_ID_ENTRY_REGEX}
validationPredicates={{
[VALIDATION_INPUT_TYPES.ARWEAVE_ID]: {
fn: (id: string) =>
arweaveDataProvider.validateArweaveId(id),
fn: (id: string) => validateArweaveId(id),
},
}}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/Register/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
formatARIOWithCommas,
formatDate,
isArweaveTransactionID,
validateArweaveId,
} from '../../../utils';
import {
MAX_LEASE_DURATION,
Expand All @@ -47,7 +48,7 @@
function RegisterNameForm() {
const [
{
arweaveDataProvider,

Check failure on line 51 in src/components/pages/Register/Register.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'arweaveDataProvider' is assigned a value but never used

Check failure on line 51 in src/components/pages/Register/Register.tsx

View workflow job for this annotation

GitHub Actions / build_and_test / lint_test_build

'arweaveDataProvider' is assigned a value but never used
arioTicker,
arioProcessId,
antAoClient,
Expand Down Expand Up @@ -483,8 +484,7 @@
placeholder={'Arweave Transaction ID (Target ID)'}
validationPredicates={{
[VALIDATION_INPUT_TYPES.ARWEAVE_ID]: {
fn: (id: string) =>
arweaveDataProvider.validateArweaveId(id),
fn: (id: string) => validateArweaveId(id),
},
}}
showValidationChecklist={false}
Expand Down
15 changes: 4 additions & 11 deletions src/components/pages/Settings/ArNSSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
import ArweaveID, {
ArweaveIdTypes,
} from '@src/components/layout/ArweaveID/ArweaveID';
import { ArweaveCompositeDataProvider } from '@src/services/arweave/ArweaveCompositeDataProvider';
import { ArweaveTransactionID } from '@src/services/arweave/ArweaveTransactionID';
import { SimpleArweaveDataProvider } from '@src/services/arweave/SimpleArweaveDataProvider';
import { useGlobalState, useWalletState } from '@src/state';
import { isArweaveTransactionID } from '@src/utils';
import { ARIO_PROCESS_ID } from '@src/utils/constants';
Expand All @@ -36,7 +34,7 @@ function ArNSSettings() {
setRegistryAddress(arioProcessId?.toString());
}, [arioProcessId]);

function confirmSetting(id: string) {
async function confirmSetting(id: string) {
if (isArweaveTransactionID(id)) {
dispatchGlobalState({
type: 'setIoProcessId',
Expand All @@ -60,16 +58,11 @@ function ArNSSettings() {
host: gateway,
protocol: 'https',
});
const arweaveDataProvider = new SimpleArweaveDataProvider(arweave);

const provider = new ArweaveCompositeDataProvider({
contract: arIOContract,
arweave: arweaveDataProvider,
});

const blockHeight = (await arweave.blocks.getCurrent()).height;
Copy link
Contributor Author

@dtfiedler dtfiedler Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use useArweaveBlockHeight hook

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking further, why do we need block height here?

dispatchGlobalState({ type: 'setBlockHeight', payload: blockHeight });
dispatchGlobalState({
type: 'setGateway',
payload: { gateway, provider },
payload: { gateway },
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
export * from './useLongPress/useLongPress';
export * from './useIsFocused/useIsFocused';
export * from './useRegistrationStatus/useRegistrationStatus';
export * from './useArPrice';
export * from './useArBalance';
export * from './useArweaveBlockHeight';
export * from './useArNSRecord';
export * from './useArNSReserved';
export * from './useSyncSettings/useSyncSettings';

Check failure on line 11 in src/hooks/index.ts

View workflow job for this annotation

GitHub Actions / lint_test_build

Delete `⏎`

Check failure on line 11 in src/hooks/index.ts

View workflow job for this annotation

GitHub Actions / build_and_test / lint_test_build

Delete `⏎`
20 changes: 20 additions & 0 deletions src/hooks/useArBalance.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ArweaveTransactionID } from '@src/services/arweave/ArweaveTransactionID';
import { useGlobalState } from '@src/state';
import { useQuery } from '@tanstack/react-query';
import Arweave from 'arweave';

export function useArBalance(address?: ArweaveTransactionID) {
const [{ gateway }] = useGlobalState();

return useQuery({
queryKey: ['ar-balance', address?.toString(), gateway],
queryFn: async () => {
if (!address) throw new Error('No address provided');
const arweave = new Arweave({ host: gateway, protocol: 'https' });
const winston = await arweave.wallets.getBalance(address.toString());
return +arweave.ar.winstonToAr(winston);
},
enabled: !!address,
staleTime: 1000 * 60 * 60,
});
}
Loading
Loading