shop password tweak

This commit is contained in:
xAnavrins
2019-07-23 00:21:11 -04:00
parent 3665bfb26a
commit 5616ef0007

View File

@@ -1,5 +1,5 @@
local UI = require('opus.ui')
local Krist = require('swshop.krist')--??
local Krist = require('swshop.krist')
local colors = _G.colors
local device = _G.device
@@ -34,6 +34,7 @@ local wizardPage = UI.WizardPage {
},
[4] = UI.Chooser {
width = 9,
formIndex = 5,
formLabel = 'Font Size', formKey = 'textScale',
nochoice = 'Small',
choices = {
@@ -42,49 +43,10 @@ local wizardPage = UI.WizardPage {
},
help = 'Adjust text scaling',
},
[5] = UI.TextEntry {
formLabel = 'Password', formKey = 'password',
shadowText = 'password or private key',
limit = 256,
required = true,
pass = true,
help = 'Krist wallet password',
},
[6] = UI.Checkbox {
formLabel = 'Is private key', formKey = 'isPrivateKey',
help = 'Password is in private key format',
limit = 64,
ispkey = true,
},
[7] = UI.TextEntry {
inactive = true,
backgroundColor = colors.cyan,
textColor = colors.yellow,
formLabel = 'Using address',
formKey = 'address',
},
},
}
local function makeAddress(text, isPrivateKey)
local privKey = text
if not isPrivateKey then
privKey = Krist.toKristWalletFormat(privKey)
end
return Krist.makev2address(privKey)
end
function wizardPage.form:eventHandler(event)
if (event.type == 'text_change' and event.element.pass) or
(event.type == 'checkbox_change' and event.element.ispkey) then
self[7].value = makeAddress(self[5].value, self[6].value)
self[7]:draw()
end
return UI.Form.eventHandler(self, event)
end
function wizardPage:setNode(node)
node.address = node.password and makeAddress(node.password, node.isPrivateKey) or ''
self.form:setValues(node)
end
@@ -110,4 +72,68 @@ function wizardPage:isValidFor(node)
return node.mtype == 'shop'
end
UI:getPage('nodeWizard').wizard:add({ storeFront = wizardPage })
-- [[Password View]] --
local passwordPage = UI.WizardPage {
title = 'Krist Settings',
index = 3,
backgroundColor = colors.cyan,
form = UI.Form {
x = 2, ex = -2, y = 1, ey = -2,
manualControls = true,
passEntry = UI.TextEntry {
formIndex = 1,
formLabel = 'Password', formKey = 'password',
shadowText = 'Password',
help = 'Krist wallet password',
limit = 256,
required = true,
pass = true,
},
pkeyCheck = UI.Checkbox {
formIndex = 2,
formLabel = 'Is private key', formKey = 'isPrivateKey',
help = 'Password is in private key format',
ispkey = true,
},
preview = UI.TextEntry {
formIndex = 4,
formLabel = 'Using address', formKey = 'address',
backgroundColor = colors.cyan,
textColor = colors.yellow,
inactive = true,
},
},
}
local function makeAddress(text, isPrivateKey)
local privKey = text
if not isPrivateKey then
privKey = Krist.toKristWalletFormat(privKey)
end
return Krist.makev2address(privKey)
end
function passwordPage.form:eventHandler(event)
if (event.type == 'text_change' and event.element.pass) or
(event.type == 'checkbox_change' and event.element.ispkey) then
self.passEntry.shadowText = self.pkeyCheck.value and 'Private key' or 'Password'
self.preview.value = makeAddress(self.passEntry.value, self.pkeyCheck.value)
self:draw()
end
return UI.Form.eventHandler(self, event)
end
function passwordPage:setNode(node)
node.address = node.password and makeAddress(node.password, node.isPrivateKey) or ''
self.form:setValues(node)
end
function passwordPage:validate()
return self.form:save()
end
function passwordPage:isValidFor(node)
return node.mtype == 'shop'
end
UI:getPage('nodeWizard').wizard:add({ storeFronta = wizardPage, storeFrontb = passwordPage })