Skip to content

Commit d333c93

Browse files
feat: add EIP-5792 section (#388)
1 parent 71c8536 commit d333c93

File tree

6 files changed

+406
-0
lines changed

6 files changed

+406
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import globalContext from '../../..';
2+
3+
export function getCallsStatusComponent(parentContainer) {
4+
parentContainer.insertAdjacentHTML(
5+
'beforeend',
6+
`<div class="form-group">
7+
<label>Request ID</label>
8+
<input
9+
class="form-control"
10+
type="text"
11+
id="eip5792RequestIdInput"
12+
/>
13+
</div>
14+
15+
<button
16+
class="btn btn-primary btn-lg btn-block mb-3"
17+
id="eip5792GetCallsStatusButton"
18+
disabled
19+
>
20+
Get Calls Status
21+
</button>
22+
23+
<p class="info-text alert alert-success">
24+
<span class="wrap" id="eip5792GetCallsStatusResult">Status</span>
25+
</p>`,
26+
);
27+
28+
const requestIdInput = document.getElementById('eip5792RequestIdInput');
29+
30+
const getCallsStatusButton = document.getElementById(
31+
'eip5792GetCallsStatusButton',
32+
);
33+
34+
const resultOutput = document.getElementById('eip5792GetCallsStatusResult');
35+
36+
document.addEventListener('globalConnectionChange', function (e) {
37+
if (e.detail.connected) {
38+
getCallsStatusButton.disabled = false;
39+
}
40+
});
41+
42+
document.addEventListener('disableAndClear', function () {
43+
getCallsStatusButton.disabled = true;
44+
});
45+
46+
getCallsStatusButton.onclick = async () => {
47+
try {
48+
const result = await globalContext.provider.request({
49+
method: 'wallet_getCallsStatus',
50+
params: [requestIdInput.value],
51+
});
52+
53+
resultOutput.innerHTML = JSON.stringify(result, null, 2);
54+
} catch (error) {
55+
console.error(error);
56+
resultOutput.innerHTML = `Error: ${error.message}`;
57+
}
58+
};
59+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import globalContext from '../../..';
2+
3+
export function getCapabilitiesComponent(parentContainer) {
4+
parentContainer.insertAdjacentHTML(
5+
'beforeend',
6+
`<div class="form-group">
7+
<label>Account</label>
8+
<input
9+
class="form-control"
10+
type="text"
11+
id="eip5792AccountInput"
12+
/>
13+
</div>
14+
15+
<button
16+
class="btn btn-primary btn-lg btn-block mb-3"
17+
id="eip5792GetCapabilitiesButton"
18+
disabled
19+
>
20+
Get Capabilities
21+
</button>
22+
23+
<p class="info-text alert alert-success">
24+
<span class="wrap" id="eip5792GetCapabilitiesResult">Status</span>
25+
</p>`,
26+
);
27+
28+
const accountInput = document.getElementById('eip5792AccountInput');
29+
const getCapabilitiesButton = document.getElementById(
30+
'eip5792GetCapabilitiesButton',
31+
);
32+
const resultOutput = document.getElementById('eip5792GetCapabilitiesResult');
33+
34+
document.addEventListener('globalConnectionChange', function (e) {
35+
if (e.detail.connected) {
36+
accountInput.value = '';
37+
getCapabilitiesButton.disabled = false;
38+
accountInput.value = globalContext.accounts[0];
39+
}
40+
});
41+
42+
document.addEventListener('disableAndClear', function () {
43+
accountInput.value = '';
44+
getCapabilitiesButton.disabled = true;
45+
});
46+
47+
getCapabilitiesButton.onclick = async () => {
48+
try {
49+
const result = await globalContext.provider.request({
50+
method: 'wallet_getCapabilities',
51+
params: [accountInput.value],
52+
});
53+
54+
resultOutput.innerHTML = JSON.stringify(result, null, 2);
55+
} catch (error) {
56+
console.error(error);
57+
resultOutput.innerHTML = `Error: ${error.message}`;
58+
}
59+
};
60+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { getCallsStatusComponent } from './getCallsStatus';
2+
import { getCapabilitiesComponent } from './getCapabilities';
3+
import { sendCallsComponent } from './sendCalls';
4+
5+
export function eip5792Component(parentContainer) {
6+
parentContainer.insertAdjacentHTML(
7+
'beforeend',
8+
`<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12 d-flex align-items-stretch">
9+
<div class="card full-width">
10+
<div class="card-body eip5792">
11+
<h4 class="card-title">
12+
EIP 5792
13+
</h4>
14+
<div id="eip5792SendCalls"></div>
15+
<hr/>
16+
<div id="eip5792GetCallsStatus"></div>
17+
<hr/>
18+
<div id="eip5792GetCapabilities"></div>
19+
</div>
20+
</div>
21+
</div`,
22+
);
23+
24+
sendCallsComponent(document.getElementById('eip5792SendCalls'));
25+
getCallsStatusComponent(document.getElementById('eip5792GetCallsStatus'));
26+
getCapabilitiesComponent(document.getElementById('eip5792GetCapabilities'));
27+
}

0 commit comments

Comments
 (0)