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

feat: 1-click auth #3

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 3 additions & 23 deletions .github/workflows/dotnet-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,12 @@ on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.x

- name: Restore dependencies
run: dotnet restore
working-directory: ./

- name: Build
run: dotnet build Reown.NoUnity.slnf --no-restore
working-directory: ./

test:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
test-type: [unit-tests, integration-tests]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
Expand All @@ -47,4 +27,4 @@ jobs:
uses: ./.github/actions/test-dotnet
with:
type: ${{ matrix.test-type }}
project-id: ${{ secrets.PROJECT_ID }}
project-id: ${{ secrets.PROJECT_ID }}
52 changes: 52 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: SonarCloud
on:
workflow_dispatch:
push:
branches:
- 2.0
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: windows-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Install dotnet-coverage
run: dotnet tool install --global dotnet-coverage
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"reown-com_reown-dotnet" /o:"reown-com" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet build --no-incremental
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
1 change: 1 addition & 0 deletions .github/workflows/unity-bulid-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
buildForAllSupportedPlatforms:
if: github.event.pull_request.draft == false
name: Build for ${{ matrix.targetPlatform }}
runs-on: ubuntu-latest
strategy:
Expand Down
1 change: 1 addition & 0 deletions Reown.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=caip/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=reown/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
125 changes: 109 additions & 16 deletions sample/Reown.AppKit.Unity/Assets/Scripts/AppKitInit.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using mixpanel;
using Reown.AppKit.Unity;
using Reown.AppKit.Unity.Model;
using Reown.Core.Common.Logging;
using Skibitsky.Unity;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityLogger = Reown.Sign.Unity.UnityLogger;

#if !UNITY_WEBGL
using mixpanel;
#endif

namespace Sample
{
Expand All @@ -12,30 +18,117 @@ public class AppKitInit : MonoBehaviour

private async void Start()
{
Debug.Log($"[AppKit Init] Initializing AppKit...");
// Set up Reown logger to collect logs from AppKit
ReownLogger.Instance = new UnityLogger();

// The very basic configuration of SIWE
var siweConfig = new SiweConfig
{
GetMessageParams = () => new SiweMessageParams
{
Domain = "example.com",
Uri = "https://example.com/login"
}
};

// Subscribe to SIWE events
siweConfig.SignInSuccess += _ => Debug.Log("[Dapp] SIWE Sign In Success!");
siweConfig.SignOutSuccess += () => Debug.Log("[Dapp] SIWE Sign Out Success!");

// AppKit configuration
var appKitConfig = new AppKitConfig
{
// Project ID from https://cloud.reown.com/
projectId = "884a108399b5e7c9bc00bd9be4ccb2cc",
metadata = new Metadata(
"AppKit Unity",
"AppKit Unity Sample",
"https://reown.com",
"https://raw.githubusercontent.com/reown-com/reown-dotnet/main/media/appkit-icon.png",
new RedirectData
{
// Used by native wallets to redirect back to the app after approving requests
Native = "appkit-sample-unity://"
}
),
customWallets = GetCustomWallets(),
// On mobile show 5 wallets on the Connect view (the first AppKit modal screen)
connectViewWalletsCountMobile = 5,
// Assign the SIWE configuration created above. Can be null if SIWE is not used.
siweConfig = siweConfig
};

Debug.Log("[AppKit Init] Initializing AppKit...");

await AppKit.InitializeAsync(
new AppKitConfig(
projectId: "884a108399b5e7c9bc00bd9be4ccb2cc",
new Metadata(
name: "AppKit Unity",
description: "AppKit Unity Sample",
url: "https://reown.com",
iconUrl: "https://raw.githubusercontent.com/reown-com/reown-dotnet/main/media/appkit-icon.png",
new RedirectData
{
Native = "appkit-sample-unity"
}
)
)
appKitConfig
);

#if !UNITY_WEBGL
// The Mixpanel is used by the sample project to collect telemetry
var clientId = await AppKit.Instance.SignClient.CoreClient.Crypto.GetClientId();
Mixpanel.Identify(clientId);
#endif

Debug.Log($"[AppKit Init] AppKit initialized. Loading menu scene...");
SceneManager.LoadScene(_menuScene);
}

/// <summary>
/// This method returns a list of Reown sample wallets on iOS and Android.
/// These wallets are used for testing and are not included in the default list of wallets returned by AppKit's REST API.
/// On other platforms, this method returns null, so only the default list of wallets is used.
/// </summary>
private Wallet[] GetCustomWallets()
{
#if UNITY_IOS && !UNITY_EDITOR
return new[]
{
new Wallet
{
Name = "Swift Wallet",
ImageUrl = "https://raw.githubusercontent.com/reown-com/reown-dotnet/refs/heads/main/media/walletkit-icon.png",
MobileLink = "walletapp://"
},
new Wallet
{
Name = "React Native Wallet",
ImageUrl = "https://raw.githubusercontent.com/reown-com/reown-dotnet/refs/heads/main/media/walletkit-icon.png",
MobileLink = "rn-web3wallet://"
},
new Wallet
{
Name = "Flutter Wallet Prod",
ImageUrl = "https://raw.githubusercontent.com/reown-com/reown-dotnet/refs/heads/main/media/walletkit-icon.png",
MobileLink = "wcflutterwallet://"
}
};
#endif

#if UNITY_ANDROID && !UNITY_EDITOR
return new[]
{
new Wallet
{
Name = "Kotlin Wallet",
ImageUrl = "https://raw.githubusercontent.com/reown-com/reown-dotnet/refs/heads/main/media/walletkit-icon.png",
MobileLink = "kotlin-web3wallet://"
},
new Wallet
{
Name = "React Native Wallet",
ImageUrl = "https://raw.githubusercontent.com/reown-com/reown-dotnet/refs/heads/main/media/walletkit-icon.png",
MobileLink = "rn-web3wallet://"
},
new Wallet
{
Name = "Flutter Wallet Prod",
ImageUrl = "https://raw.githubusercontent.com/reown-com/reown-dotnet/refs/heads/main/media/walletkit-icon.png",
MobileLink = "wcflutterwallet://"
}
};
#endif
return null;
}
}
}
16 changes: 11 additions & 5 deletions sample/Reown.AppKit.Unity/Assets/Scripts/Dapp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Nethereum.JsonRpc.Client;
using Nethereum.Web3;
using Reown.AppKit.Unity;
using Reown.Core;
using UnityEngine;
using UnityEngine.UIElements;
using ButtonUtk = UnityEngine.UIElements.Button;
Expand Down Expand Up @@ -145,19 +146,20 @@ private async void Start()
{
RefreshButtons();

if (e.Chain == null)
if (e.NewChain == null)
{
Notification.ShowMessage("Unsupported chain");
return;
}
};

AppKit.AccountConnected += async (_, e) => { RefreshButtons(); };
AppKit.AccountConnected += async (_, e) => RefreshButtons();

AppKit.AccountDisconnected += (_, _) => { RefreshButtons(); };
AppKit.AccountDisconnected += (_, _) => RefreshButtons();

AppKit.AccountChanged += (_, e) => { RefreshButtons(); };
AppKit.AccountChanged += (_, e) => RefreshButtons();

// After the scene and UI are loaded, try to resume the session from the storage
var sessionResumed = await AppKit.ConnectorController.TryResumeSessionAsync();
Debug.Log($"Session resumed: {sessionResumed}");
}
Expand Down Expand Up @@ -302,7 +304,11 @@ public async void OnSignTypedDataV4Button()
Contents = "Hello, Bob!"
};

typedData.Domain.ChainId = BigInteger.Parse(account.ChainId.Split(":")[1]);
// Convert CAIP-2 chain reference to EIP-155 chain ID
// This is equivalent to `account.ChainId.Split(":")[1]`, but allocates less memory
var ethChainId = Utils.ExtractChainReference(account.ChainId);

typedData.Domain.ChainId = BigInteger.Parse(ethChainId);
typedData.SetMessage(mail);

var jsonMessage = typedData.ToJson();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Reown.AppKit.Unity;
using Sample.UI;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
using Sample.UI;
using Button = UnityEngine.UIElements.Button;

namespace Sample
Expand Down
5 changes: 3 additions & 2 deletions sample/Reown.AppKit.Unity/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
"com.reown.sign.unity": "file:./../../../src/Reown.Sign.Unity",
"com.reown.unity.dependencies": "file:./../../../src/Reown.Unity.Dependencies",
"com.skibitsky.scene-reference": "1.1.1",
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.rider": "3.0.34",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.mobile.android-logcat": "1.4.3",
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.render-pipelines.universal": "14.0.11",
"com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.9",
"com.unity.ugui": "1.0.0",
"com.yasirkula.ingamedebugconsole": "1.6.8",
"io.sentry.unity": "2.2.1",
"io.sentry.unity": "2.3.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down
11 changes: 9 additions & 2 deletions sample/Reown.AppKit.Unity/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "3.0.31",
"version": "3.0.34",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -177,6 +177,13 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.mobile.android-logcat": {
"version": "1.4.3",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.nuget.newtonsoft-json": {
"version": "3.2.1",
"depth": 0,
Expand Down Expand Up @@ -287,7 +294,7 @@
"url": "https://package.openupm.com"
},
"io.sentry.unity": {
"version": "2.2.1",
"version": "2.3.0",
"depth": 0,
"source": "registry",
"dependencies": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ PlayerSettings:
buildNumber:
Standalone: 0
VisionOS: 0
iPhone: 0
iPhone: 2
tvOS: 0
overrideDefaultApplicationIdentifier: 1
AndroidBundleVersionCode: 1
AndroidBundleVersionCode: 2
AndroidMinSdkVersion: 23
AndroidTargetSdkVersion: 0
AndroidPreferredInstallLocation: 1
Expand Down
Loading
Loading