Skip to content

Commit

Permalink
fix(ant cu url): add ANT cu url on all ant usage
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Dec 13, 2024
1 parent 3f36b2f commit fc684c0
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 534 deletions.
2 changes: 1 addition & 1 deletion src/components/cards/NavMenuCard/NavMenuCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function NavMenuCard() {
buildIOBalanceQuery({
address: walletAddress.toString(),
arioContract,
meta: [arioProcessId, aoNetwork.CU_URL],
meta: [arioProcessId, aoNetwork.ARIO.CU_URL],
}),
);
const arBalance = await queryClient.fetchQuery(
Expand Down
182 changes: 133 additions & 49 deletions src/components/devtools/NetworkSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ function NetworkSettings() {
const [{ wallet }] = useWalletState();
const [newGateway, setNewGateway] = useState<string>(gateway);
const [validGateway, setValidGateway] = useState<boolean>(true);
const [newCuUrl, setNewCuUrl] = useState<string>(NETWORK_DEFAULTS.AO.CU_URL);
const [validCuUrl, setValidCuUrl] = useState<boolean>(true);
const [newMuUrl, setNewMuUrl] = useState<string>(NETWORK_DEFAULTS.AO.MU_URL);

const [newARIOCuUrl, setNewARIOCuUrl] = useState<string>(
NETWORK_DEFAULTS.AO.ARIO.CU_URL,
);
const [validARIOCuUrl, setValidARIOCuUrl] = useState<boolean>(true);

const [newANTCuUrl, setNewANTCuUrl] = useState<string>(
NETWORK_DEFAULTS.AO.ANT.CU_URL,
);
const [validANTCuUrl, setValidANTCuUrl] = useState<boolean>(true);

const [newMuUrl, setNewMuUrl] = useState<string>(
NETWORK_DEFAULTS.AO.ARIO.MU_URL,
);
const [validMuUrl, setValidMuUrl] = useState<boolean>(true);
const [newSuAddress, setNewSuAddress] = useState<string>(
NETWORK_DEFAULTS.AO.SCHEDULER,
NETWORK_DEFAULTS.AO.ARIO.SCHEDULER,
);
const [validSuAddress, setValidSuAddress] = useState<boolean>(true);
const [showGatewayModal, setShowGatewayModal] = useState<boolean>(false);
Expand All @@ -44,16 +55,16 @@ function NetworkSettings() {
setValidGateway(true);
updateGateway(NETWORK_DEFAULTS.ARWEAVE.HOST);
// ao network
setNewCuUrl(NETWORK_DEFAULTS.AO.CU_URL);
setValidCuUrl(true);
setNewMuUrl(NETWORK_DEFAULTS.AO.MU_URL);
setNewARIOCuUrl(NETWORK_DEFAULTS.AO.ARIO.CU_URL);
setValidARIOCuUrl(true);
setNewMuUrl(NETWORK_DEFAULTS.AO.ARIO.MU_URL);
setValidMuUrl(true);
setNewSuAddress(NETWORK_DEFAULTS.AO.SCHEDULER);
setNewSuAddress(NETWORK_DEFAULTS.AO.ARIO.SCHEDULER);
setValidSuAddress(true);
updateAoNetwork({
CU_URL: NETWORK_DEFAULTS.AO.CU_URL,
MU_URL: NETWORK_DEFAULTS.AO.MU_URL,
SCHEDULER: NETWORK_DEFAULTS.AO.SCHEDULER,
updateARIOAoNetwork({
CU_URL: NETWORK_DEFAULTS.AO.ARIO.CU_URL,
MU_URL: NETWORK_DEFAULTS.AO.ARIO.MU_URL,
SCHEDULER: NETWORK_DEFAULTS.AO.ARIO.SCHEDULER,
});
}

Expand All @@ -63,13 +74,13 @@ function NetworkSettings() {
}, [gateway]);

useEffect(() => {
setNewCuUrl(aoNetwork.CU_URL);
setValidCuUrl(true);
setNewMuUrl(aoNetwork.MU_URL);
setNewARIOCuUrl(aoNetwork.ARIO.CU_URL);
setValidARIOCuUrl(true);
setNewMuUrl(aoNetwork.ARIO.MU_URL);
setValidMuUrl(true);
setNewSuAddress(aoNetwork.SCHEDULER);
setNewSuAddress(aoNetwork.ARIO.SCHEDULER);
setValidSuAddress(true);
}, [aoNetwork]);
}, [aoNetwork.ARIO]);

async function updateGateway(gate: string) {
try {
Expand All @@ -93,16 +104,15 @@ function NetworkSettings() {
}
}

function updateAoNetwork(config: {
function updateARIOAoNetwork(config: {
CU_URL?: string;
MU_URL?: string;
SCHEDULER?: string;
}) {
try {
const newConfig = {
...aoNetwork,
...config,
GATEWAY_URL: gateway,
...{ ARIO: { ...aoNetwork.ARIO, ...config, GATEWAY_URL: gateway } },
};
dispatchGlobalState({
type: 'setAONetwork',
Expand All @@ -111,11 +121,11 @@ function NetworkSettings() {

const ao = connect({
GATEWAY_URL: 'https://' + gateway,
CU_URL: newConfig.CU_URL,
MU_URL: newConfig.MU_URL,
CU_URL: newConfig.ARIO.CU_URL,
MU_URL: newConfig.ARIO.MU_URL,
});
dispatchGlobalState({
type: 'setAoClient',
type: 'setARIOAoClient',
payload: ao,
});
dispatchArIOContract({
Expand All @@ -133,6 +143,30 @@ function NetworkSettings() {
}
}

function updateANTAoNetwork(config: { CU_URL?: string }) {
try {
const newConfig = {
...aoNetwork,
...{ ANT: { ...aoNetwork.ANT, ...config } },
};
dispatchGlobalState({
type: 'setAONetwork',
payload: newConfig,
});

const ao = connect({
GATEWAY_URL: 'https://' + gateway,
CU_URL: newConfig.ANT.CU_URL,
});
dispatchGlobalState({
type: 'setANTAoClient',
payload: ao,
});
} catch (error) {
eventEmitter.emit('error', error);
}
}

return (
<div className="flex" style={{ width: '100%' }}>
<Space direction="vertical" style={{ width: '100%' }}>
Expand Down Expand Up @@ -208,42 +242,90 @@ function NetworkSettings() {
}
/>
<span className="flex w-fit justify-center items-center bg-primary-thin rounded-t-md px-4 py-1 border-x-2 border-t-2 border-primary text-md text-primary font-semibold mt-2">
CU URL:{' '}
<span className="text-white pl-2">{aoNetwork.CU_URL}</span>
ARIO CU URL:{' '}
<span className="text-white pl-2">{aoNetwork.ARIO.CU_URL}</span>
</span>
<Input
className="bg-background justify-center items-center"
placeholder="Enter custom CU url"
value={newCuUrl}
value={newARIOCuUrl}
onChange={(e) => {
setValidCuUrl(isValidURL(e.target.value.trim()));
setNewCuUrl(e.target.value.trim());
setValidARIOCuUrl(isValidURL(e.target.value.trim()));
setNewARIOCuUrl(e.target.value.trim());
}}
onClear={() => setNewCuUrl('')}
onClear={() => setNewARIOCuUrl('')}
onPressEnter={(e) =>
updateAoNetwork({
updateARIOAoNetwork({
CU_URL: e.currentTarget.value.trim(),
})
}
variant="outlined"
status={validCuUrl ? '' : 'error'}
status={validARIOCuUrl ? '' : 'error'}
addonAfter={
<div className="flex flex-row" style={{ gap: '5px' }}>
<button
disabled={!validCuUrl}
disabled={!validARIOCuUrl}
className="bg-primary text-black h-full flex w-fit p-1 rounded-sm text-xs"
onClick={() =>
updateAoNetwork({ CU_URL: newCuUrl.trim() })
updateARIOAoNetwork({ CU_URL: newARIOCuUrl.trim() })
}
>
Set CU url
Set ARIO CU url
</button>
<button
className="bg-primary-thin text-white h-full flex w-fit p-1 rounded-sm text-xs"
onClick={() => {
setNewCuUrl(NETWORK_DEFAULTS.AO.CU_URL);
setValidCuUrl(true);
updateAoNetwork({ CU_URL: NETWORK_DEFAULTS.AO.CU_URL });
setNewARIOCuUrl(NETWORK_DEFAULTS.AO.ARIO.CU_URL);
setValidARIOCuUrl(true);
updateARIOAoNetwork({
CU_URL: NETWORK_DEFAULTS.AO.ARIO.CU_URL,
});
}}
>
reset
</button>
</div>
}
/>
<span className="flex w-fit justify-center items-center bg-primary-thin rounded-t-md px-4 py-1 border-x-2 border-t-2 border-primary text-md text-primary font-semibold mt-2">
ANT CU URL:{' '}
<span className="text-white pl-2">{aoNetwork.ANT.CU_URL}</span>
</span>
<Input
className="bg-background justify-center items-center"
placeholder="Enter custom CU url"
value={newANTCuUrl}
onChange={(e) => {
setValidANTCuUrl(isValidURL(e.target.value.trim()));
setNewANTCuUrl(e.target.value.trim());
}}
onClear={() => setNewANTCuUrl('')}
onPressEnter={(e) =>
updateANTAoNetwork({
CU_URL: e.currentTarget.value.trim(),
})
}
variant="outlined"
status={validANTCuUrl ? '' : 'error'}
addonAfter={
<div className="flex flex-row" style={{ gap: '5px' }}>
<button
disabled={!validANTCuUrl}
className="bg-primary text-black h-full flex w-fit p-1 rounded-sm text-xs"
onClick={() =>
updateARIOAoNetwork({ CU_URL: newANTCuUrl.trim() })
}
>
Set ANT CU url
</button>
<button
className="bg-primary-thin text-white h-full flex w-fit p-1 rounded-sm text-xs"
onClick={() => {
setNewANTCuUrl(NETWORK_DEFAULTS.AO.ANT.CU_URL);
setValidANTCuUrl(true);
updateANTAoNetwork({
CU_URL: NETWORK_DEFAULTS.AO.ANT.CU_URL,
});
}}
>
reset
Expand All @@ -253,7 +335,7 @@ function NetworkSettings() {
/>
<span className="flex w-fit justify-center items-center bg-primary-thin rounded-t-md px-4 py-1 border-x-2 border-t-2 border-primary text-md text-primary font-semibold mt-2">
MU URL:{' '}
<span className="text-white pl-2">{aoNetwork.MU_URL}</span>
<span className="text-white pl-2">{aoNetwork.ARIO.MU_URL}</span>
</span>
<Input
className="bg-background justify-center items-center"
Expand All @@ -263,9 +345,9 @@ function NetworkSettings() {
setValidMuUrl(isValidURL(e.target.value.trim()));
setNewMuUrl(e.target.value.trim());
}}
onClear={() => setNewCuUrl('')}
onClear={() => setNewARIOCuUrl('')}
onPressEnter={(e) =>
updateAoNetwork({
updateARIOAoNetwork({
MU_URL: e.currentTarget.value.trim(),
})
}
Expand All @@ -277,17 +359,19 @@ function NetworkSettings() {
disabled={!validMuUrl}
className="bg-primary text-black h-full flex w-fit p-1 rounded-sm text-xs"
onClick={() =>
updateAoNetwork({ MU_URL: newMuUrl.trim() })
updateARIOAoNetwork({ MU_URL: newMuUrl.trim() })
}
>
Set MU url
</button>
<button
className="bg-primary-thin text-white h-full flex w-fit p-1 rounded-sm text-xs"
onClick={() => {
setNewMuUrl(NETWORK_DEFAULTS.AO.MU_URL);
setNewMuUrl(NETWORK_DEFAULTS.AO.ARIO.MU_URL);
setValidMuUrl(true);
updateAoNetwork({ MU_URL: NETWORK_DEFAULTS.AO.MU_URL });
updateARIOAoNetwork({
MU_URL: NETWORK_DEFAULTS.AO.ARIO.MU_URL,
});
}}
>
reset
Expand All @@ -299,7 +383,7 @@ function NetworkSettings() {
SU Address:{' '}
<span className="text-white pl-2">
<ArweaveID
id={new ArweaveTransactionID(aoNetwork.SCHEDULER)}
id={new ArweaveTransactionID(aoNetwork.ARIO.SCHEDULER)}
shouldLink
type={ArweaveIdTypes.ADDRESS}
characterCount={16}
Expand All @@ -318,7 +402,7 @@ function NetworkSettings() {
}}
onClear={() => setNewSuAddress('')}
onPressEnter={(e) =>
updateAoNetwork({
updateARIOAoNetwork({
SCHEDULER: e.currentTarget.value.trim(),
})
}
Expand All @@ -330,18 +414,18 @@ function NetworkSettings() {
disabled={!validSuAddress}
className="bg-primary text-black h-full flex w-fit p-1 rounded-sm text-xs"
onClick={() =>
updateAoNetwork({ SCHEDULER: newSuAddress })
updateARIOAoNetwork({ SCHEDULER: newSuAddress })
}
>
Set Scheduler Address
</button>
<button
className="bg-primary-thin text-white h-full flex w-fit p-1 rounded-sm text-xs"
onClick={() => {
setNewSuAddress(NETWORK_DEFAULTS.AO.SCHEDULER);
setNewSuAddress(NETWORK_DEFAULTS.AO.ARIO.SCHEDULER);
setValidSuAddress(true);
updateAoNetwork({
SCHEDULER: NETWORK_DEFAULTS.AO.SCHEDULER,
updateARIOAoNetwork({
SCHEDULER: NETWORK_DEFAULTS.AO.ARIO.SCHEDULER,
});
}}
>
Expand Down
14 changes: 10 additions & 4 deletions src/components/inputs/text/NameTokenSelector/NameTokenSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANT, AoArNSNameData } from '@ar.io/sdk/web';
import { ANT, AOProcess, AoArNSNameData } from '@ar.io/sdk/web';
import Tooltip from '@src/components/data-display/Tooltip';
import { Pagination, PaginationProps } from 'antd';
import { useEffect, useRef, useState } from 'react';
Expand Down Expand Up @@ -31,7 +31,7 @@ function NameTokenSelector({
}: {
selectedTokenCallback: (id: ArweaveTransactionID | undefined) => void;
}) {
const [{ arweaveDataProvider }] = useGlobalState();
const [{ arweaveDataProvider, antAoClient }] = useGlobalState();
const [{ walletAddress }] = useWalletState();

const [searchText, setSearchText] = useState<string>();
Expand Down Expand Up @@ -121,7 +121,10 @@ function NameTokenSelector({
imports.map(async (id: ArweaveTransactionID) => {
try {
const contract = ANT.init({
processId: id.toString(),
process: new AOProcess({
processId: id.toString(),
ao: antAoClient,
}),
});

const info = await contract.getInfo();
Expand Down Expand Up @@ -165,7 +168,10 @@ function NameTokenSelector({
}[] = await Promise.all(
processIds.map(async (processId) => {
const contract = ANT.init({
processId: processId.toString(),
process: new AOProcess({
processId: processId.toString(),
ao: antAoClient,
}),
});
const names = Object.keys(associatedRecords).reduce(
(acc: Record<string, AoArNSNameData>, id: string) => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/layout/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ function Breadcrumbs() {
// check for ant flag
if (isArweaveTransactionID(processId)) {
const state = await queryClient.fetchQuery(
buildAntStateQuery({ processId, meta: [gateway, aoNetwork.CU_URL] }),
buildAntStateQuery({
processId,
meta: [gateway, aoNetwork.ARIO.CU_URL],
}),
);
const name = state?.Name;

Expand Down
Loading

0 comments on commit fc684c0

Please sign in to comment.