-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathAddToMetaMask.tsx
More file actions
105 lines (100 loc) · 2.8 KB
/
AddToMetaMask.tsx
File metadata and controls
105 lines (100 loc) · 2.8 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React from 'react';
const AddToMetaMask = (props: {
name: string,
chainId: string,
token: string,
rpcs: string[],
hideRpcs: boolean,
be: string[],
}) => {
return (
<span>
{!props.hideRpcs && props.rpcs.map(item => (
<code key={item}>{item}<br/></code>
))}
<button
className={"button button--primary"+(props.hideRpcs ? "" : " margin-top--md")}
onClick={() => {
if (!window.ethereum?.request) {
return alert('Have you installed MetaMask yet? If not, please do so.\n\nComputer: Once it is installed, you will be able to add the ParaTime to your MetaMask.\n\nPhone: Open the website through your MetaMask Browser to add the ParaTime.')
}
const startTime = Date.now()
window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: props.chainId,
chainName: props.name,
nativeCurrency: {
name: props.token,
symbol: props.token,
decimals: 18,
},
rpcUrls: props.rpcs,
blockExplorerUrls: props.be,
},
],
}).then(response => {
// XXX: A workaround to figure out if the RPC already exists.
const isAutomatedResponse = Date.now() - startTime < 100
if (response === null && isAutomatedResponse) alert(`The ${props.name} RPC already added.`)
})
}}
>
Add to MetaMask
</button>
</span>
);
};
export const AddSapphireToMetaMask = (props: {
rpcs: string[],
hideRpcs: boolean,
}) => {
return AddToMetaMask({
name: 'Oasis Sapphire',
chainId: '0x5afe',
token: 'ROSE',
rpcs: props.rpcs,
hideRpcs: props.hideRpcs,
be: ['https://explorer.oasis.io/mainnet/sapphire'],
});
};
export const AddSapphireTestnetToMetaMask = (props: {
rpcs: string[],
hideRpcs: boolean,
}) => {
return AddToMetaMask({
name: 'Oasis Sapphire Testnet',
chainId: '0x5aff',
token: 'TEST',
rpcs: props.rpcs,
hideRpcs: props.hideRpcs,
be: ['https://explorer.oasis.io/testnet/sapphire'],
});
};
export const AddEmeraldToMetaMask = (props: {
rpcs: string[],
hideRpcs: boolean,
}) => {
return AddToMetaMask({
name: 'Oasis Emerald',
chainId: '0xa516',
token: 'ROSE',
rpcs: props.rpcs,
hideRpcs: props.hideRpcs,
be: ['https://explorer.oasis.io/mainnet/emerald'],
});
};
export const AddEmeraldTestnetToMetaMask = (props: {
rpcs: string[],
hideRpcs: boolean,
}) => {
return AddToMetaMask({
name: 'Oasis Emerald Testnet',
chainId: '0xa515',
token: 'TEST',
rpcs: props.rpcs,
hideRpcs: props.hideRpcs,
be: ['https://explorer.oasis.io/testnet/emerald'],
});
};