这是indexloc提供的服务,不要输入任何密码
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using ChainSafe.Gaming.Evm.Signers;
using ChainSafe.Gaming.Web3.Analytics;
using ChainSafe.Gaming.Web3.Core;

namespace ChainSafe.Gaming.Exchangers.Ramp
Expand All @@ -9,20 +10,28 @@ public class RampExchangerUniversal : IRampExchanger, ILifecycleParticipant
{
private readonly IRampExchangerConfig config;
private readonly ISigner signer;

private readonly IAnalyticsClient analyticsClient;

public event Action<OnRampPurchaseData> OnRampPurchaseCreated;
public event Action<OffRampSaleData> OffRampSaleCreated;

private IRampExchanger platformImplementation;


public RampExchangerUniversal(IRampExchangerConfig config, ISigner signer)
public RampExchangerUniversal(IRampExchangerConfig config, ISigner signer, IAnalyticsClient analyticsClient)
{
this.signer = signer;
this.config = config;
this.analyticsClient = analyticsClient;
}

public ValueTask WillStartAsync()
{
analyticsClient.CaptureEvent(new AnalyticsEvent()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sneaked this one in, forgot we didn't have analytics in Ramp and Jay needed it 😢

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noice

{
EventName = "Ramp Initialized",
PackageName = "io.chiansafe.web3-unity.exchangers.ramp"
});
platformImplementation = RampExchangerFactory.CreateRampExchanger(config, signer);
platformImplementation.OnRampPurchaseCreated += InvokeOnRampPurchaseCreated;
platformImplementation.OffRampSaleCreated += InvokeOffRampSaleCreated;
Expand All @@ -47,9 +56,23 @@ public Task<RampTransactionData> BuyOrSellCrypto(RampBuyOrSellWidgetSettings set
=> platformImplementation.BuyOrSellCrypto(settings);

private void InvokeOnRampPurchaseCreated(OnRampPurchaseData obj)
=> OnRampPurchaseCreated?.Invoke(obj);
{
analyticsClient.CaptureEvent(new AnalyticsEvent()
{
EventName = "Ramp Purchased Happened",
PackageName = "io.chiansafe.web3-unity.exchangers.ramp"
});
OnRampPurchaseCreated?.Invoke(obj);
}

private void InvokeOffRampSaleCreated(OffRampSaleData obj)
=> OffRampSaleCreated?.Invoke(obj);
{
analyticsClient.CaptureEvent(new AnalyticsEvent()
{
EventName = "Ramp Sale Happened",
PackageName = "io.chiansafe.web3-unity.exchangers.ramp"
});
OffRampSaleCreated?.Invoke(obj);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// custom.jspre

Module.InjectExternalScripts = function() {
const scripts = [
"https://cdn.jsdelivr.net/npm/@web3auth/no-modal",
"https://cdn.jsdelivr.net/npm/@web3auth/wallet-services-plugin",
"https://cdn.jsdelivr.net/npm/@web3auth/openlogin-adapter",
"https://cdn.jsdelivr.net/npm/@web3auth/ethereum-provider"
];

scripts.forEach(src => {
const script = document.createElement('script');
script.src = src;
document.body.appendChild(script);
});
};

// Automatically call the function to inject the scripts
Module['onRuntimeInitialized'] = function() {
Module.InjectExternalScripts();
};

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

Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private void authorizeSession(string newSessionId)
sessionId = newSessionId;
// Debug.Log("sessionId during authorizeSession in else part =>" + sessionId);
}

if (!string.IsNullOrEmpty(sessionId))
{
var pubKey = KeyStoreManagerUtils.getPubKey(sessionId);
Expand All @@ -391,10 +391,12 @@ private void authorizeSession(string newSessionId)
shareMetadata.ephemPublicKey,
shareMetadata.iv
);


var encryptedShareBytes = AES256CBC.toByteArray(new BigInteger(shareMetadata.ciphertext, 16));
var share = aes256cbc.decrypt(encryptedShareBytes, shareMetadata.mac);
var tempJson = JsonConvert.DeserializeObject<JObject>(System.Text.Encoding.UTF8.GetString(share));


this.web3AuthResponse = JsonConvert.DeserializeObject<Web3AuthResponse>(tempJson.ToString());
if (this.web3AuthResponse != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
var Web3AuthWebGLNoModal = {
$Web3AuthWebGLNoModal : {},

SetLoginCallback: function (login) {
Web3AuthWebGLNoModal.loginCallback = function(sessionId){
var returnStr = sessionId;
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
Module.dynCall_vi(login, [buffer]);
};
},
InitWeb3Auth: function (clientId, chainId, rpcTarget, displayName, blockExplorerUrl, ticker, tickerName, network) {
window.web3auth = null;
window.walletServicesPlugin = null;



(async function init() {
try {

console.log("Initializing Web3Auth...");

const chainConfig = {
chainNamespace: "eip155",
chainId: UTF8ToString(chainId),
rpcTarget: UTF8ToString(rpcTarget),
displayName: UTF8ToString(displayName),
blockExplorerUrl: UTF8ToString(blockExplorerUrl),
ticker: UTF8ToString(ticker),
tickerName: UTF8ToString(tickerName),
};

const privateKeyProvider = new window.EthereumProvider.EthereumPrivateKeyProvider({ config: { chainConfig } });
window.web3auth = new window.NoModal.Web3AuthNoModal({
clientId: UTF8ToString(clientId),
privateKeyProvider,
web3AuthNetwork: UTF8ToString(network),
});

window.web3auth.on("connected", (data) => {
const openLoginStore = localStorage.getItem("openlogin_store");
const openLoginStoreObj = openLoginStore ? JSON.parse(openLoginStore) : null;
if (openLoginStoreObj && openLoginStoreObj.sessionId) {
const sessionId = openLoginStoreObj.sessionId;
Web3AuthWebGLNoModal.loginCallback(sessionId);
} else {
console.log("No session ID found in localStorage.");
}
});

const openloginAdapter = new window.OpenloginAdapter.OpenloginAdapter();
window.web3auth.configureAdapter(openloginAdapter);

await window.web3auth.init();
console.log("Web3Auth Initialized Successfully!");
} catch (error) {
console.error("Error during Web3Auth initialization:", error);
}
})();
},

Web3AuthLogin: async function (provider, rememberMe) {
try {
await window.web3auth.connectTo("openlogin", {
loginProvider: UTF8ToString(provider)
});
if (!rememberMe){
localStorage.removeItem("openlogin_store");
}
} catch (error) {
console.log(error.message);
}
},
};

autoAddDeps(Web3AuthWebGLNoModal, '$Web3AuthWebGLNoModal');
mergeInto(LibraryManager.library,Web3AuthWebGLNoModal);

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

Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ public async ValueTask WillStartAsync()
if (config.LoginParams != null) coreInstance.login(config.LoginParams);

var privateKeyString = await loginTcs.Task;

var privateKey = new EthECKey(privateKeyString);

var signerConfig = new InProcessSignerConfig { PrivateKey = privateKey };

signer = new InProcessSigner(signerConfig);


transactionExecutor = new InProcessTransactionExecutor(signer, analyticsClient.ChainConfig, rpcProvider, rpcClient);

transactionHandler.OnTransactionApproved += OnTransactionApproved;
Expand Down Expand Up @@ -190,7 +192,6 @@ private TWeb3Auth CreateCoreInstance()
Object.DontDestroyOnLoad(gameObject);

var instance = gameObject.GetComponent<TWeb3Auth>();
instance.Awake();
instance.setOptions(config.Web3AuthOptions, config.RememberMe);

return instance;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using ChainSafe.Gaming.Web3;
using ChainSafe.Gaming.Web3.Analytics;
using Plugins.CountlySDK;
using Plugins.CountlySDK.Models;
using UnityEngine;

public class CountlyAnalytics : IAnalyticsClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using ChainSafe.Gaming.Web3.Core.Unity;
using ChainSafe.Gaming.Web3.Environment;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace ChainSafe.Gaming.Web3.Unity
{
Expand Down
Loading