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

🐛 Several fixes #17

Closed
wants to merge 6 commits into from
Closed
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 app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default {
"onesignal-expo-plugin",
{
mode: "development",
smallIcons: ["./assets/notifications-default.png"],
largeIcons: ["./assets/notifications-default-large.png"],
smallIcons: ["./assets/notifications_default.png"],
largeIcons: ["./assets/notifications_default_large.png"],
} as OneSignalPluginProps,
],
],
Expand Down
File renamed without changes
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"test:forge": "forge test",
"test:solhint": "solhint '{src,script,test}/**/*.sol'",
"test:slither": "slither .",
"prepare": "git submodule update --init --recursive"
"prepare": "git submodule update --init --recursive || true"
},
"devDependencies": {
"concurrently": "^8.2.2",
Expand Down
2 changes: 1 addition & 1 deletion metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
...(Array.isArray(defaultConfig.resolver?.blockList)
? defaultConfig.resolver.blockList
: [defaultConfig.resolver?.blockList]),
/\/contracts\/lib\//,
/\/contracts\/lib\/light-account\//,
],
},
};
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@onesignal/node-onesignal": "^2.0.1-beta2",
"@react-native-async-storage/async-storage": "1.18.2",
"@sentry/react-native": "^5.15.0",
"@tamagui/config": "^1.79.7",
"@tamagui/config": "^1.82.3",
"@tanstack/react-query": "5.8.4",
"@turnkey/api-key-stamper": "^0.3.0",
"@turnkey/http": "^2.5.0",
Expand All @@ -48,6 +48,7 @@
"expo-linking": "~5.0.2",
"expo-router": "^2.0.0",
"expo-splash-screen": "~0.20.5",
"expo-sqlite": "~11.3.3",
"expo-status-bar": "~1.6.0",
"expo-system-ui": "~2.4.0",
"expo-web-browser": "~12.3.2",
Expand All @@ -64,7 +65,7 @@
"react-native-web": "^0.19.9",
"react-onesignal": "^3.0.1",
"sentry-expo": "^7.1.1",
"tamagui": "^1.79.7",
"tamagui": "^1.82.3",
"text-encoding": "^0.7.0",
"ua-parser-js": "^1.0.37",
"viem": "2.0.0-beta.15",
Expand All @@ -74,7 +75,7 @@
"devDependencies": {
"@babel/core": "^7.23.5",
"@babel/plugin-transform-private-methods": "^7.23.3",
"@tamagui/babel-plugin": "^1.79.7",
"@tamagui/babel-plugin": "^1.82.3",
"@types/babel__core": "^7.20.5",
"@types/eslint": "^8.44.8",
"@types/react": "^18.2.42",
Expand All @@ -84,7 +85,7 @@
"@typescript-eslint/parser": "^6.13.2",
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
"concurrently": "^8.2.2",
"eas-cli": "^5.9.1",
"eas-cli": "^5.9.3",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-universe": "^12.0.0",
Expand All @@ -104,9 +105,7 @@
"typescript": "^5.3.3"
},
"overrides": {
"tslib": "^2.6.2",
"ts-node": "10.9.2",
"typescript": "5.3.3"
"tslib": "^2.6.2"
},
"trustedDependencies": [
"@sentry/cli",
Expand Down
47 changes: 47 additions & 0 deletions utils/onesignal.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useState, useEffect, useRef } from "react";
import { OneSignal as RNOneSignal } from "react-native-onesignal";

import { oneSignalAPPId } from "./constants";

type OneSignalProperties = {
userId?: string;
};

type Instance = typeof RNOneSignal;

export default function useOneSignal({ userId }: OneSignalProperties) {
const instance = useRef<Instance | null>(null);
const [initialized, setInitialized] = useState(false);

useEffect(() => {
const load = function () {
if (!oneSignalAPPId) {
setInitialized(true);
return;
}

if (!initialized) {
RNOneSignal.initialize(oneSignalAPPId);
instance.current = RNOneSignal;

setInitialized(true);
}

if (instance.current && userId) {
instance.current.login(userId);
}
};

load();

return () => {
if (!userId || !instance.current) {
return;
}

instance.current.logout();
};
}, [userId, initialized]);

return initialized;
}
84 changes: 12 additions & 72 deletions utils/onesignal.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,18 @@
import { useState, useEffect, useRef } from "react";
import { Platform } from "react-native";
import { OneSignal as RNOneSignal } from "react-native-onesignal";
import ROneSignal from "react-onesignal";

import { oneSignalAPPId } from "./constants";

type OneSignalProperties = {
userId?: string;
};

type Instance =
| {
type: "native";
value: typeof RNOneSignal;
}
| {
type: "web";
value: typeof ROneSignal;
};

export default function useOneSignal({ userId }: OneSignalProperties) {
const instance = useRef<Instance | null>(null);
const [initialized, setInitialized] = useState(false);

useEffect(() => {
const load = async function () {
if (!oneSignalAPPId) {
setInitialized(true);
return;
}

if (!initialized) {
switch (Platform.OS) {
case "web": {
await ROneSignal.init({
appId: oneSignalAPPId,
allowLocalhostAsSecureOrigin: true,
});
instance.current = { type: "web", value: ROneSignal };
break;
}
case "ios":
case "android": {
RNOneSignal.initialize(oneSignalAPPId);
instance.current = { type: "native", value: RNOneSignal };
break;
}
}

setInitialized(true);
}

if (instance.current && userId) {
await instance.current.value.login(userId);
}
};

load().catch(() => {
setInitialized(true);
});

return () => {
if (!userId || !instance.current) {
return;
}

const logout = instance.current.value.logout();
if (logout instanceof Promise) {
logout.catch(() => {
// ignore
});
}
};
}, [userId, initialized]);

return initialized;
}
type OneSignal = (parameters: OneSignalProperties) => boolean;

export default Platform.select<OneSignal>({
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
web: require("./onesignal.web") as OneSignal,
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
android: require("./onesignal.native") as OneSignal,
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
ios: require("./onesignal.native") as OneSignal,
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
default: require("./onesignal.native") as OneSignal,
});
54 changes: 54 additions & 0 deletions utils/onesignal.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useState, useEffect, useRef } from "react";
import OneSignal from "react-onesignal";

import { oneSignalAPPId } from "./constants";

type OneSignalProperties = {
userId?: string;
};

type Instance = typeof OneSignal;

export default function useOneSignal({ userId }: OneSignalProperties) {
const instance = useRef<Instance | null>(null);
const [initialized, setInitialized] = useState(false);

useEffect(() => {
const load = async function () {
if (!oneSignalAPPId) {
setInitialized(true);
return;
}

if (!initialized) {
await OneSignal.init({
appId: oneSignalAPPId,
allowLocalhostAsSecureOrigin: true,
});
instance.current = OneSignal;

setInitialized(true);
}

if (instance.current && userId) {
await instance.current.login(userId);
}
};

load().catch(() => {
setInitialized(true);
});

return () => {
if (!userId || !instance.current) {
return;
}

instance.current.logout().catch(() => {
// ignore
});
};
}, [userId, initialized]);

return initialized;
}