From e73ce3875b49f74e02a566a61d2e8f42191e232f Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sun, 21 Jul 2019 13:58:25 -0600 Subject: [PATCH] milo shop updates --- swshop/Shoplogs.lua | 2 +- swshop/shopConfig.lua | 9 +++++++-- swshop/shopView.lua | 2 +- swshop/swshop.lua | 25 ++++++++++++------------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/swshop/Shoplogs.lua b/swshop/Shoplogs.lua index 476744b..2427bc4 100644 --- a/swshop/Shoplogs.lua +++ b/swshop/Shoplogs.lua @@ -140,7 +140,7 @@ end function page.grid:getDisplayValues(row) row = Util.shallowCopy(row) local x = row.recipient - row.from = x:match('(%w+)@') or x + row.from = x and x:match('(%w+)@') or row.from return row end diff --git a/swshop/shopConfig.lua b/swshop/shopConfig.lua index 573f7a4..0c157a1 100644 --- a/swshop/shopConfig.lua +++ b/swshop/shopConfig.lua @@ -21,7 +21,7 @@ local wizardPage = UI.WizardPage { }, [2] = UI.TextEntry { formLabel = 'Password', formKey = 'password', - shadowText = 'password', + shadowText = 'password or private key', limit = 256, required = true, help = 'Krist wallet password', @@ -38,7 +38,12 @@ local wizardPage = UI.WizardPage { help = 'Password is in private key format', limit = 64, }, - [5] = UI.Chooser { + [5] = UI.Checkbox { + formLabel = 'Single shop', formKey = 'refundInvalid', + help = 'Only this shop using this domain', + limit = 64, + }, + [6] = UI.Chooser { width = 9, formLabel = 'Font Size', formKey = 'textScale', nochoice = 'Small', diff --git a/swshop/shopView.lua b/swshop/shopView.lua index 9880a01..223ff6c 100644 --- a/swshop/shopView.lua +++ b/swshop/shopView.lua @@ -18,7 +18,7 @@ local function startShop(node) if shopTab then multishell.terminate(shopTab) end - shopTab = shell.openTab('/packages/swshop/swshop.lua', node.domain, node.password, node.isPrivateKey and 'true') + shopTab = shell.openTab('/packages/swshop/swshop.lua', node.name) end -- node has been reconfigured diff --git a/swshop/swshop.lua b/swshop/swshop.lua index 2c6a35a..9e8aa0d 100644 --- a/swshop/swshop.lua +++ b/swshop/swshop.lua @@ -1,4 +1,5 @@ -local Util = require('opus.util') +local Config = require('opus.config') +local Util = require('opus.util') local fs = _G.fs local os = _G.os @@ -19,6 +20,7 @@ local rs = _G.rs local textutils = _G.textutils local chat = device['plethora:chat'] +local storage = Config.load('storage') rs.setOutput('top', false) @@ -26,14 +28,9 @@ r.init(jua) w.init(jua) k.init(jua, json, w, r) -local function Syntax() - error('Syntax: swshop [domain] [password | privateKey] [isPrivateKey]') -end - -local args = { ... } -local domain = args[1] or Syntax() -local password = args[2] or Syntax() -local privatekey = args[3] and args[2] or k.toKristWalletFormat(password) +local node = ({ ... })[1] or error('Node name is required') +local config = storage[node] +local privatekey = config.isPrivateKey and config.password or k.toKristWalletFormat(config.password) local address = k.makev2address(privatekey) jua.on("terminate", function() @@ -72,7 +69,7 @@ local function handleTransaction(transaction) if to ~= address or not transaction.metadata then return end local metadata = k.parseMeta(transaction.metadata) - if not metadata.domain or metadata.domain ~= domain then return end + if not metadata.domain or metadata.domain ~= config.domain then return end local recipient = metadata.meta and (metadata.meta["return"] or from) or from print("Handling transaction from ", recipient) @@ -98,8 +95,10 @@ local function handleTransaction(transaction) if not t.itemId or not t.price then print('invalid item') logTransaction(t, { reason = 'invalid item' }) - --return refundTransaction(value, "error=Item specified is not valid") - return -- there could be multiple stores... + if config.refundInvalid then + return refundTransaction(value, "error=Item specified is not valid") + end + return -- multiple store setup end if value < t.price then @@ -141,7 +140,7 @@ local function handleTransaction(transaction) end local function connect() - print('opening store for: ' .. domain) + print('opening store for: ' .. config.domain) print('using address: ' .. address) local success, ws = await(k.connect, privatekey)