From 21ddfa5396518c795e257f25abaf861e6a755bcb Mon Sep 17 00:00:00 2001 From: Francis Rodriguez Date: Thu, 28 Sep 2023 12:52:06 -0300 Subject: [PATCH] US-1955 Added mainnet contracts and fixed rns in mainnet --- src/lib/rns/RnsProcessor.ts | 16 +++--- src/redux/slices/contactsSlice/constants.ts | 53 ++++++++++++++----- src/redux/slices/contactsSlice/index.ts | 2 +- src/screens/profile/ProfileCreateScreen.tsx | 8 ++- src/screens/rnsManager/DomainInput.tsx | 13 +++-- .../rnsManager/PurchaseDomainScreen.tsx | 7 ++- src/screens/rnsManager/SearchDomainScreen.tsx | 7 ++- src/screens/rnsManager/addresses.json | 16 ++++-- src/screens/rnsManager/types.ts | 18 +++++++ 9 files changed, 105 insertions(+), 35 deletions(-) create mode 100644 src/screens/rnsManager/types.ts diff --git a/src/lib/rns/RnsProcessor.ts b/src/lib/rns/RnsProcessor.ts index 82c7ea8aa..ab72d3bbe 100644 --- a/src/lib/rns/RnsProcessor.ts +++ b/src/lib/rns/RnsProcessor.ts @@ -2,32 +2,36 @@ import { RSKRegistrar } from '@rsksmart/rns-sdk' import { RIFWallet } from '@rsksmart/rif-wallet-core' import { BigNumber } from 'ethers' -import addresses from 'screens/rnsManager/addresses.json' import { getRnsProcessor, hasRnsProcessor, saveRnsProcessor, } from 'storage/RnsProcessorStore' import { OnSetTransactionStatusChange } from 'screens/send/types' +import { RNS_ADDRESSES_TYPE } from 'screens/rnsManager/types' export class RnsProcessor { private rskRegistrar private wallet private index: IDomainRegistrationProcessIndex = {} + private rnsAddresses: RNS_ADDRESSES_TYPE onSetTransactionStatusChange?: OnSetTransactionStatusChange constructor({ wallet, onSetTransactionStatusChange, + rnsAddresses, }: { wallet: RIFWallet onSetTransactionStatusChange?: OnSetTransactionStatusChange + rnsAddresses: RNS_ADDRESSES_TYPE }) { this.wallet = wallet + this.rnsAddresses = rnsAddresses this.rskRegistrar = new RSKRegistrar( - addresses.rskOwnerAddress, - addresses.fifsAddrRegistrarAddress, - addresses.rifTokenAddress, + this.rnsAddresses.rskOwnerAddress, + this.rnsAddresses.fifsAddrRegistrarAddress, + this.rnsAddresses.rifTokenAddress, wallet, ) if (hasRnsProcessor()) { @@ -61,7 +65,7 @@ export class RnsProcessor { ...makeCommitmentTransaction, txStatus: 'PENDING', value: BigNumber.from('0'), - finalAddress: addresses.fifsAddrRegistrarAddress, + finalAddress: this.rnsAddresses.fifsAddrRegistrarAddress, }) this.setIndex(domain, { domain, @@ -177,7 +181,7 @@ export class RnsProcessor { this.onSetTransactionStatusChange?.({ ...tx, txStatus: 'PENDING', - finalAddress: addresses.fifsAddrRegistrarAddress, + finalAddress: this.rnsAddresses.fifsAddrRegistrarAddress, }) this.setIndex(domain, { ...this.index[domain], diff --git a/src/redux/slices/contactsSlice/constants.ts b/src/redux/slices/contactsSlice/constants.ts index 05b64f117..a15b2ae4c 100644 --- a/src/redux/slices/contactsSlice/constants.ts +++ b/src/redux/slices/contactsSlice/constants.ts @@ -1,29 +1,56 @@ import { Contact } from 'shared/types' -import addresses from 'screens/rnsManager/addresses.json' +import { TESTNET, MAINNET } from 'screens/rnsManager/addresses.json' export const defaultContacts: Record = { - [addresses.fifsAddrRegistrarAddress]: { - address: addresses.fifsAddrRegistrarAddress, + [TESTNET.fifsAddrRegistrarAddress]: { + address: TESTNET.fifsAddrRegistrarAddress, name: 'RNS Manager', - displayAddress: addresses.fifsAddrRegistrarAddress, + displayAddress: TESTNET.fifsAddrRegistrarAddress, isEditable: false, }, - [addresses.rifTokenAddress]: { - address: addresses.rifTokenAddress, + [TESTNET.rifTokenAddress]: { + address: TESTNET.rifTokenAddress, name: 'RIF Token', - displayAddress: addresses.rifTokenAddress, + displayAddress: TESTNET.rifTokenAddress, isEditable: false, }, - [addresses.rnsRegistryAddress]: { - address: addresses.rnsRegistryAddress, + [TESTNET.rnsRegistryAddress]: { + address: TESTNET.rnsRegistryAddress, name: 'RNS Registry', - displayAddress: addresses.rnsRegistryAddress, + displayAddress: TESTNET.rnsRegistryAddress, isEditable: false, }, - [addresses.rskOwnerAddress]: { - address: addresses.rskOwnerAddress, + [TESTNET.rskOwnerAddress]: { + address: TESTNET.rskOwnerAddress, name: 'RSK Owner', - displayAddress: addresses.rskOwnerAddress, + displayAddress: TESTNET.rskOwnerAddress, + isEditable: false, + }, +} + +export const mainnetContacts: Record = { + [MAINNET.fifsAddrRegistrarAddress]: { + address: MAINNET.fifsAddrRegistrarAddress, + name: 'RNS Manager', + displayAddress: MAINNET.fifsAddrRegistrarAddress, + isEditable: false, + }, + [MAINNET.rifTokenAddress]: { + address: MAINNET.rifTokenAddress, + name: 'RIF Token', + displayAddress: MAINNET.rifTokenAddress, + isEditable: false, + }, + [MAINNET.rnsRegistryAddress]: { + address: MAINNET.rnsRegistryAddress, + name: 'RNS Registry', + displayAddress: MAINNET.rnsRegistryAddress, + isEditable: false, + }, + [MAINNET.rskOwnerAddress]: { + address: MAINNET.rskOwnerAddress, + name: 'RSK Owner', + displayAddress: MAINNET.rskOwnerAddress, isEditable: false, }, } diff --git a/src/redux/slices/contactsSlice/index.ts b/src/redux/slices/contactsSlice/index.ts index 38486e9b2..fbd7e5953 100644 --- a/src/redux/slices/contactsSlice/index.ts +++ b/src/redux/slices/contactsSlice/index.ts @@ -7,7 +7,7 @@ import { import { getContacts, saveContacts } from 'storage/MainStorage' import { Contact } from 'shared/types' import { defaultContacts } from 'store/slices/contactsSlice/constants' -import addresses from 'screens/rnsManager/addresses.json' +import { TESTNET as addresses } from 'screens/rnsManager/addresses.json' const initialState: ContactsState = { contacts: defaultContacts, diff --git a/src/screens/profile/ProfileCreateScreen.tsx b/src/screens/profile/ProfileCreateScreen.tsx index 7f887d5bb..71bf96fb9 100644 --- a/src/screens/profile/ProfileCreateScreen.tsx +++ b/src/screens/profile/ProfileCreateScreen.tsx @@ -47,6 +47,7 @@ import { useAppDispatch, useAppSelector } from 'store/storeUtils' import { AppSpinner } from 'components/index' import { AvatarIcon } from 'components/icons/AvatarIcon' import { rootTabsRouteNames } from 'navigation/rootNavigator' +import { RNS_ADDRESSES_BY_CHAIN_ID } from 'screens/rnsManager/types' import { rnsManagerStyles } from '../rnsManager/rnsManagerStyles' @@ -55,7 +56,7 @@ export const ProfileCreateScreen = ({ }: ProfileStackScreenProps) => { const dispatch = useAppDispatch() const profile = useAppSelector(selectProfile) - const { wallet, chainType } = useAppSelector(selectWalletState) + const { wallet, chainType, chainId } = useAppSelector(selectWalletState) const [infoBoxClosed, setInfoBoxClosed] = useState( profile.infoBoxClosed ?? false, ) @@ -136,7 +137,10 @@ export const ProfileCreateScreen = ({ profile.alias && profile.status === ProfileStatus.REQUESTING ) { - const rns = new RnsProcessor({ wallet }) + const rns = new RnsProcessor({ + wallet, + rnsAddresses: RNS_ADDRESSES_BY_CHAIN_ID[chainId], + }) commitment( rns, profile.alias.split('.rsk')[0], diff --git a/src/screens/rnsManager/DomainInput.tsx b/src/screens/rnsManager/DomainInput.tsx index 148ce09cc..d7515bbc4 100644 --- a/src/screens/rnsManager/DomainInput.tsx +++ b/src/screens/rnsManager/DomainInput.tsx @@ -14,8 +14,10 @@ import { Input, Typography } from 'components/index' import { sharedColors } from 'shared/constants' import { castStyle } from 'shared/utils' import { colors } from 'src/styles' +import { useAppSelector } from 'store/storeUtils' +import { selectChainId } from 'store/slices/settingsSlice' +import { RNS_ADDRESSES_BY_CHAIN_ID } from 'screens/rnsManager/types' -import addresses from './addresses.json' import { minDomainLength } from './SearchDomainScreen' interface Props { @@ -55,6 +57,7 @@ export const DomainInput = ({ const [domainAvailability, setDomainAvailability] = useState( DomainStatus.NONE, ) + const chainId = useAppSelector(selectChainId) const { t } = useTranslation() const errorType = error?.type const errorMessage = error?.message @@ -62,12 +65,12 @@ export const DomainInput = ({ const rskRegistrar = useMemo( () => new RSKRegistrar( - addresses.rskOwnerAddress, - addresses.fifsAddrRegistrarAddress, - addresses.rifTokenAddress, + RNS_ADDRESSES_BY_CHAIN_ID[chainId].rskOwnerAddress, + RNS_ADDRESSES_BY_CHAIN_ID[chainId].fifsAddrRegistrarAddress, + RNS_ADDRESSES_BY_CHAIN_ID[chainId].rifTokenAddress, wallet, ), - [wallet], + [wallet, chainId], ) const searchDomain = useCallback( async (domain: string) => { diff --git a/src/screens/rnsManager/PurchaseDomainScreen.tsx b/src/screens/rnsManager/PurchaseDomainScreen.tsx index 5de0e4d21..136c38f87 100644 --- a/src/screens/rnsManager/PurchaseDomainScreen.tsx +++ b/src/screens/rnsManager/PurchaseDomainScreen.tsx @@ -36,7 +36,8 @@ import { import { useAppDispatch, useAppSelector } from 'store/storeUtils' import { rootTabsRouteNames } from 'navigation/rootNavigator' import { handleDomainTransactionStatusChange } from 'screens/rnsManager/utils' -import { selectWallet } from 'store/slices/settingsSlice' +import { selectChainId, selectWallet } from 'store/slices/settingsSlice' +import { RNS_ADDRESSES_BY_CHAIN_ID } from 'screens/rnsManager/types' import { rnsManagerStyles } from './rnsManagerStyles' @@ -52,6 +53,7 @@ export const PurchaseDomainScreen = ({ navigation }: Props) => { const rifToken = useRifToken() const wallet = useAppSelector(selectWallet) const profile = useAppSelector(selectProfile) + const chainId = useAppSelector(selectChainId) const alias = profile.alias const duration = profile.duration || 1 const profileStatus = useAppSelector(selectProfileStatus) @@ -64,8 +66,9 @@ export const PurchaseDomainScreen = ({ navigation }: Props) => { dispatch, wallet, ), + rnsAddresses: RNS_ADDRESSES_BY_CHAIN_ID[chainId], }), - [dispatch, wallet], + [dispatch, wallet, chainId], ) const methods = useForm() diff --git a/src/screens/rnsManager/SearchDomainScreen.tsx b/src/screens/rnsManager/SearchDomainScreen.tsx index 2f291fe63..6d477a6e3 100644 --- a/src/screens/rnsManager/SearchDomainScreen.tsx +++ b/src/screens/rnsManager/SearchDomainScreen.tsx @@ -36,6 +36,7 @@ import { settingsStackRouteNames } from 'src/navigation/settingsNavigator/types' import { handleDomainTransactionStatusChange } from 'screens/rnsManager/utils' import { ConfirmationModal } from 'components/modal' import { selectWalletState } from 'store/slices/settingsSlice' +import { RNS_ADDRESSES_BY_CHAIN_ID } from 'screens/rnsManager/types' import { DomainInput } from './DomainInput' import { rnsManagerStyles } from './rnsManagerStyles' @@ -50,7 +51,8 @@ interface FormValues { } export const SearchDomainScreen = ({ navigation }: Props) => { - const { wallet, walletIsDeployed } = useAppSelector(selectWalletState) + const { wallet, walletIsDeployed, chainId } = + useAppSelector(selectWalletState) const { isDeployed, loading } = walletIsDeployed const [isDomainOwned, setIsDomainOwned] = useState(false) const [validDomain, setValidDomain] = useState(false) @@ -112,8 +114,9 @@ export const SearchDomainScreen = ({ navigation }: Props) => { dispatch, wallet, ), + rnsAddresses: RNS_ADDRESSES_BY_CHAIN_ID[chainId], }), - [dispatch, wallet], + [dispatch, wallet, chainId], ) const onSubmit = useCallback( diff --git a/src/screens/rnsManager/addresses.json b/src/screens/rnsManager/addresses.json index 432318403..c0631bef2 100644 --- a/src/screens/rnsManager/addresses.json +++ b/src/screens/rnsManager/addresses.json @@ -1,6 +1,14 @@ { - "rskOwnerAddress": "0xca0a477e19bac7e0e172ccfd2e3c28a7200bdb71", - "fifsAddrRegistrarAddress": "0x90734bd6bf96250a7b262e2bc34284b0d47c1e8d", - "rifTokenAddress": "0x19f64674d8a5b4e652319f5e239efd3bc969a1fe", - "rnsRegistryAddress": "0x7d284aaac6e925aad802a53c0c69efe3764597b8" + "TESTNET": { + "rskOwnerAddress": "0xca0a477e19bac7e0e172ccfd2e3c28a7200bdb71", + "fifsAddrRegistrarAddress": "0x90734bd6bf96250a7b262e2bc34284b0d47c1e8d", + "rifTokenAddress": "0x19f64674d8a5b4e652319f5e239efd3bc969a1fe", + "rnsRegistryAddress": "0x7d284aaac6e925aad802a53c0c69efe3764597b8" + }, + "MAINNET": { + "rskOwnerAddress": "0x45d3e4fb311982a06ba52359d44cb4f5980e0ef1", + "fifsAddrRegistrarAddress": "0xd9c79ced86ecf49f5e4a973594634c83197c35ab", + "rifTokenAddress": "0x2acc95758f8b5f583470ba265eb685a8f45fc9d5", + "rnsRegistryAddress": "0xcb868aeabd31e2b66f74e9a55cf064abb31a4ad5" + } } diff --git a/src/screens/rnsManager/types.ts b/src/screens/rnsManager/types.ts new file mode 100644 index 000000000..099b48858 --- /dev/null +++ b/src/screens/rnsManager/types.ts @@ -0,0 +1,18 @@ +import { ChainTypesByIdType } from 'shared/constants/chainConstants' + +import { TESTNET, MAINNET } from './addresses.json' + +export interface RNS_ADDRESSES_TYPE { + rskOwnerAddress: string + fifsAddrRegistrarAddress: string + rifTokenAddress: string + rnsRegistryAddress: string +} + +export const RNS_ADDRESSES_BY_CHAIN_ID: Record< + ChainTypesByIdType, + RNS_ADDRESSES_TYPE +> = { + 30: MAINNET, + 31: TESTNET, +}