Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast withdraw dialog updates #103

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions net.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ extends Node
# Enable this for debug printing in net.gd and fast_withdraw.gd
var print_debug_net : bool = false

# TODO rename this and move it on the server as well?
const FAST_WITHDRAW_CHAIN_TESTCHAIN : String = "Testchain"
const FAST_WITHDRAW_CHAIN_THUNDER : String = "Thunder"
const FAST_WITHDRAW_CHAIN_ZSIDE : String = "ZSide"

# Server signals
signal fast_withdraw_requested(peer : int, amount: float, destination: String)
signal fast_withdraw_invoice_paid(peer : int, txid: String, amount: float, destination: String)
signal fast_withdraw_requested(peer : int, chain_name : String, amount: float, destination: String)
signal fast_withdraw_invoice_paid(peer : int, chain_name : String, txid: String, amount: float, destination: String)

# Client signals
signal fast_withdraw_invoice(amount: float, destination: String)
signal fast_withdraw_complete(txid: String, amount: float, destination: String)

# TODO add params: SC #, MC fee, MC destination
# TODO add params: MC fee
@rpc("any_peer", "call_remote", "reliable")
func request_fast_withdraw(amount : float, destination : String) -> void:
func request_fast_withdraw(amount : float, chain_name: String, destination : String) -> void:
if print_debug_net:
print("Received fast withdrawal request")
print("Chain: ", chain_name)
print("Amount: ", amount)
print("Destination: ", destination)
print("Peer: ", multiplayer.get_remote_sender_id())

fast_withdraw_requested.emit(multiplayer.get_remote_sender_id(), amount, destination)
fast_withdraw_requested.emit(multiplayer.get_remote_sender_id(), chain_name, amount, destination)


@rpc("authority", "call_remote", "reliable")
Expand All @@ -37,15 +40,16 @@ func receive_fast_withdraw_invoice(amount : float, destination : String) -> void


@rpc("any_peer", "call_remote", "reliable")
func invoice_paid(txid: String, amount : float, destination : String) -> void:
func invoice_paid(chain_name : String, txid: String, amount : float, destination : String) -> void:
if print_debug_net:
print("Paid fast withdrawal invoice")
print("Chain: ", chain_name)
print("Amount: ", amount)
print("Destination: ", destination)
print("Txid: ", txid)
print("Peer: ", multiplayer.get_remote_sender_id())

fast_withdraw_invoice_paid.emit(multiplayer.get_remote_sender_id(), txid, amount, destination)
fast_withdraw_invoice_paid.emit(multiplayer.get_remote_sender_id(), chain_name, txid, amount, destination)


@rpc("authority", "call_remote", "reliable")
Expand Down
48 changes: 31 additions & 17 deletions ui/components/fast_withdraw/fast_withdraw.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
extends Control

const SERVER_LOCALHOST = "127.0.0.1"
const SERVER_L2L_GA = "172.105.148.135"

const PORT = 8382
const SERVER_LOCALHOST : String = "127.0.0.1"
const SERVER_L2L_GA : String = "172.105.148.135"
const PORT : int = 8382

var invoice_address : String = ""
var connected_to_server : bool = false
var selected_chain : String = ""

signal fast_withdraw_server_connection_status_changed

func _ready() -> void:
$LabelConnectionStatus.visible = false

selected_chain = $"/root/Net".FAST_WITHDRAW_CHAIN_TESTCHAIN

multiplayer.connected_to_server.connect(_on_connected_to_withdrawal_server)
multiplayer.connection_failed.connect(_on_failed_connect_to_withdrawal_server)
multiplayer.server_disconnected.connect(_on_disconnected_from_withdrawal_server)
Expand All @@ -23,25 +29,28 @@ func _on_connected_to_withdrawal_server() -> void:

$LabelConnectionStatus.text = "Connected"

$ButtonConnect.disabled = true
connected_to_server = true
fast_withdraw_server_connection_status_changed.emit()


func _on_disconnected_from_withdrawal_server() -> void:
if $"/root/Net".print_debug_net:
print("Disonnected to fast withdraw server")
print("Disonnected from fast withdraw server")

$LabelConnectionStatus.text = "Not Connected"

$ButtonConnect.disabled = false
$LabelConnectionStatus.text = "Disconnected"
$LabelInvoice.text = ""
connected_to_server = false
fast_withdraw_server_connection_status_changed.emit()


func _on_failed_connect_to_withdrawal_server() -> void:
if $"/root/Net".print_debug_net:
print("Failed to connect to fast withdraw server")

$LabelConnectionStatus.text = "Not Connected"

$ButtonConnect.disabled = false

connected_to_server = false
fast_withdraw_server_connection_status_changed.emit()


func connect_to_withdrawal_server() -> void:
Expand All @@ -63,8 +72,6 @@ func connect_to_withdrawal_server() -> void:

$LabelConnectionStatus.text = "Connecting..."

$ButtonConnect.disabled = true

multiplayer.multiplayer_peer = peer


Expand Down Expand Up @@ -107,13 +114,20 @@ func _on_button_copy_address_pressed() -> void:
func _on_button_invoice_paid_pressed() -> void:
# Tell the server we paid
var txid : String = $LineEditTXID.text
$"/root/Net".invoice_paid.rpc_id(1, txid, $SpinBoxAmount.value, $LineEditMainchainAddress.text)
$"/root/Net".invoice_paid.rpc_id(1, selected_chain, txid, $SpinBoxAmount.value, $LineEditMainchainAddress.text)


func _on_button_request_invoice_pressed() -> void:
# Establish connection with fast withdraw server
connect_to_withdrawal_server()
$LabelConnectionStatus.visible = true

await fast_withdraw_server_connection_status_changed

# Send fast withdraw request only to server
$"/root/Net".request_fast_withdraw.rpc_id(1, $SpinBoxAmount.value, $LineEditMainchainAddress.text)
$"/root/Net".request_fast_withdraw.rpc_id(1, $SpinBoxAmount.value, selected_chain, $LineEditMainchainAddress.text)


func _on_button_connect_pressed() -> void:
connect_to_withdrawal_server()
func _on_chain_selection_button_item_selected(index):
var selection_index = $ChainSelectionButton.get_selected()
selected_chain = $ChainSelectionButton.get_item_text(selection_index)
117 changes: 66 additions & 51 deletions ui/components/fast_withdraw/fast_withdraw.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,106 +13,121 @@ script = ExtResource("1_4itd0")

[node name="ButtonRequestInvoice" type="Button" parent="."]
layout_mode = 0
offset_left = 15.0
offset_top = 104.0
offset_right = 303.0
offset_bottom = 135.0
offset_left = 156.0
offset_top = 79.0
offset_right = 470.0
offset_bottom = 114.0
text = "Request fast withdrawal test invoice"

[node name="LineEditMainchainAddress" type="LineEdit" parent="."]
layout_mode = 0
offset_left = 14.0
offset_top = 67.0
offset_right = 429.0
offset_bottom = 98.0
offset_left = 10.0
offset_top = 12.0
offset_right = 425.0
offset_bottom = 43.0
placeholder_text = "Enter mainchain address"

[node name="LabelInvoice" type="Label" parent="."]
layout_mode = 0
offset_left = 22.0
offset_top = 147.0
offset_right = 62.0
offset_bottom = 170.0
offset_left = 18.0
offset_top = 135.0
offset_right = 58.0
offset_bottom = 158.0

[node name="ButtonInvoicePaid" type="Button" parent="."]
layout_mode = 0
offset_left = 16.0
offset_top = 278.0
offset_right = 117.0
offset_bottom = 309.0
offset_top = 298.0
offset_right = 126.0
offset_bottom = 333.0
text = "Invoice Paid"

[node name="LineEditTXID" type="LineEdit" parent="."]
layout_mode = 0
offset_left = 16.0
offset_top = 239.0
offset_top = 259.0
offset_right = 620.0
offset_bottom = 270.0
offset_bottom = 290.0
placeholder_text = "Enter L2 payment txid"

[node name="LabelComplete" type="Label" parent="."]
layout_mode = 0
offset_left = 19.0
offset_top = 321.0
offset_right = 550.0
offset_bottom = 344.0
offset_left = 17.0
offset_top = 341.0
offset_right = 548.0
offset_bottom = 364.0

[node name="SpinBoxAmount" type="SpinBox" parent="."]
layout_mode = 0
offset_left = 620.0
offset_top = 66.0
offset_right = 776.0
offset_bottom = 97.0
offset_left = 614.0
offset_top = 14.0
offset_right = 770.0
offset_bottom = 45.0
min_value = 1.0
value = 1.0
suffix = "BTC"

[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 443.0
offset_top = 71.0
offset_right = 608.0
offset_bottom = 94.0
offset_left = 441.0
offset_top = 17.0
offset_right = 606.0
offset_bottom = 40.0
text = "Amount to withdraw:
"

[node name="ButtonCopyAddress" type="Button" parent="."]
layout_mode = 0
offset_left = 499.0
offset_top = 176.0
offset_right = 612.0
offset_bottom = 207.0
offset_left = 390.0
offset_top = 181.0
offset_right = 515.0
offset_bottom = 216.0
text = "Copy Address
"

[node name="CheckButtonLocalhost" type="CheckButton" parent="."]
layout_mode = 0
offset_left = 268.0
offset_top = 24.0
offset_right = 535.0
offset_bottom = 55.0
text = "Use localhost (debug) server"
offset_left = 865.0
offset_top = 4.0
offset_right = 1016.0
offset_bottom = 35.0
text = "Debug server"

[node name="LabelConnectionStatus" type="Label" parent="."]
layout_mode = 0
offset_left = 488.0
offset_top = 88.0
offset_right = 604.0
offset_bottom = 111.0
text = "Not Connected"

[node name="ButtonConnect" type="Button" parent="."]
[node name="Label2" type="Label" parent="."]
layout_mode = 0
offset_left = 15.0
offset_top = 21.0
offset_right = 85.0
offset_bottom = 52.0
text = "connect
offset_left = 14.0
offset_top = 51.0
offset_right = 198.0
offset_bottom = 72.0
text = "Sidechain to withdraw from:
"

[node name="LabelConnectionStatus" type="Label" parent="."]
[node name="ChainSelectionButton" type="OptionButton" parent="."]
layout_mode = 0
offset_left = 100.0
offset_top = 27.0
offset_right = 216.0
offset_bottom = 50.0
text = "Not Connected"
offset_left = 16.0
offset_top = 79.0
offset_right = 40.0
offset_bottom = 99.0
item_count = 3
selected = 0
popup/item_0/text = "Testchain"
popup/item_0/id = 0
popup/item_1/text = "Thunder"
popup/item_1/id = 1
popup/item_2/text = "ZSide"
popup/item_2/id = 2

[connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_request_invoice_pressed"]
[connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_test_pressed"]
[connection signal="pressed" from="ButtonInvoicePaid" to="." method="_on_button_invoice_paid_pressed"]
[connection signal="pressed" from="ButtonInvoicePaid" to="." method="_on_button_test_complete_pressed"]
[connection signal="pressed" from="ButtonCopyAddress" to="." method="_on_button_copy_address_pressed"]
[connection signal="pressed" from="ButtonConnect" to="." method="_on_button_connect_pressed"]
[connection signal="item_selected" from="ChainSelectionButton" to="." method="_on_chain_selection_button_item_selected"]
Loading