Skip to content

Commit

Permalink
Merge branch 'main' into chore/webgl-appkit-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
skibitsky committed Nov 20, 2024
2 parents 09f8209 + 073c3c3 commit e96f48b
Show file tree
Hide file tree
Showing 154 changed files with 5,664 additions and 581 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,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
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@

.snackbar__icon-container--color-success > .snackbar__icon {
--unity-image-tint-color: var(--ro-color-success-100);
}

.snackbar__icon-container--color-info {
background-color: var(--ro-accent-glass-005);
}

.snackbar__icon-container--color-info > .snackbar__icon {
--unity-image-tint-color: var(--ro-color-fg-100);
}

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

Loading

0 comments on commit e96f48b

Please sign in to comment.