Skip to content

Commit

Permalink
rename mns var
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed May 16, 2024
1 parent d249e05 commit d657423
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions web-frontend/src/custom/useMNS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { contracts } from '@/utils/const';

export function useMNS() {
const [targetMnsAddress, setTargetMnsAddress] = useState<string>('');
const [mns, setMns] = useState<string>('');
const [domainName, setDomainName] = useState<string>('');

const { client, account, isMainnet } = usePrepareScCall();

Expand All @@ -27,15 +27,14 @@ export function useMNS() {
parameter: new Args().addString(targetAddress).serialize(),
} as ICallData;

if (!client) return;

try {
if (!client) throw new Error('Client not initialized');
const result = await client
.smartContracts()
.readSmartContract(reverseResolveCallData);
setMns(bytesToStr(result.returnValue));
setDomainName(bytesToStr(result.returnValue));
} catch (e) {
setMns('');
setDomainName('');
console.error('Reverse DNS resolution failed:', e);
}
},
Expand All @@ -44,14 +43,14 @@ export function useMNS() {

const resolveDns = useCallback(
async (domain: string) => {
if (!client) return;
const resolveCallData = {
targetAddress: targetContractAddress,
targetFunction: 'dnsResolve',
parameter: new Args().addString(domain).serialize(),
} as ICallData;

try {
if (!client) throw new Error('Client not initialized');
const result = await client
.smartContracts()
.readSmartContract(resolveCallData);
Expand All @@ -69,7 +68,7 @@ export function useMNS() {
}

return {
mns,
domainName,
resolveDns,
targetMnsAddress,
reverseResolveDns,
Expand Down
4 changes: 2 additions & 2 deletions web-frontend/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function Home() {
data: account,
isLoading,
} = useResource<AccountObject>(`accounts/${nickname}`);
const { reverseResolveDns, mns } = useMNS();
const { reverseResolveDns, domainName } = useMNS();

useEffect(() => {
reverseResolveDns();
Expand Down Expand Up @@ -91,7 +91,7 @@ export default function Home() {
{Intl.t('home.title-account-address')}
</p>
<div className="flex w-full justify-between items-center">
{mns && <Mns mns={mns} />}
{domainName && <Mns mns={domainName} />}
<Clipboard
displayedContent={maskAddress(address)}
rawContent={address}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function SendConfirmation(props: SendConfirmationProps) {
decimals,
).amountFormattedFull;

const { reverseResolveDns, mns } = useMNS();
const { reverseResolveDns, domainName } = useMNS();

useEffect(() => {
reverseResolveDns(recipientAddress);
Expand Down Expand Up @@ -137,7 +137,7 @@ export function SendConfirmation(props: SendConfirmationProps) {
w-fit h-fit px-3 py-1 rounded bg-primary cursor-pointer"
/>
</div>
{mns && <Mns mns={mns} />}
{domainName && <Mns mns={domainName} />}
</div>
<Button disabled={isLoading} onClick={() => handleConfirm(true)}>
{Intl.t('send-coins.confirm-sign')}
Expand Down

0 comments on commit d657423

Please sign in to comment.