From cf03cb4e51cccfc9e8fcdc79b9d827bba4425d70 Mon Sep 17 00:00:00 2001 From: xomf Date: Sun, 1 Jun 2025 18:03:34 +0000 Subject: [PATCH] Add eCash.lua --- eCash.lua | 265 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 eCash.lua diff --git a/eCash.lua b/eCash.lua new file mode 100644 index 0000000..9d587d2 --- /dev/null +++ b/eCash.lua @@ -0,0 +1,265 @@ +local basalt = require("../lib/basalt") +local libcredit = require("../lib/libcredit_mobile") + +local username = "" +local main = basalt.getMainFrame() + +function show_notification(status) + local notifFrame = main:addFrame() + :setSize(26,4) + :setBackground(colours.grey) + + notifFrame:addButton() + :setText("Dismiss") + :setSize(26,1) + :setPosition(1,4) + :onClick(function() + notifFrame:destroy() + end) + + local label = notifFrame:addLabel() + + if status then + label:setText("Transaction successful") + :setPosition(4,2) + :setBackground(colours.lime) + :setForeground(colours.black) + notifFrame:setBackground(colours.lime) + else + label:setText("Transaction unsuccessful") + :setPosition(3,2) + :setBackground(colours.red) + :setForeground(colours.white) + notifFrame:setBackground(colours.red) + end +end + +local appFrame = main:addFrame() + :setVisible(false) + :setSize(26,19) + :setBackground(colours.white) + +local requestFrame = main:addFrame() + :setVisible(false) + :setSize(26,19) + :setBackground(colours.white) + + +requestFrame:addLabel() + :setText("Username: ") + :setPosition(2, 6) + :setSize(10, 1) + :setForeground(colours.black) + +local request_user_input = requestFrame:addInput() + :setPosition(12, 6) + :setSize(12, 1) + :setBackground(colours.lightGrey) + :setForeground(colours.black) + :setText("") + +requestFrame:addLabel() + :setText("Amount:   ") + :setPosition(2, 8) + :setSize(10, 1) + :setForeground(colours.black) + +local request_amount_input = requestFrame:addInput() + :setPosition(12, 8) + :setSize(12, 1) + :setBackground(colours.lightGrey) + :setForeground(colours.black) + :setText("") + +requestFrame:addButton() + :setText("Request") + :setPosition(7, 15) + :setSize(12, 3) + :setBackground(colours.blue) + :setForeground(colours.white) + :onClick(function(request_btn) + request_btn:setBackground(colours.black) + request_btn:setText("Pending") + local target_usr = request_user_input:getText() + local target_amount = request_amount_input:getText() + target_amount = tonumber(target_amount:match("^%d+$")) + + if not target_amount or target_amount <= 0 then + show_notification(false) + request_btn:setBackground(colours.blue) + request_btn:setText("Request") + return + end + + libcredit.addTransaction(target_usr, target_amount, username .. " [ecash]", username, function(successful) + request_btn:setBackground(colours.blue) + request_btn:setText("Request") + show_notification(successful) + refresh_ui() + appFrame:setVisible(true) + requestFrame:setVisible(false) + + if successful then + request_amount_input:setText("") + request_user_input:setText("") + end + end) + end) + +local sendFrame = main:addFrame() + :setVisible(false) + :setSize(26,19) + :setBackground(colours.white) + +sendFrame:addLabel() + :setText("Recipient: ") + :setPosition(2, 6) + :setSize(10, 1) + :setForeground(colours.black) + +local send_user_input = sendFrame:addInput() + :setPosition(12, 6) + :setSize(12, 1) + :setBackground(colours.lightGrey) + :setForeground(colours.black) + :setText("") + +sendFrame:addLabel() + :setText("Amount:   ") + :setPosition(2, 8) + :setSize(10, 1) + :setForeground(colours.black) + +local send_amount_input = sendFrame:addInput() + :setPosition(12, 8) + :setSize(12, 1) + :setBackground(colours.lightGrey) + :setForeground(colours.black) + :setText("") + +sendFrame:addButton() + :setText("Send") + :setPosition(7, 15) + :setSize(12, 3) + :setBackground(colours.blue) + :setForeground(colours.white) + :onClick(function(send_btn) + send_btn:setBackground(colours.black) + send_btn:setText("Pending") + local target_usr = send_user_input:getText() + local target_amount = send_amount_input:getText() + target_amount = tonumber(target_amount:match("^%d+$")) + + if not target_amount or target_amount <= 0 then + show_notification(false) + send_btn:setBackground(colours.blue) + send_btn:setText("Send") + return + end + + libcredit.addTransaction(username, target_amount, target_usr .. " [ecash]", target_usr, function(successful) + send_btn:setBackground(colours.blue) + send_btn:setText("Send") + show_notification(successful) + refresh_ui() + appFrame:setVisible(true) + sendFrame:setVisible(false) + + if successful then + send_amount_input:setText("") + send_user_input:setText("") + end + end) + end) + +local cash_label = appFrame:addBigFont() + :setText("__G") + :setPosition(6,2) + :setBackground(colours.white) + :setForeground(colours.black) + +local request_cash = appFrame:addButton() + :setText("Request") + :setPosition(8,10) + :setSize(10, 3) + :setBackground(colours.green) + :setForeground(colours.white) + :onClick(function() + requestFrame:setVisible(true) + appFrame:setVisible(false) + end) + +local send_cash = appFrame:addButton() + :setText("Send") + :setPosition(8,15) + :setSize(10, 3) + :setBackground(colours.orange) + :setForeground(colours.white) + :onClick(function() + sendFrame:setVisible(true) + appFrame:setVisible(false) + end) + +function refresh_ui() + libcredit.getCredit(username, function(amount) + local amount_str = amount .. "G" + cash_label:setText(amount_str) + + if #amount_str < 6 then + cash_label:setPosition(6 - (#amount_str / 4) - 1,2) + else + cash_label:setSize(26,4) + cash_label:setPosition(1,2) + end + end) +end + +local login = main:addFrame() + :setBackground(colours.grey) + :setPosition(1,1) + :setSize(26,19) + +login:addLabel() + :setText("Username: ") + :setPosition(2, 3) + :setSize(10, 1) + :setForeground(colours.white) + +local usernameInput = login:addInput() + :setPosition(12, 3) + :setSize(12, 1) + :setBackground(colours.lightGrey) + :setForeground(colours.black) + :setText("") + +local loginButton = login:addButton() + :setText("Login") + :setPosition(9, 15) + :setSize(8, 3) + :setBackground(colours.blue) + :setForeground(colours.white) + :onClick(function() + + + username = usernameInput:getText() + + if not fs.exists("/.usrcache") then + local file = fs.open("/.usrcache","w") + file.write(username) + file.close() + end + + login:setVisible(false) + appFrame:setVisible(true) + refresh_ui() + + end) + +if fs.exists("/.usrcache") then + local file = fs.open("/.usrcache","r") + local username = file.readLine() + file.close() + usernameInput:setText(username) +end + +basalt.run() \ No newline at end of file