Skip to content

Commit

Permalink
fixing adding anchor contract
Browse files Browse the repository at this point in the history
  • Loading branch information
kkatusic committed Dec 17, 2024
1 parent 8c3d635 commit 37576df
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 126 deletions.
112 changes: 59 additions & 53 deletions src/components/views/create/AlloProtocol/AlloProtocolModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,64 +122,70 @@ const AlloProtocolModal: FC<IAlloProtocolModal> = ({
? chain.id === config.OPTIMISM_NETWORK_NUMBER
: false;

const isOnBase = chain ? chain.id === config.BASE_NETWORK_NUMBER : false;

const handleButtonClick = async () => {
if (!isOnOptimism) {
switchChain?.({ chainId: config.OPTIMISM_NETWORK_NUMBER });
} else {
try {
setIsLoading(true);
const hash = await writeContract(wagmiConfig, {
address: config.OPTIMISM_CONFIG.anchorRegistryAddress,
functionName: 'createProfile',
abi: createProfileABI.abi,
chainId: config.OPTIMISM_NETWORK_NUMBER,
args: [
generateRandomNonce(), //nonce
addedProjectState?.id!,
{
protocol: 1,
pointer: '',
},
addedProjectState?.adminUser?.walletAddress, //admin user wallet address
[],
],
try {
setIsLoading(true);
const hash = await writeContract(wagmiConfig, {
address: isOnOptimism
? config.OPTIMISM_CONFIG.anchorRegistryAddress
: config.BASE_CONFIG.anchorRegistryAddress,
functionName: 'createProfile',
abi: createProfileABI.abi,
chainId: isOnOptimism
? config.OPTIMISM_NETWORK_NUMBER
: config.BASE_NETWORK_NUMBER,
args: [
generateRandomNonce(), //nonce
addedProjectState?.id!,
{
protocol: 1,
pointer: '',
},
addedProjectState?.adminUser?.walletAddress, //admin user wallet address
[],
],
});
setTxResult(hash);
if (hash) {
const data = await waitForTransactionReceipt(wagmiConfig, {
hash: hash,
chainId: isOnOptimism
? config.OPTIMISM_NETWORK_NUMBER
: config.BASE_NETWORK_NUMBER,
});
setTxResult(hash);
if (hash) {
const data = await waitForTransactionReceipt(wagmiConfig, {
hash: hash,
chainId: config.OPTIMISM_NETWORK_NUMBER,
});

const contractAddress = extractContractAddressFromString(
data.logs[0].data,

const contractAddress = extractContractAddressFromString(
data.logs[0].data,
);
//Call backend to update project
await client.mutate({
mutation: CREATE_ANCHOR_CONTRACT_ADDRESS_QUERY,
variables: {
projectId: Number(addedProjectState.id),
networkId: isOnOptimism
? config.OPTIMISM_NETWORK_NUMBER
: config.BASE_NETWORK_NUMBER,
address: contractAddress,
txHash: hash,
},
});
if (!isEditMode || (isEditMode && isDraft)) {
await router.push(
slugToSuccessView(addedProjectState.slug),
);
} else {
await router.push(
slugToProjectView(addedProjectState.slug),
);
//Call backend to update project
await client.mutate({
mutation: CREATE_ANCHOR_CONTRACT_ADDRESS_QUERY,
variables: {
projectId: Number(addedProjectState.id),
networkId: config.OPTIMISM_NETWORK_NUMBER,
address: contractAddress,
txHash: hash,
},
});
if (!isEditMode || (isEditMode && isDraft)) {
await router.push(
slugToSuccessView(addedProjectState.slug),
);
} else {
await router.push(
slugToProjectView(addedProjectState.slug),
);
}
}
setShowModal(false); // Close the modal
} catch (error) {
console.error('Error Contract', error);
} finally {
setIsLoading(false);
}
setShowModal(false); // Close the modal
} catch (error) {
console.error('Error Contract', error);
} finally {
setIsLoading(false);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,62 +64,66 @@ const AlloProtocolFirstDonationModal: FC<IAlloProtocolModal> = ({
: false;

const handleButtonClick = async () => {
if (!isOnOptimism) {
switchChain?.({ chainId: config.OPTIMISM_NETWORK_NUMBER });
} else {
try {
setIsLoading(true);
if (
!project?.adminUser?.walletAddress ||
!isAddress(project?.adminUser?.walletAddress)
) {
throw new Error('Invalid Project Admin Address');
}
const hash = await writeContract(wagmiConfig, {
address: config.OPTIMISM_CONFIG.anchorRegistryAddress,
functionName: 'createProfile',
abi: createProfileABI.abi,
chainId: config.OPTIMISM_NETWORK_NUMBER,
args: [
generateRandomNonce(), //nonce
project?.id!,
{
protocol: 1,
pointer: '',
},
project?.adminUser?.walletAddress, //admin user wallet address
[],
],
try {
setIsLoading(true);
if (
!project?.adminUser?.walletAddress ||
!isAddress(project?.adminUser?.walletAddress)
) {
throw new Error('Invalid Project Admin Address');
}
const hash = await writeContract(wagmiConfig, {
address: isOnOptimism
? config.OPTIMISM_CONFIG.anchorRegistryAddress
: config.BASE_CONFIG.anchorRegistryAddress,
functionName: 'createProfile',
abi: createProfileABI.abi,
chainId: isOnOptimism
? config.OPTIMISM_NETWORK_NUMBER
: config.BASE_NETWORK_NUMBER,
args: [
generateRandomNonce(), //nonce
project?.id!,
{
protocol: 1,
pointer: '',
},
project?.adminUser?.walletAddress, //admin user wallet address
[],
],
});
setTxResult(hash);
if (hash) {
const data = await waitForTransactionReceipt(wagmiConfig, {
hash: hash,
chainId: isOnOptimism
? config.OPTIMISM_NETWORK_NUMBER
: config.BASE_NETWORK_NUMBER,
});
setTxResult(hash);
if (hash) {
const data = await waitForTransactionReceipt(wagmiConfig, {
hash: hash,
chainId: config.OPTIMISM_NETWORK_NUMBER,
});

const contractAddress = extractContractAddressFromString(
data.logs[0].data,
);
//Call backend to update project
await client.mutate({
mutation: CREATE_ANCHOR_CONTRACT_ADDRESS_QUERY,
variables: {
projectId: Number(project.id),
networkId: config.OPTIMISM_NETWORK_NUMBER,
address: contractAddress,
txHash: hash,
},
});
await fetchProject();
onModalCompletion();
}
setShowModal(false); // Close the modal
} catch (error) {
showToastError(error);
} finally {
setIsLoading(false);
const contractAddress = extractContractAddressFromString(
data.logs[0].data,
);
//Call backend to update project
await client.mutate({
mutation: CREATE_ANCHOR_CONTRACT_ADDRESS_QUERY,
variables: {
projectId: Number(project.id),
networkId: isOnOptimism
? config.OPTIMISM_NETWORK_NUMBER
: config.BASE_NETWORK_NUMBER,
address: contractAddress,
txHash: hash,
},
});
await fetchProject();
onModalCompletion();
}
setShowModal(false); // Close the modal
} catch (error) {
showToastError(error);
} finally {
setIsLoading(false);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IModifySuperTokenInnerModalProps } from './ModifySuperTokenModal';
import { ISuperToken, IToken } from '@/types/superFluid';
import { actionButtonLabel, EModifySuperTokenSteps } from './common';
import { ModifyWrapper, Wrapper } from './common.sc';
import config, { isProduction } from '@/configuration';
import { isProduction } from '@/configuration';
import { showToastError } from '@/lib/helpers';
import { Item } from '../RecurringDonationModal/Item';
import { RunOutInfo } from '../RunOutInfo';
Expand All @@ -36,7 +36,8 @@ export const WithDrawSuperToken: FC<IWithDrawSuperTokenProps> = ({
closeModal,
}) => {
const [amount, setAmount] = useState(0n);
const { address } = useAccount();
const { address, chain } = useAccount();
const recurringNetworkID = chain?.id ?? 0;
const { formatMessage } = useIntl();
const tokenPrice = useTokenPrice(token);
const [isWarning, setIsWarning] = useState(false);
Expand All @@ -60,7 +61,7 @@ export const WithDrawSuperToken: FC<IWithDrawSuperTokenProps> = ({
const onWithdraw = async () => {
setStep(EModifySuperTokenSteps.WITHDRAWING);
try {
await ensureCorrectNetwork(config.OPTIMISM_NETWORK_NUMBER);
await ensureCorrectNetwork(recurringNetworkID);
if (!address) {
throw new Error('address not found1');
}
Expand All @@ -76,7 +77,7 @@ export const WithDrawSuperToken: FC<IWithDrawSuperTokenProps> = ({
throw new Error('Provider or signer not found');

const _options = {
chainId: config.OPTIMISM_CONFIG.id,
chainId: recurringNetworkID,
provider: provider,
resolverAddress: isProduction
? undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ export const RecurringDonationCard = () => {
tokenStreams[selectedRecurringToken?.token.id.toLowerCase() || ''];

const anchorContractAddress = useMemo(
() => findAnchorContractAddress(project.anchorContracts),
[project.anchorContracts],
() => findAnchorContractAddress(project.anchorContracts, chain?.id),
[project.anchorContracts, chain?.id],
);

// otherStreamsPerSec is the total flow rate of all streams except the one to the project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const RecurringDonationInnerModal: FC<IRecurringDonationInnerModalProps> = ({
setStep(EDonationSteps.DONATING);
const projectAnchorContract = findAnchorContractAddress(
project?.anchorContracts,
recurringNetworkID,
);
if (!projectAnchorContract) {
throw new Error('Project anchor address not found');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const AdminActions = () => {

const anchorContractAddress = findAnchorContractAddress(
project.anchorContracts,
chain?.id,
);

const options: IOption[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const ModifyStreamInnerModal: FC<IModifyStreamInnerModalProps> = ({
otherStreamsTotalFlowRate: 0n,
});
const { formatMessage } = useIntl();
const { address } = useAccount();
const { address, chain } = useAccount();

// Get the balance of the super token
const { data: balance } = useBalance({
Expand Down Expand Up @@ -117,6 +117,7 @@ export const ModifyStreamInnerModal: FC<IModifyStreamInnerModalProps> = ({
};
const anchorContractAddress = findAnchorContractAddress(
donation.project.anchorContracts,
chain?.id,
);
for (let i = 0; i < tokenStream.length; i++) {
const ts = tokenStream[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const UpdateStreamInnerModal: FC<IModifyStreamInnerModalProps> = ({
const [tx, setTx] = useState('');
const { formatMessage } = useIntl();
const tokenPrice = useTokenPrice(token);
const { address } = useAccount();
const { address, chain } = useAccount();
const { refetchTokenStream } = useProfileDonateTabData();

const onDonate = async () => {
Expand All @@ -60,6 +60,7 @@ export const UpdateStreamInnerModal: FC<IModifyStreamInnerModalProps> = ({
await ensureCorrectNetwork(config.OPTIMISM_NETWORK_NUMBER);
const projectAnchorContract = findAnchorContractAddress(
donation.project.anchorContracts,
chain?.id,
);
if (!projectAnchorContract) {
throw new Error('Project anchor address not found');
Expand Down
Loading

0 comments on commit 37576df

Please sign in to comment.