-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: run alias registration in the background * fix: add custome hook * fix: request domain code to the custom hook * fix: request domain code to the custom hook * fix: request domain code to the custom hook * refactor: use new storage * fix: changes due storage refactor * fix: typo * fix: merge * fix: add missing code * fix: add missing code * fix: add missing code
- Loading branch information
Showing
8 changed files
with
165 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { RSKRegistrar } from '@rsksmart/rns-sdk' | ||
|
||
import { | ||
getAliasRegistration, | ||
hasAliasRegistration, | ||
IProfileRegistrationStore, | ||
saveAliasRegistration, | ||
} from 'src/storage/AliasRegistrationStore' | ||
import addresses from '../../screens/rnsManager/addresses.json' | ||
import { RIFWallet } from 'lib/core' | ||
|
||
export function useAliasRegistration(wallet: RIFWallet) { | ||
const rskRegistrar = new RSKRegistrar( | ||
addresses.rskOwnerAddress, | ||
addresses.fifsAddrRegistrarAddress, | ||
addresses.rifTokenAddress, | ||
wallet, | ||
) | ||
|
||
const registrationStarted = () => { | ||
const hasStartedRegistration = hasAliasRegistration() | ||
|
||
if (hasStartedRegistration) { | ||
const myAliasRegistration = getAliasRegistration() | ||
const hash = myAliasRegistration.commitToRegisterHash | ||
return !!hash | ||
} else { | ||
return false | ||
} | ||
} | ||
const readyToRegister = async (_hash?: string) => { | ||
if (registrationStarted()) { | ||
const myAliasRegistration: IProfileRegistrationStore = | ||
getAliasRegistration() | ||
const hash = _hash || myAliasRegistration.commitToRegisterHash | ||
const canReveal = await rskRegistrar.canReveal(hash) | ||
return await canReveal() | ||
} else { | ||
return false | ||
} | ||
} | ||
const getRegistrationData = getAliasRegistration | ||
|
||
const setRegistrationData = async ( | ||
alias: string, | ||
duration: number, | ||
): Promise<IProfileRegistrationStore> => { | ||
const response = await rskRegistrar.commitToRegister( | ||
alias, | ||
wallet.smartWallet.address, | ||
) | ||
|
||
saveAliasRegistration({ | ||
alias: alias, | ||
duration: duration, | ||
commitToRegisterSecret: response.secret, | ||
commitToRegisterHash: response.hash, | ||
}) | ||
await response.makeCommitmentTransaction.wait() | ||
console.log('commitToRegister succesfull') | ||
return getRegistrationData() | ||
} | ||
|
||
return { | ||
registrationStarted, | ||
readyToRegister, | ||
getRegistrationData, | ||
setRegistrationData, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { MainStorage } from './MainStorage' | ||
|
||
const key = 'ALIAS_REGISTRATION' | ||
export type IProfileRegistrationStore = { | ||
alias: string | ||
duration: number | ||
commitToRegisterHash: string | ||
commitToRegisterSecret: string | ||
} | ||
export const hasAliasRegistration = () => MainStorage.has(key) | ||
|
||
export const getAliasRegistration = () => { | ||
const jsonProfile = MainStorage.has(key) ? MainStorage.get(key) : '{}' | ||
const store: IProfileRegistrationStore = JSON.parse(jsonProfile || '{}') | ||
return store | ||
} | ||
|
||
export const deleteAliasRegistration = () => MainStorage.delete(key) | ||
|
||
export const saveAliasRegistration = ( | ||
aliasRegistration: IProfileRegistrationStore, | ||
) => MainStorage.set(key, JSON.stringify(aliasRegistration)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters