Skip to content

Commit

Permalink
US-1955 Added mainnet contracts and fixed rns in mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Freshenext committed Sep 28, 2023
1 parent 8966026 commit 21ddfa5
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 35 deletions.
16 changes: 10 additions & 6 deletions src/lib/rns/RnsProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down
53 changes: 40 additions & 13 deletions src/redux/slices/contactsSlice/constants.ts
Original file line number Diff line number Diff line change
@@ -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<string, Contact> = {
[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<string, Contact> = {
[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,
},
}
2 changes: 1 addition & 1 deletion src/redux/slices/contactsSlice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/screens/profile/ProfileCreateScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -55,7 +56,7 @@ export const ProfileCreateScreen = ({
}: ProfileStackScreenProps<profileStackRouteNames.ProfileCreateScreen>) => {
const dispatch = useAppDispatch()
const profile = useAppSelector(selectProfile)
const { wallet, chainType } = useAppSelector(selectWalletState)
const { wallet, chainType, chainId } = useAppSelector(selectWalletState)
const [infoBoxClosed, setInfoBoxClosed] = useState<boolean>(
profile.infoBoxClosed ?? false,
)
Expand Down Expand Up @@ -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],
Expand Down
13 changes: 8 additions & 5 deletions src/screens/rnsManager/DomainInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -55,19 +57,20 @@ export const DomainInput = ({
const [domainAvailability, setDomainAvailability] = useState<DomainStatus>(
DomainStatus.NONE,
)
const chainId = useAppSelector(selectChainId)
const { t } = useTranslation()
const errorType = error?.type
const errorMessage = error?.message

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) => {
Expand Down
7 changes: 5 additions & 2 deletions src/screens/rnsManager/PurchaseDomainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
Expand All @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions src/screens/rnsManager/SearchDomainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<boolean>(false)
const [validDomain, setValidDomain] = useState<boolean>(false)
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 12 additions & 4 deletions src/screens/rnsManager/addresses.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
18 changes: 18 additions & 0 deletions src/screens/rnsManager/types.ts
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 21ddfa5

Please sign in to comment.