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

chore: upgrade appkit cdn to v1.2.1 #15

Open
wants to merge 10 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
4 changes: 2 additions & 2 deletions .github/workflows/unity-bulid-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
unityVersion: 2022.3.42f1
unityVersion: ${{ matrix.targetPlatform == 'WebGL' && '6000.0.25f1' || '2022.3.42f1' }}
buildsPath: Builds
projectPath: ${{ matrix.projectPath }}
targetPlatform: ${{ matrix.targetPlatform }}
Expand Down Expand Up @@ -72,4 +72,4 @@ jobs:
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
github-token: ${{ secrets.GITHUB_TOKEN }}
github-comment: true
working-directory: Builds/WebGL
working-directory: Builds/WebGL/WebGL
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,18 @@ PlayerSettings:
webGLLinkerTarget: 1
webGLThreadsSupport: 0
webGLDecompressionFallback: 0
webGLInitialMemorySize: 32
webGLInitialMemorySize: 1024
webGLMaximumMemorySize: 2048
webGLMemoryGrowthMode: 2
webGLMemoryLinearGrowthStep: 16
webGLMemoryGeometricGrowthStep: 0.2
webGLMemoryGeometricGrowthCap: 96
webGLEnableWebGPU: 0
webGLPowerPreference: 2
webGLWebAssemblyTable: 0
webGLWebAssemblyBigInt: 0
webGLCloseOnQuit: 0
webWasm2023: 0
scriptingDefineSymbols: {}
additionalCompilerArguments: {}
platformArchitecture: {}
Expand All @@ -785,6 +790,7 @@ PlayerSettings:
Standalone: 0
il2cppCompilerConfiguration: {}
il2cppCodeGeneration: {}
il2cppStacktraceInformation: {}
managedStrippingLevel:
EmbeddedLinux: 1
GameCoreScarlett: 1
Expand Down
74 changes: 27 additions & 47 deletions src/Reown.AppKit.Unity/Plugins/AppKit.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -65,66 +65,45 @@ mergeInto(LibraryManager.library, {
const projectId = parameters.projectId;
const metadata = parameters.metadata;
const chains = parameters.chains;
const includeWalletIds = parameters.includeWalletIds;
const excludeWalletIds = parameters.excludeWalletIds;

const enableOnramp = parameters.enableOnramp;
const enableAnalytics = parameters.enableAnalytics;
const enableCoinbaseWallet = parameters.enableCoinbaseWallet;

// Load the scripts and initialize the configuration
import("https://cdn.jsdelivr.net/npm/@web3modal/[email protected]/dist/wagmi.js").then(CDNW3M => {
const WagmiCore = CDNW3M['WagmiCore'];
const Chains = CDNW3M['Chains'];
const Web3modal = CDNW3M['Web3modal'];
const Connectors = CDNW3M['Connectors'];

const createWeb3Modal = Web3modal['createWeb3Modal'];
const coinbaseWallet = Connectors['coinbaseWallet'];
const walletConnect = Connectors['walletConnect'];
const injected = Connectors['injected'];
const createConfig = WagmiCore['createConfig'];
const http = WagmiCore['http'];
import("https://cdn.jsdelivr.net/npm/@reown/[email protected]/dist/appkit.js").then(AppKit => {
const WagmiCore = AppKit['WagmiCore'];
const WagmiAdapter = AppKit['WagmiAdapter'];
const Chains = AppKit['networks'];
const reconnect = WagmiCore['reconnect'];
const createAppKit = AppKit['createAppKit'];

const chainsMap = chains.map(chainName => Chains[chainName]);

const config = createConfig({
chains: chainsMap,
transports: chains.reduce((acc, chainName) => {
acc[Chains[chainName].id] = http();
return acc;
}, {}),
connectors: [
walletConnect({projectId, metadata, showQrModal: false}),
injected({shimDisconnect: true}),
...(enableCoinbaseWallet ? [coinbaseWallet({
appName: metadata.name,
appLogoUrl: metadata.icons[0]
})] : [])
]
});
const chainsArr = chains.map(chainName => Chains[chainName]);

reconnect(config);
const wagmiAdapter = new WagmiAdapter({
networks: chainsArr,
projectId
})

const modal = createWeb3Modal({
wagmiConfig: config,
const modal = createAppKit({
adapters: [wagmiAdapter],
networks: chainsArr,
metadata: metadata,
projectId,
enableOnramp: enableOnramp,
enableAnalytics: enableAnalytics,
disableAppend: true,
includeWalletIds: includeWalletIds,
excludeWalletIds: excludeWalletIds
});

features: {
analytics: enableAnalytics,
onramp: enableOnramp
}
})

reconnect(wagmiAdapter.wagmiConfig);

// Store the configuration and modal globally
_appKitConfig = {
config: config,
config: wagmiAdapter.wagmiConfig,
modal: modal,
wagmiCore: WagmiCore
};


// Insert the container into the DOM at the canvas's original position
const canvas = document.getElementsByTagName('canvas')[0];
const container = document.createElement('div');
Expand Down Expand Up @@ -220,9 +199,10 @@ mergeInto(LibraryManager.library, {
ModalSubscribeState__deps: ['$SerializeJson'],
ModalSubscribeState: function (callbackPtr) {
_appKitConfig.modal.subscribeState(newState => {
const newStateStr = stringToNewUTF8(SerializeJson(newState));
{{{makeDynCall('vi', 'callbackPtr')}}}(newStateStr);
_free(newStateStr);
const json = SerializeJson(newState);
const dataStr = stringToNewUTF8(json);
{{{makeDynCall('vi', 'callbackPtr')}}}(dataStr);
_free(dataStr);
});
},
});
3 changes: 2 additions & 1 deletion src/Reown.AppKit.Unity/Runtime/WebGL/Modal/ModalModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Reown.AppKit.Unity.WebGl.Modal
public class ModalState
{
public bool open;
public int selectedNetworkId;
public string selectedNetworkId;
public bool loading;
}

[Serializable]
Expand Down
Loading