-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutilities.ts
55 lines (46 loc) · 1.35 KB
/
utilities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
declare const window: any;
const hasOwn = {}.hasOwnProperty;
export async function getWalletStatus() {
const isMetamaskEnabled =
typeof window.ethereum !== "undefined" && window.ethereum.isMetaMask;
const isPhantomEnabled =
typeof window.solana !== "undefined" && window.solana.isPhantom;
// NOTE(jim): This allows you to get the public key.
if (isPhantomEnabled && !window.solana.publicKey) {
try {
await window.solana.connect({ onlyIfTrusted: true });
} catch (e) {
console.log(e);
}
}
return { isMetamaskEnabled, isPhantomEnabled };
}
export function classNames(...args: any[]): string {
var classes = [];
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (!arg) continue;
var argType = typeof arg;
if (argType === "string" || argType === "number") {
classes.push(arg);
} else if (Array.isArray(arg)) {
if (arg.length) {
var inner = classNames.apply(null, arg);
if (inner) {
classes.push(inner);
}
}
} else if (argType === "object") {
if (arg.toString !== Object.prototype.toString) {
classes.push(arg.toString());
} else {
for (var key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
}
}
}
}
return classes.join(" ");
}