Build a Wallet tutorial: text for first few steps

This commit is contained in:
mDuo13
2022-01-18 19:04:34 -08:00
parent 773cabbe5c
commit 14a1fc84d7
11 changed files with 209 additions and 38 deletions

View File

@@ -9,16 +9,13 @@ class TWaXLFrame(wx.Frame):
user interface, main frame.
"""
def __init__(self, url):
super(TWaXLFrame, self).__init__(None, title="TWaXL")
wx.Frame.__init__(self, None, title="TWaXL", size=wx.Size(800,400))
self.client = xrpl.clients.JsonRpcClient(url)
main_panel = wx.Panel(self)
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_panel.SetSizer(main_sizer)
st = wx.StaticText(main_panel, label=self.get_validated_ledger())
main_sizer.Add(st, wx.SizerFlags().Border(wx.TOP|wx.LEFT, 25))
self.ledger_info = wx.StaticText(main_panel,
label=self.get_validated_ledger())
def get_validated_ledger(self):
try:
@@ -38,7 +35,6 @@ class TWaXLFrame(wx.Frame):
if __name__ == "__main__":
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
app = wx.App()
frame = TWaXLFrame(JSON_RPC_URL)
frame.Show()

View File

@@ -1,10 +1,8 @@
# "Build a Wallet" tutorial, step 2: Watch ledger closes from a worker thread.
import xrpl
import asyncio
import re
import wx
import asyncio
from threading import Thread
class XRPLMonitorThread(Thread):
@@ -15,6 +13,8 @@ class XRPLMonitorThread(Thread):
"""
def __init__(self, url, gui, loop):
Thread.__init__(self, daemon=True)
# Note: For thread safety, this thread should treat self.gui as
# read-only; to modify the GUI, use wx.CallAfter(...)
self.gui = gui
self.url = url
self.loop = loop
@@ -47,8 +47,7 @@ class XRPLMonitorThread(Thread):
Set up initial subscriptions and populate the GUI with data from the
ledger on startup. Requires that self.client be connected first.
"""
# Set up 2 subscriptions: all new ledgers, and any new transactions that
# affect the chosen account.
# Set up a subscriptions for new ledgers
response = await self.client.request(xrpl.models.requests.Subscribe(
streams=["ledger"]
))
@@ -63,11 +62,9 @@ class TWaXLFrame(wx.Frame):
Tutorial Wallet for the XRP Ledger (TWaXL)
user interface, main frame.
"""
def __init__(self, url, test_network=True):
def __init__(self, url):
wx.Frame.__init__(self, None, title="TWaXL", size=wx.Size(800,400))
self.test_network = test_network
self.build_ui()
# Start background thread for updates from the ledger ------------------
@@ -77,8 +74,10 @@ class TWaXLFrame(wx.Frame):
self.run_bg_job(self.worker.watch_xrpl())
def build_ui(self):
"""
Called during __init__ to set up all the GUI components.
"""
main_panel = wx.Panel(self)
self.ledger_info = wx.StaticText(main_panel, label="Not connected")
main_sizer = wx.BoxSizer(wx.VERTICAL)
@@ -107,6 +106,6 @@ class TWaXLFrame(wx.Frame):
if __name__ == "__main__":
WS_URL = "wss://s.altnet.rippletest.net:51233" # Testnet
app = wx.App()
frame = TWaXLFrame(WS_URL, test_network=True)
frame = TWaXLFrame(WS_URL)
frame.Show()
app.MainLoop()

View File

@@ -1,10 +1,8 @@
# "Build a Wallet" tutorial, step 3: Take account input & show account info
import xrpl
import asyncio
import re
import wx
import asyncio
from threading import Thread
from decimal import Decimal
@@ -16,6 +14,8 @@ class XRPLMonitorThread(Thread):
"""
def __init__(self, url, gui, loop):
Thread.__init__(self, daemon=True)
# Note: For thread safety, this thread should treat self.gui as
# read-only; to modify the GUI, use wx.CallAfter(...)
self.gui = gui
self.url = url
self.loop = loop
@@ -129,6 +129,9 @@ class TWaXLFrame(wx.Frame):
self.run_bg_job(self.worker.watch_xrpl_account(address, wallet))
def build_ui(self):
"""
Called during __init__ to set up all the GUI components.
"""
main_panel = wx.Panel(self)
self.acct_info_area = wx.StaticBox(main_panel, label="Account Info")
@@ -148,7 +151,6 @@ class TWaXLFrame(wx.Frame):
(lbl_xrp_bal, self.st_xrp_balance),
(lbl_reserve, self.st_reserve)) )
# Ledger info text. One multi-line static text, unlike the account area.
self.ledger_info = wx.StaticText(main_panel, label="Not connected")
main_sizer = wx.BoxSizer(wx.VERTICAL)
@@ -156,7 +158,6 @@ class TWaXLFrame(wx.Frame):
main_sizer.Add(self.ledger_info, 1, flag=wx.EXPAND|wx.ALL, border=5)
main_panel.SetSizer(main_sizer)
def run_bg_job(self, job):
"""
Schedules a job to run asynchronously in the XRPL worker thread.

View File

@@ -1,12 +1,11 @@
# "Build a Wallet" tutorial, step 4: Show transaction history
import xrpl
import asyncio
import re
import wx
import wx.dataview
import wx.adv
import asyncio
import re
from threading import Thread
from decimal import Decimal
@@ -18,6 +17,8 @@ class XRPLMonitorThread(Thread):
"""
def __init__(self, url, gui, loop):
Thread.__init__(self, daemon=True)
# Note: For thread safety, this thread should treat self.gui as
# read-only; to modify the GUI, use wx.CallAfter(...)
self.gui = gui
self.url = url
self.loop = loop
@@ -139,6 +140,9 @@ class TWaXLFrame(wx.Frame):
self.run_bg_job(self.worker.watch_xrpl_account(address, wallet))
def build_ui(self):
"""
Called during __init__ to set up all the GUI components.
"""
self.tabs = wx.Notebook(self, style=wx.BK_DEFAULT)
# Tab 1: "Summary" pane ------------------------------------------------
main_panel = wx.Panel(self.tabs)
@@ -161,7 +165,6 @@ class TWaXLFrame(wx.Frame):
(lbl_xrp_bal, self.st_xrp_balance),
(lbl_reserve, self.st_reserve)) )
# Ledger info text. One multi-line static text, unlike the account area.
self.ledger_info = wx.StaticText(main_panel, label="Not connected")
main_sizer = wx.BoxSizer(wx.VERTICAL)

View File

@@ -2,12 +2,11 @@
# This step finally introduces events from the GUI to the worker thread.
import xrpl
import asyncio
import re
import wx
import wx.dataview
import wx.adv
import asyncio
import re
from threading import Thread
from decimal import Decimal
@@ -19,6 +18,8 @@ class XRPLMonitorThread(Thread):
"""
def __init__(self, url, gui, loop):
Thread.__init__(self, daemon=True)
# Note: For thread safety, this thread should treat self.gui as
# read-only; to modify the GUI, use wx.CallAfter(...)
self.gui = gui
self.url = url
self.loop = loop
@@ -244,6 +245,9 @@ class TWaXLFrame(wx.Frame):
self.run_bg_job(self.worker.watch_xrpl_account(address, wallet))
def build_ui(self):
"""
Called during __init__ to set up all the GUI components.
"""
self.tabs = wx.Notebook(self, style=wx.BK_DEFAULT)
# Tab 1: "Summary" pane ------------------------------------------------
main_panel = wx.Panel(self.tabs)
@@ -273,8 +277,6 @@ class TWaXLFrame(wx.Frame):
self.sxb.Disable()
self.Bind(wx.EVT_BUTTON, self.click_send_xrp, source=self.sxb)
# Ledger info text. One multi-line static text, unlike the account area.
self.ledger_info = wx.StaticText(main_panel, label="Not connected")
main_sizer = wx.BoxSizer(wx.VERTICAL)

View File

@@ -2,12 +2,11 @@
# This step adds sanity checks to the Send XRP dialog, along with some other
# small improvements.
import xrpl
import asyncio
import re
import wx
import wx.dataview
import wx.adv
import asyncio
import re
from threading import Thread
from decimal import Decimal
@@ -21,6 +20,8 @@ class XRPLMonitorThread(Thread):
"""
def __init__(self, url, gui, loop):
Thread.__init__(self, daemon=True)
# Note: For thread safety, this thread should treat self.gui as
# read-only; to modify the GUI, use wx.CallAfter(...)
self.gui = gui
self.url = url
self.loop = loop
@@ -393,6 +394,9 @@ class TWaXLFrame(wx.Frame):
self.run_bg_job(self.worker.watch_xrpl_account(address, wallet))
def build_ui(self):
"""
Called during __init__ to set up all the GUI components.
"""
self.tabs = wx.Notebook(self, style=wx.BK_DEFAULT)
# Tab 1: "Summary" pane ------------------------------------------------
main_panel = wx.Panel(self.tabs)
@@ -422,8 +426,6 @@ class TWaXLFrame(wx.Frame):
self.sxb.Disable()
self.Bind(wx.EVT_BUTTON, self.click_send_xrp, source=self.sxb)
# Ledger info text. One multi-line static text, unlike the account area.
self.ledger_info = wx.StaticText(main_panel, label="Not connected")
main_sizer = wx.BoxSizer(wx.VERTICAL)

View File

@@ -1,2 +1,4 @@
xrpl-py==1.1.1
wxPython=4.1.1
xrpl-py==1.3.0
wxPython==4.1.1
toml==0.10.2
requests==2.25.1