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

resolved conflicts #949

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AuthContext } from '../../../../context/AuthContext';
import { ConfigureProfileContext } from '../../context/ConfigureProfileContext';
import { SubmitOnChainProfile } from '../SubmitOnChainProfile';
import { IChain, NAME_TYPE, validateEnsName } from '../common';
import { submitEnsNameTransaction } from './bl';
import { fetchExistingEnsName, submitEnsNameTransaction } from './bl';
import { ModalContext } from '../../../../context/ModalContext';
import { ConfigureDM3NameContext } from '../../context/ConfigureDM3NameContext';
import { fetchChainIdFromServiceName } from '../../bl';
Expand Down Expand Up @@ -101,6 +101,18 @@ export const ConfigureEnsProfile = (props: IChain) => {
}
}, [connectedChainId]);

// Fetches existing ENS name if exists
useEffect(() => {
const fetchEnsName = async () => {
if (ethAddress) {
setExistingEnsName(
await fetchExistingEnsName(ethAddress, provider),
);
}
};
fetchEnsName();
}, []);

// on change of dropdown selected, error vanishes
useEffect(() => {
onShowError(undefined, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,15 @@ export async function getPublishProfileOnchainTransaction(
args: [node, key, value],
};
}

export const fetchExistingEnsName = async (
address: string,
provider: ethers.providers.StaticJsonRpcProvider,
): Promise<string | null> => {
try {
return await provider.lookupAddress(address);
} catch (error) {
console.log('Failed to query ENS name : ', error);
return null;
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useContext, useEffect, useState } from 'react';
import { SubmitOnChainProfile } from '../SubmitOnChainProfile';
import { submitGenomeNameTransaction, validateGenomeName } from './bl';
import {
fetchExistingGnoName,
submitGenomeNameTransaction,
validateGenomeName,
} from './bl';
import { ConfigureProfileContext } from '../../context/ConfigureProfileContext';
import { useChainId, useSwitchNetwork } from 'wagmi';
import { AuthContext } from '../../../../context/AuthContext';
Expand All @@ -10,6 +14,7 @@ import { ModalContext } from '../../../../context/ModalContext';
import { DM3ConfigurationContext } from '../../../../context/DM3ConfigurationContext';
import { ConfigureDM3NameContext } from '../../context/ConfigureDM3NameContext';
import { fetchChainIdFromServiceName } from '../../bl';
import { supportedChains } from '../../../../utils/common-utils';

export const ConfigureGenomeProfile = (props: IChain) => {
const connectedChainId = useChainId();
Expand Down Expand Up @@ -105,6 +110,21 @@ export const ConfigureGenomeProfile = (props: IChain) => {
setEnsName('');
}, [namingServiceSelected]);

// Fetches existing GNO name if exists
useEffect(() => {
const fetchGnoName = async () => {
if (ethAddress) {
setExistingEnsName(
await fetchExistingGnoName(
ethAddress,
supportedChains.gnosisMainnet,
),
);
}
};
fetchGnoName();
}, []);

const propertyName = 'GNO Name';

const label =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createAlias } from '@dm3-org/dm3-lib-delivery-api';
import { Account, SignedUserProfile } from '@dm3-org/dm3-lib-profile';
import { ethersHelper, stringify } from '@dm3-org/dm3-lib-shared';
import { getConractInstance } from '@dm3-org/dm3-lib-shared/dist/ethersHelper';
import { ethersHelper, log, stringify } from '@dm3-org/dm3-lib-shared';
import { ethers } from 'ethers';
import { closeLoader, startLoader } from '../../../Loader/Loader';
import { Address, namehash, toHex } from 'viem';
Expand Down Expand Up @@ -161,3 +160,19 @@ export const submitGenomeNameTransaction = async (
export const validateGenomeName = (ensName: string) => {
return ensName.endsWith('.gno');
};

export const fetchExistingGnoName = async (
address: string,
chainId: number,
): Promise<string | null> => {
try {
const web3Name = createWeb3Name();
return await web3Name.getDomainName({
address,
queryChainIdList: [chainId],
});
} catch (error) {
console.log('Failed to query GNO name : ', error);
return null;
}
};