Skip to content

Commit

Permalink
feat: oxychatwallet
Browse files Browse the repository at this point in the history
  • Loading branch information
rigbyciao authored and rightjelkin committed Jun 15, 2023
1 parent 724d780 commit 093b611
Show file tree
Hide file tree
Showing 11 changed files with 571 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react-scripts": "5.0.1",
"styled-components": "^5.3.5",
"typescript": "^4.4.2",
"venom-connect": "^1.0.17"
"venom-connect": "1.0.21"
},
"scripts": {
"start": "react-scripts start",
Expand Down
47 changes: 46 additions & 1 deletion examples/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Container,
Divider,
Grid,
Typography,
Typography
} from "@mui/material";

const initTheme = "light" as const;
Expand Down Expand Up @@ -109,6 +109,33 @@ const initVenomConnect = async () => {
"android",
],
},
oxychatwallet: {
walletWaysToConnect: [
{
// NPM package
package: ProviderRpcClient,
packageOptions: {
fallback:
VenomConnect.getPromise("oxychatwallet", "extension") ||
(() => Promise.reject()),
forceUseFallback: true,
},
packageOptionsStandalone: {
fallback: standaloneFallback,
forceUseFallback: true,
},

// Setup
id: "extension",
type: "extension",
},
],
defaultWalletWaysToConnect: [
// List of enabled options
"ios",
"android",
],
},
//
// Temporarily hidden Ever wallet
//
Expand Down Expand Up @@ -283,6 +310,24 @@ const App = () => {
<Grid item>
<Typography variant="h1" component="h1" textAlign="center">
Example
{/* (v1.0.14) */}
<br />
<small>(OXY.CHAT version)</small>
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<i
style={{
fontSize: "0.3em",
}}
>
[Deployment: Nov 28 2022]
</i>
</div>
</Typography>
</Grid>
</Grid>
Expand Down
14 changes: 13 additions & 1 deletion src/VenomConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ class VenomConnect {
} else if (this.checkIsWalletBrowser().isEverWalletBrowser) {
await this.connectTo("everwallet", "extension");

// проверяем что мобильный oxychat
} else if (this.checkIsWalletBrowser().isOxyWalletBrowser) {
await this.connectTo("oxychatwallet", "extension");

// показываем обычный попап
} else {
await this._toggleModal();
Expand Down Expand Up @@ -398,6 +402,7 @@ class VenomConnect {

private checkIsWalletBrowser = () => {
const ids = this.options.map(({ id }) => id);

const isVenomWalletBrowser = !!(
navigator &&
navigator.userAgent.includes("VenomWalletBrowser") &&
Expand All @@ -408,10 +413,17 @@ class VenomConnect {
navigator.userAgent.includes("EverWalletBrowser") &&
ids.includes("everwallet")
);
const isOxyWalletBrowser = !!(
navigator &&
navigator.userAgent.includes("OxyWalletBrowser") &&
ids.includes("oxychatwallet")
);
return {
isVenomWalletBrowser,
isEverWalletBrowser,
isOneOfWalletBrowsers: isVenomWalletBrowser || isEverWalletBrowser,
isOxyWalletBrowser,
isOneOfWalletBrowsers:
isVenomWalletBrowser || isEverWalletBrowser || isOxyWalletBrowser,
};
};

Expand Down
4 changes: 3 additions & 1 deletion src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ declare global {
__hasVenomProvider?: boolean;
__venom?: any;

// oxychat wallet
__oxy?: any;

// lib
updateVenomModal: any;
venomNetworkIntervalId?: number;
Expand Down Expand Up @@ -151,7 +154,6 @@ export const Modal = ({
ret = [...ret, ...o.walletWaysToConnect];
});
return ret;
// return options.find(({ id }) => id === _walletId)?.walletWaysToConnect;
};

// const getInitialSlide = () =>
Expand Down
2 changes: 1 addition & 1 deletion src/components/NotSupported.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type BrowserTextProps = {
browserName: Browsers | string;
};
const BrowserText = ({ browserName }: BrowserTextProps) => (
<>You need to install {browserName} browser</>
browserName ? <>You need to install {browserName} browser</> : <></>
);

type ProviderBadgeProps = {
Expand Down
37 changes: 37 additions & 0 deletions src/controllers/ProviderController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ export const getPromiseRaw = (
return Promise.reject();
},
},
oxychatwallet: {
// todo
extension: () => {
if (windowObject) {
return new Promise((resolve, reject) => {
if (windowObject.__oxy) {
resolve(windowObject.__oxy);
return;
}
let nTries = 0; // число попыток, иначе он будет бесконечно, может это вынести в конфиг
let interval = setInterval(() => {
if (windowObject.__oxy) {
clearInterval(interval);
resolve(windowObject.__oxy);
} else if (nTries > 0) {
nTries--;
} else {
clearInterval(interval);
reject("Ever wallet is not found");
}
}, 100);
});
}
return Promise.reject();
},
},
};

// @ts-ignore
Expand Down Expand Up @@ -159,6 +185,17 @@ export class ProviderController {
standalone: {}, // ?
}
: {},
oxychatwallet: window
? {
extension: {
forceUseFallback: true,
fallback:
getPromiseRaw(window, "oxychatwallet") ||
(() => Promise.reject("oxychatwallet fallback error")),
},
standalone: {}, // ?
}
: {},
};

this.checkNetworkId = options.checkNetworkId;
Expand Down
3 changes: 2 additions & 1 deletion src/providers/connectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import everwallet from "./everwallet";
import oxychatwallet from "./oxychatwallet";
import venomwallet from "./venomwallet";

export { venomwallet, everwallet };
export { everwallet, oxychatwallet, venomwallet };
Loading

0 comments on commit 093b611

Please sign in to comment.