Governance: Mnemonic import implemented for creating profile.

This commit is contained in:
Luis Fernando Molina committed 2021-08-18 12:17:29 +02:00
1 parent 0d2d91ef09
commit a42a4c025c
6 files changed
+352 -4207

No files matched your search

@@ -34,7 +34,7 @@
"config": true
},
"initialValues": {
"config": "{ \"githubUsername\": \"\"}"
"config": "{ \"githubUsername\": \"\", \"mnemonic\": \"\"}"
},
"addLeftIcons": true,
"level": 2,
@@ -13,24 +13,32 @@ function newGovernanceFunctionLibraryProfileConstructor() {
Some validations first...
*/
let githubUsername = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'githubUsername')
let mnemonic = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'mnemonic')
if (githubUsername === undefined || githubUsername === "") {
node.payload.uiObject.setErrorMessage("githubUsername config property missing.")
return
}
let userProfile = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(
node,
'User Profile',
UI.projects.foundations.spaces.designSpace.workspace.workspaceNode.rootNodes
)
createWallet()
createNewAccount()
function createWallet() {
let params
function createNewAccount() {
let params = {
method: 'createWalletAccount',
entropy: node.id + (new Date()).valueOf()
/*
If the user provides a mnemonic then we will get the private key and address from it,
otherwise, we will create a new private key and address.
*/
if (mnemonic === undefined || mnemonic === "") {
params = {
method: 'createWalletAccount',
entropy: node.id + (new Date()).valueOf()
}
} else {
params = {
method: 'mnemonicToPrivateKey',
mnemonic: mnemonic
}
}
let url = 'WEB3' // We will access the default Client WEB3 endpoint.
@@ -41,7 +49,6 @@ function newGovernanceFunctionLibraryProfileConstructor() {
/* Lets check the result of the call through the http interface */
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object')
return
}
@@ -49,8 +56,16 @@ function newGovernanceFunctionLibraryProfileConstructor() {
/* Lets check the result of the method call */
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
return
if (mnemonic === undefined || mnemonic === "") {
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
console.log('Call to WEB3 Server failed. ' + response.error)
return
} else {
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct.' + response.error)
console.log('Call to WEB3 Server failed. Most likely the Mnemonic provided is not correct.' + response.error)
return
}
}
signUserProfileData(response.address, response.privateKey)
@@ -85,6 +100,11 @@ function newGovernanceFunctionLibraryProfileConstructor() {
console.log('Call to WEB3 Server failed. ' + response.error)
return
}
let userProfile = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(
node,
'User Profile',
UI.projects.foundations.spaces.designSpace.workspace.workspaceNode.rootNodes
)
/*
We store at the User Profile the Signed githubUsername
*/
@@ -103,7 +123,11 @@ function newGovernanceFunctionLibraryProfileConstructor() {
/*
Show nice message.
*/
node.payload.uiObject.setInfoMessage("Profile Private Key has been successfully created. User Profile installed as a plugin and saved. Use the Private Key at a crypto wallet and delete this node once done.", 10000)
if (mnemonic === undefined || mnemonic === "") {
node.payload.uiObject.setInfoMessage("Profile Private Key has been successfully created. User Profile installed as a plugin and saved. Use the Private Key at a crypto wallet and delete this node once done.", 10000)
} else {
node.payload.uiObject.setInfoMessage("Mnemonic successfully imported. User Profile installed as a plugin and saved. Your external wallet was sucessfully linked to your profile.", 10000)
}
}
}
}