Skip to content
Merged
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
36 changes: 26 additions & 10 deletions examples/WinForms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 25 additions & 27 deletions examples/WinForms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Mx.NET.SDK.TransactionsManager;
using Mx.NET.SDK.WalletConnect;
using QRCoder;
using System.Diagnostics;
using WalletConnectSharp.Core;
using WalletConnectSharp.Sign.Models;
using WalletConnectSharp.Sign.Models.Engine.Events;
Expand All @@ -24,7 +23,7 @@ public partial class MainForm : Form
const string CHAIN_ID = "D";
const string PROJECT_ID = "c7d3aa2b21836c991357e8a56c252962";

IWalletConnect WalletConnect { get; set; }
private WalletConnect WalletConnect { get; set; }

private readonly NativeAuthClient _nativeAuthToken = default!;
private readonly NativeAuthServer _nativeAuthServer = default!;
Expand All @@ -36,14 +35,13 @@ public partial class MainForm : Form
public MainForm()
{
InitializeComponent();
this.ActiveControl = qrCodeImg;
CheckForIllegalCrossThreadCalls = false;
ActiveControl = qrCodeImg;

var metadata = new Metadata()
{
Name = "Mx.NET.WinForms",
Description = "Mx.NET.WinForms login testing",
Icons = new[] { "https://devnet.remarkable.tools/remarkabletools.ico" },
Icons = ["https://devnet.remarkable.tools/remarkabletools.ico"],
Url = "https://devnet.remarkable.tools/"
};
WalletConnect = new WalletConnect(metadata, PROJECT_ID, CHAIN_ID);
Expand All @@ -55,7 +53,7 @@ public MainForm()
});
var nativeAuthServerConfig = new NativeAuthServerConfig()
{
AcceptedOrigins = new[] { "https://devnet.remarkable.tools/" }
AcceptedOrigins = ["https://devnet.remarkable.tools/"]
};
_nativeAuthServer = new(nativeAuthServerConfig);
}
Expand Down Expand Up @@ -89,13 +87,9 @@ private async void MainForm_Load(object sender, EventArgs e)
LogMessage("Connect with xPortal App", SystemColors.ControlText);
}
}
catch (APIException)
{
LogMessage("Wallet reconnected. API error", Color.Gold);
}
catch (Exception)
catch (Exception ex)
{
LogMessage("Could not reconnect to wallet", Color.Firebrick);
LogMessage(ex.Message, Color.Red);
}
}

Expand All @@ -112,29 +106,33 @@ private void LogMessage(string message, Color? color = null)

private void OnSessionDeleteEvent(object? sender, SessionEvent e)
{
NetworkConfig = default!;
Account = default!;

btnDisconnect.Visible = false;
btnConnect.Visible = true;

LogMessage("Wallet disconnected", Color.Firebrick);
DisconnectSessionEvent("Wallet disconnected");
}

private void OnSessionExpireEvent(object? sender, SessionStruct e)
{
DisconnectSessionEvent("Session expired");
}

private void DisconnectSessionEvent(string message)
{
NetworkConfig = default!;
Account = default!;

btnDisconnect.Visible = false;
btnConnect.Visible = true;
this.Invoke(new Action(() =>
{
btnConnect.Visible = true;
btnDisconnect.Visible = false;

LogMessage("Session expired", Color.Firebrick);
LogMessage(message, Color.Firebrick);
}));
}

private async void BtnConnect_Click(object sender, EventArgs e)
{
LogMessage("Generating QR code...", Color.Blue);
loading.Visible = true;
btnConnect.Visible = false;

try
{
Expand All @@ -146,6 +144,7 @@ private async void BtnConnect_Click(object sender, EventArgs e)
var qrCode = new QRCode(qrCodeData);
qrCodeImg.BackgroundImage = qrCode.GetGraphic(4);
qrCodeImg.Visible = true;
loading.Visible = false;

LogMessage("Waiting for wallet connection...", Color.Blue);

Expand All @@ -163,7 +162,6 @@ private async void BtnConnect_Click(object sender, EventArgs e)
}

qrCodeImg.Visible = false;
btnConnect.Visible = false;
btnDisconnect.Visible = true;

NetworkConfig = await NetworkConfig.GetFromNetwork(Provider);
Expand All @@ -173,11 +171,10 @@ private async void BtnConnect_Click(object sender, EventArgs e)
}
catch (APIException)
{
LogMessage("Wallet connected. API error", Color.Gold);
LogMessage("API error", Color.Gold);
}
catch (Exception ex)
catch (Exception)
{
MessageBox.Show(ex.Message);
LogMessage("Wallet connection was not approved", Color.Gold);
}
}
Expand All @@ -195,8 +192,9 @@ private async Task Disconnect()
Account = default!;

qrCodeImg.Visible = false;
btnDisconnect.Visible = false;
btnConnect.Visible = true;
btnDisconnect.Visible = false;
lbSignature.Text = "";

LogMessage("Wallet disconnected", Color.Firebrick);
}
Expand Down
62 changes: 61 additions & 1 deletion examples/WinForms/MainForm.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down
8 changes: 4 additions & 4 deletions examples/WinForms/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/WinForms/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="remarkabletools" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\remarkabletools.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="loading" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\loading.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added examples/WinForms/Resources/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading