-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor to remove SimpleArweaveDataProvider #798
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
base: develop
Are you sure you want to change the base?
Changes from 2 commits
ab55e21
9a7bcf6
b886f00
c71ee54
809bd36
53e278c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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(); | ||
|
|
@@ -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', | ||
|
|
@@ -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; | ||
|
||
| dispatchGlobalState({ type: 'setBlockHeight', payload: blockHeight }); | ||
| dispatchGlobalState({ | ||
| type: 'setGateway', | ||
| payload: { gateway, provider }, | ||
| payload: { gateway }, | ||
| }); | ||
| } | ||
| } | ||
|
|
@@ -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, | ||
| }, | ||
| }} | ||
|
|
||
| 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'; | ||
|
|
||
|
|
@@ -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
|
||
| const [{ walletAddress }] = useWalletState(); | ||
|
|
||
| const [searchText, setSearchText] = useState<string>(); | ||
|
|
@@ -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()], | ||
| }), | ||
| ); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: revert this change back |
||
|
|
||
| const contracts: { | ||
| processId: ArweaveTransactionID; | ||
|
|
@@ -377,7 +380,7 @@ | |
| validationPredicates={{ | ||
| [VALIDATION_INPUT_TYPES.ARWEAVE_ID]: { | ||
| fn: (id: string) => { | ||
| return arweaveDataProvider.validateArweaveId(id); | ||
| return validateArweaveId(id); | ||
| }, | ||
| }, | ||
| }} | ||
|
|
||
| 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; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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', | ||
|
|
@@ -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; | ||
|
||
| dispatchGlobalState({ type: 'setBlockHeight', payload: blockHeight }); | ||
| dispatchGlobalState({ | ||
| type: 'setGateway', | ||
| payload: { gateway, provider }, | ||
| payload: { gateway }, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| 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, | ||
| }); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.