diff --git a/app.json b/app.json index 9233bcba..ebd13567 100644 --- a/app.json +++ b/app.json @@ -1,51 +1,54 @@ { - "name": "Cartridge Marketplace", - "slug": "cartridge-marketplace", - "version": "1.0.0", - "web": { - "favicon": "./assets/favicon.png" - }, - "experiments": { - "tsconfigPaths": true - }, - "plugins": [ - [ - "expo-font", - { - "fonts": [ - "node_modules/@expo-google-fonts/inter/400Regular/Inter_400Regular.ttf", - "node_modules/@expo-google-fonts/inter/500Medium/Inter_500Medium.ttf", - "node_modules/@expo-google-fonts/inter/600SemiBold/Inter_600SemiBold.ttf", - "node_modules/@expo-google-fonts/inter/700Bold/Inter_700Bold.ttf", - "node_modules/@expo-google-fonts/ibm-plex-mono/400Regular/IBMPlexMono_400Regular.ttf", - "node_modules/@expo-google-fonts/ibm-plex-mono/500Medium/IBMPlexMono_500Medium.ttf", - "node_modules/@expo-google-fonts/ibm-plex-mono/600SemiBold/IBMPlexMono_600SemiBold.ttf", - "node_modules/@expo-google-fonts/ibm-plex-mono/700Bold/IBMPlexMono_700Bold.ttf" - ] - } - ] - ], - "orientation": "portrait", - "icon": "./assets/icon.png", - "userInterfaceStyle": "light", - "splash": { - "image": "./assets/splash.png", - "resizeMode": "contain", - "backgroundColor": "#ffffff" - }, - "assetBundlePatterns": ["**/*"], - "ios": { - "supportsTablet": true, - "bundleIdentifier": "com.cartridge.marketplace", + "name": "Cartridge Marketplace", + "slug": "cartridge-marketplace", + "version": "1.0.0", + "web": { + "favicon": "./assets/favicon.png" + }, + "experiments": { + "tsconfigPaths": true + }, + "plugins": [ + [ + "expo-font", + { + "fonts": [ + "node_modules/@expo-google-fonts/inter/400Regular/Inter_400Regular.ttf", + "node_modules/@expo-google-fonts/inter/500Medium/Inter_500Medium.ttf", + "node_modules/@expo-google-fonts/inter/600SemiBold/Inter_600SemiBold.ttf", + "node_modules/@expo-google-fonts/inter/700Bold/Inter_700Bold.ttf", + "node_modules/@expo-google-fonts/ibm-plex-mono/400Regular/IBMPlexMono_400Regular.ttf", + "node_modules/@expo-google-fonts/ibm-plex-mono/500Medium/IBMPlexMono_500Medium.ttf", + "node_modules/@expo-google-fonts/ibm-plex-mono/600SemiBold/IBMPlexMono_600SemiBold.ttf", + "node_modules/@expo-google-fonts/ibm-plex-mono/700Bold/IBMPlexMono_700Bold.ttf" + ] + } + ], + "react-native-webassembly" + ], + "orientation": "portrait", + "icon": "./assets/icon.png", + "userInterfaceStyle": "light", + "splash": { + "image": "./assets/splash.png", + "resizeMode": "contain", + "backgroundColor": "#ffffff" + }, + "assetBundlePatterns": [ + "**/*" + ], + "ios": { + "supportsTablet": true, + "bundleIdentifier": "com.cartridge.marketplace", "associatedDomains": [ "webcredentials:x.cartridge.gg" ] - }, - "android": { - "adaptiveIcon": { - "foregroundImage": "./assets/adaptive-icon.png", - "backgroundColor": "#ffffff" - }, - "package": "com.cartridge.marketplace" - } + }, + "android": { + "adaptiveIcon": { + "foregroundImage": "./assets/adaptive-icon.png", + "backgroundColor": "#ffffff" + }, + "package": "com.cartridge.marketplace" + } } diff --git a/app/index.tsx b/app/index.tsx index 7935c90f..89c26d55 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -3,13 +3,16 @@ import { View } from "react-native"; import { Button, SonnerToaster, Text } from "#components"; export default function RootScreen() { - return ( - - Cartridge Marketplace - - - - ); + return ( + + Cartridge Marketplace + + + + + ); } diff --git a/app/wasm.tsx b/app/wasm.tsx new file mode 100644 index 00000000..7533b78a --- /dev/null +++ b/app/wasm.tsx @@ -0,0 +1,61 @@ +import { useEffect, useState } from "react"; +import { View } from "react-native"; +import * as WebAssembly from 'react-native-webassembly'; +import { Text } from "#components"; +import axios from "axios"; + +// Alternative approach: Bundle WASM locally +// 1. Download the WASM file and place it in your assets folder +// 2. Import it directly: +// import wasmFile from '../assets/account_wasm_bg.wasm'; + +export default function WasmScreen() { + // const [controller, setController] = useState | null>(null); + const [error, setError] = useState(null); + + useEffect(() => { + async function init() { + try { + // const bytes = await fetchWasm("https://unpkg.com/@cartridge/controller-wasm@0.2.4/pkg-controller/account_wasm_bg.wasm"); + const bytes = await fetchWasm("https://github.com/JunichiSugiura/controller-rs/raw/feat/no-modules/account-wasm/controller.wasm") + console.log(bytes) + const wasm = await WebAssembly.instantiate<{ + cartridgeaccount_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void; + }>(bytes); + const res = wasm.instance.exports.cartridgeaccount_new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13); + console.log(res) + } catch (err) { + console.error('Error fetching WASM:', err); + setError(err instanceof Error ? err.message : 'Unknown error'); + throw err; + } + }; + + init(); + }, []); + + // console.log(Object.keys(controller?.instance?.exports ?? {})) + + return ( + + {error && ( + + Error: {error} + + )} + + {/* {JSON.stringify(Object.keys(controller?.instance?.exports ?? {}))} */} + + + ); +} + +export async function fetchWasm(uri: string) { + const { data: bufferSource } = await axios({ + url: uri, + method: 'get', + responseType: 'arraybuffer', + }); + + return bufferSource; +} diff --git a/bun.lock b/bun.lock index 8df3ea91..76f64052 100644 --- a/bun.lock +++ b/bun.lock @@ -29,6 +29,7 @@ "@rn-primitives/slot": "^1.2.0", "@rn-primitives/tooltip": "^1.2.0", "@rn-primitives/utils": "^1.2.0", + "axios": "^1.11.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "expo": "^53.0.20", @@ -53,6 +54,7 @@ "react-native-svg": "15.11.2", "react-native-toast-message": "^2.3.0", "react-native-web": "^0.20.0", + "react-native-webassembly": "^0.3.3", "sonner": "^2.0.5", "sonner-native": "^0.21.0", "starknet": "^7.6.2", @@ -974,7 +976,7 @@ "bser": ["bser@2.1.1", "", { "dependencies": { "node-int64": "^0.4.0" } }, "sha512-gQxTNE/GAfIIrmHLUE3oJyp5FO6HRBfhjnw4/wMmA63ZGDJnWBmgY/lyQBpnDUkGmAhbSe39tx2d/iTOAfglwQ=="], - "buffer": ["buffer@5.7.1", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ=="], + "buffer": ["buffer@6.0.3", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" } }, "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA=="], "buffer-from": ["buffer-from@1.1.2", "", {}, "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="], @@ -1924,6 +1926,8 @@ "react-native-web": ["react-native-web@0.20.0", "", { "dependencies": { "@babel/runtime": "^7.18.6", "@react-native/normalize-colors": "^0.74.1", "fbjs": "^3.0.4", "inline-style-prefixer": "^7.0.1", "memoize-one": "^6.0.0", "nullthrows": "^1.1.1", "postcss-value-parser": "^4.2.0", "styleq": "^0.1.3" }, "peerDependencies": { "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" } }, "sha512-OOSgrw+aON6R3hRosCau/xVxdLzbjEcsLysYedka0ZON4ZZe6n9xgeN9ZkoejhARM36oTlUgHIQqxGutEJ9Wxg=="], + "react-native-webassembly": ["react-native-webassembly@0.3.3", "", { "dependencies": { "buffer": "^6.0.3", "nanoid": "3.3.4" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-wC8r/C6bHcWsNZmzES6vhMX1bao3JtG2FIVC9Un5kTn9EKQBN63qGVGMaD7ppe/vkzD8aPTfj9MKjsid4m7VRA=="], + "react-refresh": ["react-refresh@0.17.0", "", {}, "sha512-z6F7K9bV85EfseRCp2bzrpyQ0Gkw1uLoCel9XBVWPg/TjRj94SkJzUTGfOa4bs7iJvBWtQG0Wq7wnI0syw3EBQ=="], "react-remove-scroll": ["react-remove-scroll@2.7.1", "", { "dependencies": { "react-remove-scroll-bar": "^2.3.7", "react-style-singleton": "^2.2.3", "tslib": "^2.1.0", "use-callback-ref": "^1.3.3", "use-sidecar": "^1.1.3" }, "peerDependencies": { "@types/react": "*", "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-HpMh8+oahmIdOuS5aFKKY6Pyog+FNaZV/XyJOq7b4YFwsFHe5yYfdbIalI4k3vU2nSDql7YskmUseHsRrJqIPA=="], @@ -2578,6 +2582,8 @@ "react-native-web/memoize-one": ["memoize-one@6.0.0", "", {}, "sha512-rkpe71W0N0c0Xz6QD0eJETuWAJGnJ9afsl1srmwPrI+yBCkge5EycXXbYRyvL29zZVUWQCY7InPRCv3GDXuZNw=="], + "react-native-webassembly/nanoid": ["nanoid@3.3.4", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw=="], + "readdirp/picomatch": ["picomatch@2.3.1", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="], "recast/source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="], @@ -2638,6 +2644,8 @@ "whatwg-url/webidl-conversions": ["webidl-conversions@3.0.1", "", {}, "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="], + "whatwg-url-without-unicode/buffer": ["buffer@5.7.1", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ=="], + "wrap-ansi/strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="], "wrap-ansi-cjs/strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="], diff --git a/package.json b/package.json index 98493f53..9b9b7ed4 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "@rn-primitives/slot": "^1.2.0", "@rn-primitives/tooltip": "^1.2.0", "@rn-primitives/utils": "^1.2.0", + "axios": "^1.11.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "expo": "^53.0.20", @@ -75,6 +76,7 @@ "react-native-svg": "15.11.2", "react-native-toast-message": "^2.3.0", "react-native-web": "^0.20.0", + "react-native-webassembly": "^0.3.3", "sonner": "^2.0.5", "sonner-native": "^0.21.0", "starknet": "^7.6.2",