@hyperlane-xyz/widgets 1.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +195 -0
- package/README.md +21 -0
- package/dist/color.d.ts +9 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +13 -0
- package/dist/color.js.map +1 -0
- package/dist/consts.d.ts +2 -0
- package/dist/consts.d.ts.map +1 -0
- package/dist/consts.js +5 -0
- package/dist/consts.js.map +1 -0
- package/dist/icons/Airplane.d.ts +11 -0
- package/dist/icons/Airplane.d.ts.map +1 -0
- package/dist/icons/Airplane.js +35 -0
- package/dist/icons/Airplane.js.map +1 -0
- package/dist/icons/ChainLogo.d.ts +15 -0
- package/dist/icons/ChainLogo.d.ts.map +1 -0
- package/dist/icons/ChainLogo.js +95 -0
- package/dist/icons/ChainLogo.js.map +1 -0
- package/dist/icons/Envelope.d.ts +11 -0
- package/dist/icons/Envelope.d.ts.map +1 -0
- package/dist/icons/Envelope.js +36 -0
- package/dist/icons/Envelope.js.map +1 -0
- package/dist/icons/Lock.d.ts +11 -0
- package/dist/icons/Lock.d.ts.map +1 -0
- package/dist/icons/Lock.js +34 -0
- package/dist/icons/Lock.js.map +1 -0
- package/dist/icons/QuestionMark.d.ts +11 -0
- package/dist/icons/QuestionMark.d.ts.map +1 -0
- package/dist/icons/QuestionMark.js +34 -0
- package/dist/icons/QuestionMark.js.map +1 -0
- package/dist/icons/Shield.d.ts +11 -0
- package/dist/icons/Shield.d.ts.map +1 -0
- package/dist/icons/Shield.js +35 -0
- package/dist/icons/Shield.js.map +1 -0
- package/dist/icons/WideChevron.d.ts +13 -0
- package/dist/icons/WideChevron.d.ts.map +1 -0
- package/dist/icons/WideChevron.js +57 -0
- package/dist/icons/WideChevron.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/MessageTimeline.d.ts +11 -0
- package/dist/messages/MessageTimeline.d.ts.map +1 -0
- package/dist/messages/MessageTimeline.js +111 -0
- package/dist/messages/MessageTimeline.js.map +1 -0
- package/dist/messages/types.d.ts +58 -0
- package/dist/messages/types.d.ts.map +1 -0
- package/dist/messages/types.js +20 -0
- package/dist/messages/types.js.map +1 -0
- package/dist/messages/useMessage.d.ts +14 -0
- package/dist/messages/useMessage.d.ts.map +1 -0
- package/dist/messages/useMessage.js +73 -0
- package/dist/messages/useMessage.js.map +1 -0
- package/dist/messages/useMessageStage.d.ts +13 -0
- package/dist/messages/useMessageStage.d.ts.map +1 -0
- package/dist/messages/useMessageStage.js +149 -0
- package/dist/messages/useMessageStage.js.map +1 -0
- package/dist/messages/useMessageTimeline.d.ts +15 -0
- package/dist/messages/useMessageTimeline.d.ts.map +1 -0
- package/dist/messages/useMessageTimeline.js +18 -0
- package/dist/messages/useMessageTimeline.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/utils/explorers.d.ts +19 -0
- package/dist/utils/explorers.d.ts.map +1 -0
- package/dist/utils/explorers.js +81 -0
- package/dist/utils/explorers.js.map +1 -0
- package/dist/utils/timeout.d.ts +2 -0
- package/dist/utils/timeout.d.ts.map +1 -0
- package/dist/utils/timeout.js +23 -0
- package/dist/utils/timeout.js.map +1 -0
- package/dist/utils/useInterval.d.ts +2 -0
- package/dist/utils/useInterval.d.ts.map +1 -0
- package/dist/utils/useInterval.js +26 -0
- package/dist/utils/useInterval.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useMessageStage = void 0;
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const sdk_1 = require("@hyperlane-xyz/sdk");
|
|
15
|
+
const explorers_1 = require("../utils/explorers");
|
|
16
|
+
const timeout_1 = require("../utils/timeout");
|
|
17
|
+
const useInterval_1 = require("../utils/useInterval");
|
|
18
|
+
const types_1 = require("./types");
|
|
19
|
+
const VALIDATION_TIME_EST = 5;
|
|
20
|
+
function useMessageStage({ message, retryInterval = 2000 }) {
|
|
21
|
+
// Tempting to use react-query here as we did in Explorer but
|
|
22
|
+
// avoiding for now to keep dependencies for this lib minimal
|
|
23
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
24
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
25
|
+
const [data, setData] = (0, react_1.useState)(null);
|
|
26
|
+
const fetcher = (0, react_1.useCallback)(() => {
|
|
27
|
+
if (!message)
|
|
28
|
+
return;
|
|
29
|
+
setIsLoading(true);
|
|
30
|
+
fetchMessageState(message)
|
|
31
|
+
.then((result) => {
|
|
32
|
+
setData(result);
|
|
33
|
+
setError(null);
|
|
34
|
+
})
|
|
35
|
+
.catch((e) => setError(e.toString()))
|
|
36
|
+
.finally(() => setIsLoading(false));
|
|
37
|
+
}, [message]);
|
|
38
|
+
(0, useInterval_1.useInterval)(fetcher, retryInterval);
|
|
39
|
+
return {
|
|
40
|
+
stage: (data === null || data === void 0 ? void 0 : data.stage) || message ? types_1.MessageStage.Sent : types_1.MessageStage.Preparing,
|
|
41
|
+
timings: (data === null || data === void 0 ? void 0 : data.timings) || {},
|
|
42
|
+
isLoading,
|
|
43
|
+
error,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.useMessageStage = useMessageStage;
|
|
47
|
+
function fetchMessageState(message) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { status, nonce, originDomainId: originChainId, // TODO avoid assuming domain === chain
|
|
50
|
+
destinationDomainId: destChainId, originTransaction, destinationTransaction, } = message;
|
|
51
|
+
const { blockNumber: originBlockNumber, timestamp: originTimestamp } = originTransaction;
|
|
52
|
+
const destTimestamp = destinationTransaction === null || destinationTransaction === void 0 ? void 0 : destinationTransaction.timestamp;
|
|
53
|
+
const relayEstimate = Math.floor(getBlockTimeEst(destChainId) * 1.5);
|
|
54
|
+
const finalityBlocks = getFinalityBlocks(originChainId);
|
|
55
|
+
const finalityEstimate = finalityBlocks * getBlockTimeEst(originChainId);
|
|
56
|
+
if (status === types_1.MessageStatus.Delivered && destTimestamp) {
|
|
57
|
+
// For delivered messages, just to rough estimates for stages
|
|
58
|
+
// This saves us from making extra explorer calls. May want to revisit in future
|
|
59
|
+
const totalDuration = Math.round((destTimestamp - originTimestamp) / 1000);
|
|
60
|
+
const finalityDuration = Math.max(Math.min(finalityEstimate, totalDuration - VALIDATION_TIME_EST), 1);
|
|
61
|
+
const remaining = totalDuration - finalityDuration;
|
|
62
|
+
const validateDuration = Math.max(Math.min(Math.round(remaining * 0.25), VALIDATION_TIME_EST), 1);
|
|
63
|
+
const relayDuration = Math.max(remaining - validateDuration, 1);
|
|
64
|
+
return {
|
|
65
|
+
stage: types_1.MessageStage.Relayed,
|
|
66
|
+
timings: {
|
|
67
|
+
[types_1.MessageStage.Finalized]: finalityDuration,
|
|
68
|
+
[types_1.MessageStage.Validated]: validateDuration,
|
|
69
|
+
[types_1.MessageStage.Relayed]: relayDuration,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const latestNonce = yield tryFetchLatestNonce(originChainId);
|
|
74
|
+
if (latestNonce && latestNonce >= nonce) {
|
|
75
|
+
return {
|
|
76
|
+
stage: types_1.MessageStage.Validated,
|
|
77
|
+
timings: {
|
|
78
|
+
[types_1.MessageStage.Finalized]: finalityEstimate,
|
|
79
|
+
[types_1.MessageStage.Validated]: VALIDATION_TIME_EST,
|
|
80
|
+
[types_1.MessageStage.Relayed]: relayEstimate,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const latestBlock = yield tryFetchChainLatestBlock(originChainId);
|
|
85
|
+
const finalizedBlock = originBlockNumber + finalityBlocks;
|
|
86
|
+
if (latestBlock && parseInt(latestBlock.number.toString()) > finalizedBlock) {
|
|
87
|
+
return {
|
|
88
|
+
stage: types_1.MessageStage.Finalized,
|
|
89
|
+
timings: {
|
|
90
|
+
[types_1.MessageStage.Finalized]: finalityEstimate,
|
|
91
|
+
[types_1.MessageStage.Validated]: VALIDATION_TIME_EST,
|
|
92
|
+
[types_1.MessageStage.Relayed]: relayEstimate,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
stage: types_1.MessageStage.Sent,
|
|
98
|
+
timings: {
|
|
99
|
+
[types_1.MessageStage.Finalized]: finalityEstimate,
|
|
100
|
+
[types_1.MessageStage.Validated]: VALIDATION_TIME_EST,
|
|
101
|
+
[types_1.MessageStage.Relayed]: relayEstimate,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function getFinalityBlocks(chainId) {
|
|
107
|
+
var _a;
|
|
108
|
+
const finalityBlocks = ((_a = sdk_1.chainIdToMetadata[chainId]) === null || _a === void 0 ? void 0 : _a.blocks.confirmations) || 0;
|
|
109
|
+
return Math.max(finalityBlocks, 1);
|
|
110
|
+
}
|
|
111
|
+
function getBlockTimeEst(chainId) {
|
|
112
|
+
var _a;
|
|
113
|
+
return ((_a = sdk_1.chainIdToMetadata[chainId]) === null || _a === void 0 ? void 0 : _a.blocks.estimateBlockTime) || 3;
|
|
114
|
+
}
|
|
115
|
+
function tryFetchChainLatestBlock(chainId) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
console.debug(`Attempting to fetch latest block for:`, chainId);
|
|
118
|
+
try {
|
|
119
|
+
const block = yield (0, explorers_1.queryExplorerForBlock)(chainId, 'latest');
|
|
120
|
+
return block;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error('Error fetching latest block', error);
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function tryFetchLatestNonce(chainId) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
console.debug(`Attempting to fetch nonce for:`, chainId);
|
|
131
|
+
try {
|
|
132
|
+
const response = yield (0, timeout_1.fetchWithTimeout)('/api/latest-nonce', {
|
|
133
|
+
method: 'POST',
|
|
134
|
+
headers: {
|
|
135
|
+
'Content-Type': 'application/json',
|
|
136
|
+
},
|
|
137
|
+
body: JSON.stringify({ chainId }),
|
|
138
|
+
}, 3000);
|
|
139
|
+
const result = yield response.json();
|
|
140
|
+
console.debug(`Found nonce:`, result.nonce);
|
|
141
|
+
return result.nonce;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error('Error fetching nonce', error);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=useMessageStage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessageStage.js","sourceRoot":"","sources":["../../src/messages/useMessageStage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAA8C;AAE9C,4CAAuD;AAEvD,kDAA2D;AAC3D,8CAAoD;AACpD,sDAAmD;AAEnD,mCAA6F;AAE7F,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAO9B,SAAgB,eAAe,CAAC,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,EAAU;IACvE,6DAA6D;I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rB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;YAC7C,OAAO,IAAI,CAAC;SACb;IACH,CAAC;CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface Params {
|
|
2
|
+
messageId?: string;
|
|
3
|
+
originTxHash?: string;
|
|
4
|
+
explorerApiUrl?: string;
|
|
5
|
+
retryInterval?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function useMessageTimeline(params: Params): {
|
|
8
|
+
message: import("./types").ApiMessage | null;
|
|
9
|
+
stage: import("./types").MessageStage;
|
|
10
|
+
timings: {};
|
|
11
|
+
error: string | null;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=useMessageTimeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessageTimeline.d.ts","sourceRoot":"","sources":["../../src/messages/useMessageTimeline.ts"],"names":[],"mappings":"AAGA,UAAU,MAAM;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM;;;;;;EAehD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMessageTimeline = void 0;
|
|
4
|
+
const useMessage_1 = require("./useMessage");
|
|
5
|
+
const useMessageStage_1 = require("./useMessageStage");
|
|
6
|
+
function useMessageTimeline(params) {
|
|
7
|
+
const { data: message, error: msgError, isLoading: isMsgLoading } = (0, useMessage_1.useMessage)(params);
|
|
8
|
+
const { stage, timings, error: stageError, isLoading: isStageLoading, } = (0, useMessageStage_1.useMessageStage)({ message, retryInterval: params.retryInterval });
|
|
9
|
+
return {
|
|
10
|
+
message,
|
|
11
|
+
stage,
|
|
12
|
+
timings,
|
|
13
|
+
error: msgError || stageError,
|
|
14
|
+
isLoading: isMsgLoading || isStageLoading,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.useMessageTimeline = useMessageTimeline;
|
|
18
|
+
//# sourceMappingURL=useMessageTimeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessageTimeline.js","sourceRoot":"","sources":["../../src/messages/useMessageTimeline.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAC1C,uDAAoD;AASpD,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,IAAA,uBAAU,EAAC,MAAM,CAAC,CAAC;IACvF,MAAM,EACJ,KAAK,EACL,OAAO,EACP,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,cAAc,GAC1B,GAAG,IAAA,iCAAe,EAAC,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IACtE,OAAO;QACL,OAAO;QACP,KAAK;QACL,OAAO;QACP,KAAK,EAAE,QAAQ,IAAI,UAAU;QAC7B,SAAS,EAAE,YAAY,IAAI,cAAc;KAC1C,CAAC;AACJ,CAAC;AAfD,gDAeC"}
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tailwindcss v3.2.4 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:Helvetica,Arial,sans-serif;font-feature-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#025aa180;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.absolute{position:absolute}.relative{position:relative}.-top-12{top:-3rem}.-right-3{right:-.75rem}.top-0{top:0}.-left-3{left:-.75rem}.mt-2\.5{margin-top:.625rem}.mt-2{margin-top:.5rem}.mt-1{margin-top:.25rem}.block{display:block}.\!block{display:block!important}.flex{display:flex}.h-6{height:1.5rem}.h-3{height:.75rem}.h-4{height:1rem}.h-9{height:2.25rem}.w-full{width:100%}.w-3{width:.75rem}.w-0\.5{width:.125rem}.w-0{width:0}.w-2{width:.5rem}.w-9{width:2.25rem}.flex-1{flex:1 1 0%}.-rotate-90{--tw-rotate:-90deg}.-rotate-90,.rotate-90{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rotate-90{--tw-rotate:90deg}.rotate-180{--tw-rotate:180deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes pulse{50%{opacity:.5}}.animate-pulse-slow{animation:pulse infinite; 3s cubic-bezier(.4,0,.6,1)}.flex-col{flex-direction:column}.items-center{align-items:center}.justify-center{justify-content:center}.rounded-full{border-radius:9999px}.rounded{border-radius:.3rem}.rounded-l{border-top-left-radius:.3rem;border-bottom-left-radius:.3rem}.rounded-r{border-top-right-radius:.3rem;border-bottom-right-radius:.3rem}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.bg-blue-500{--tw-bg-opacity:1;background-color:rgb(2 90 161/var(--tw-bg-opacity))}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.pt-14{padding-top:3.5rem}.pb-1{padding-bottom:.25rem}.text-center{text-align:center}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xs{font-size:.75rem;line-height:1rem}.text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.opacity-50{opacity:.5}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}@media (min-width:640px){.sm\:w-5{width:1.25rem}.sm\:px-2{padding-left:.5rem;padding-right:.5rem}.sm\:px-4{padding-left:1rem;padding-right:1rem}.sm\:text-base{font-size:1rem;line-height:1.5rem}}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ExplorerQueryResponse<R> {
|
|
2
|
+
status: string;
|
|
3
|
+
message: string;
|
|
4
|
+
result: R;
|
|
5
|
+
}
|
|
6
|
+
export declare function getExplorerUrl(chainId: number): string | null;
|
|
7
|
+
export declare function getExplorerApiUrl(chainId: number): string | null;
|
|
8
|
+
export declare function getTxExplorerUrl(chainId: number, hash?: string): string | null;
|
|
9
|
+
export declare function queryExplorer<P>(chainId: number, path: string, apiKey?: string, timeout?: number): Promise<NonNullable<P>>;
|
|
10
|
+
export declare function executeExplorerQuery<P>(url: string, timeout?: number): Promise<NonNullable<P>>;
|
|
11
|
+
interface PartialBlock {
|
|
12
|
+
hash: string;
|
|
13
|
+
number: number;
|
|
14
|
+
timestamp: number;
|
|
15
|
+
nonce: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function queryExplorerForBlock(chainId: number, blockNumber?: number | string): Promise<PartialBlock>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=explorers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explorers.d.ts","sourceRoot":"","sources":["../../src/utils/explorers.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,CAAC;CACX;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,iBAI7C;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,iBAIhD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,iBAI9D;AAED,wBAAsB,aAAa,CAAC,CAAC,EACnC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,2BAcjB;AAED,wBAAsB,oBAAoB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,2BAa1E;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,yBAWzF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.queryExplorerForBlock = exports.executeExplorerQuery = exports.queryExplorer = exports.getTxExplorerUrl = exports.getExplorerApiUrl = exports.getExplorerUrl = void 0;
|
|
13
|
+
const sdk_1 = require("@hyperlane-xyz/sdk");
|
|
14
|
+
const timeout_1 = require("./timeout");
|
|
15
|
+
function getExplorerUrl(chainId) {
|
|
16
|
+
var _a;
|
|
17
|
+
const chain = sdk_1.chainIdToMetadata[chainId];
|
|
18
|
+
if (!((_a = chain === null || chain === void 0 ? void 0 : chain.blockExplorers) === null || _a === void 0 ? void 0 : _a.length))
|
|
19
|
+
return null;
|
|
20
|
+
return chain.blockExplorers[0].url;
|
|
21
|
+
}
|
|
22
|
+
exports.getExplorerUrl = getExplorerUrl;
|
|
23
|
+
function getExplorerApiUrl(chainId) {
|
|
24
|
+
var _a;
|
|
25
|
+
const chain = sdk_1.chainIdToMetadata[chainId];
|
|
26
|
+
if (!((_a = chain === null || chain === void 0 ? void 0 : chain.blockExplorers) === null || _a === void 0 ? void 0 : _a.length))
|
|
27
|
+
return null;
|
|
28
|
+
return chain.blockExplorers[0].apiUrl || chain.blockExplorers[0].url;
|
|
29
|
+
}
|
|
30
|
+
exports.getExplorerApiUrl = getExplorerApiUrl;
|
|
31
|
+
function getTxExplorerUrl(chainId, hash) {
|
|
32
|
+
const baseUrl = getExplorerUrl(chainId);
|
|
33
|
+
if (!hash || !baseUrl)
|
|
34
|
+
return null;
|
|
35
|
+
return `${baseUrl}/tx/${hash}`;
|
|
36
|
+
}
|
|
37
|
+
exports.getTxExplorerUrl = getTxExplorerUrl;
|
|
38
|
+
function queryExplorer(chainId, path, apiKey, timeout) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const baseUrl = getExplorerApiUrl(chainId);
|
|
41
|
+
if (!baseUrl)
|
|
42
|
+
throw new Error(`No URL found for explorer for chain ${chainId}`);
|
|
43
|
+
let url = `${baseUrl}/${path}`;
|
|
44
|
+
console.debug('Querying explorer url:', url);
|
|
45
|
+
if (apiKey) {
|
|
46
|
+
url += `&apikey=${apiKey}`;
|
|
47
|
+
}
|
|
48
|
+
const result = yield executeExplorerQuery(url, timeout);
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
exports.queryExplorer = queryExplorer;
|
|
53
|
+
function executeExplorerQuery(url, timeout) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const response = yield (0, timeout_1.fetchWithTimeout)(url, undefined, timeout);
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
throw new Error(`Fetch response not okay: ${response.status}`);
|
|
58
|
+
}
|
|
59
|
+
const json = (yield response.json());
|
|
60
|
+
if (!json.result) {
|
|
61
|
+
const responseText = yield response.text();
|
|
62
|
+
throw new Error(`Invalid result format: ${responseText}`);
|
|
63
|
+
}
|
|
64
|
+
return json.result;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
exports.executeExplorerQuery = executeExplorerQuery;
|
|
68
|
+
function queryExplorerForBlock(chainId, blockNumber) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const path = `api?module=proxy&action=eth_getBlockByNumber&tag=${blockNumber || 'latest'}&boolean=false`;
|
|
71
|
+
const block = yield queryExplorer(chainId, path);
|
|
72
|
+
if (!block || parseInt(block.number.toString()) < 0) {
|
|
73
|
+
const msg = 'Invalid block result';
|
|
74
|
+
console.error(msg, JSON.stringify(block), path);
|
|
75
|
+
throw new Error(msg);
|
|
76
|
+
}
|
|
77
|
+
return block;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
exports.queryExplorerForBlock = queryExplorerForBlock;
|
|
81
|
+
//# sourceMappingURL=explorers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explorers.js","sourceRoot":"","sources":["../../src/utils/explorers.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAuD;AAEvD,uCAA6C;AAQ7C,SAAgB,cAAc,CAAC,OAAe;;IAC5C,MAAM,KAAK,GAAG,uBAAiB,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,CAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,0CAAE,MAAM,CAAA;QAAE,OAAO,IAAI,CAAC;IAChD,OAAO,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACrC,CAAC;AAJD,wCAIC;AAED,SAAgB,iBAAiB,CAAC,OAAe;;IAC/C,MAAM,KAAK,GAAG,uBAAiB,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,CAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,0CAAE,MAAM,CAAA;QAAE,OAAO,IAAI,CAAC;IAChD,OAAO,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACvE,CAAC;AAJD,8CAIC;AAED,SAAgB,gBAAgB,CAAC,OAAe,EAAE,IAAa;IAC7D,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,GAAG,OAAO,OAAO,IAAI,EAAE,CAAC;AACjC,CAAC;AAJD,4CAIC;AAED,SAAsB,aAAa,CACjC,OAAe,EACf,IA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CAAe,OAAO,EAAE,IAAI,CAAC,CAAC;QAC/D,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE;YACnD,MAAM,GAAG,GAAG,sBAAsB,CAAC;YACnC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;SACtB;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CAAA;AAXD,sDAWC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/utils/timeout.ts"],"names":[],"mappings":"AAAA,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,WAAW,EACrB,OAAO,SAAQ,qBAUhB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fetchWithTimeout = void 0;
|
|
13
|
+
function fetchWithTimeout(resource, options, timeout = 10000) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
const id = setTimeout(() => controller.abort(), timeout);
|
|
17
|
+
const response = yield fetch(resource, Object.assign(Object.assign({}, options), { signal: controller.signal }));
|
|
18
|
+
clearTimeout(id);
|
|
19
|
+
return response;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.fetchWithTimeout = fetchWithTimeout;
|
|
23
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/utils/timeout.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAsB,gBAAgB,CACpC,QAAqB,EACrB,OAAqB,EACrB,OAAO,GAAG,KAAK;;QAEf,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,kCAChC,OAAO,KACV,MAAM,EAAE,UAAU,CAAC,MAAM,IACzB,CAAC;QACH,YAAY,CAAC,EAAE,CAAC,CAAC;QACjB,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA;AAbD,4CAaC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInterval.d.ts","sourceRoot":"","sources":["../../src/utils/useInterval.ts"],"names":[],"mappings":"AAMA,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,QAoBrE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInterval = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_2 = require("react");
|
|
6
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? react_2.useLayoutEffect : react_1.useEffect;
|
|
7
|
+
// https://usehooks-typescript.com/react-hook/use-interval
|
|
8
|
+
function useInterval(callback, delay) {
|
|
9
|
+
const savedCallback = (0, react_1.useRef)(callback);
|
|
10
|
+
// Remember the latest callback if it changes.
|
|
11
|
+
useIsomorphicLayoutEffect(() => {
|
|
12
|
+
savedCallback.current = callback;
|
|
13
|
+
}, [callback]);
|
|
14
|
+
// Set up the interval.
|
|
15
|
+
(0, react_1.useEffect)(() => {
|
|
16
|
+
// Don't schedule if no delay is specified.
|
|
17
|
+
// Note: 0 is a valid value for delay.
|
|
18
|
+
if (!delay && delay !== 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const id = setInterval(() => savedCallback.current(), delay);
|
|
22
|
+
return () => clearInterval(id);
|
|
23
|
+
}, [delay]);
|
|
24
|
+
}
|
|
25
|
+
exports.useInterval = useInterval;
|
|
26
|
+
//# sourceMappingURL=useInterval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInterval.js","sourceRoot":"","sources":["../../src/utils/useInterval.ts"],"names":[],"mappings":";;;AAAA,iCAA0C;AAC1C,iCAAwC;AAExC,MAAM,yBAAyB,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,uBAAe,CAAC,CAAC,CAAC,iBAAS,CAAC;AAE9F,0DAA0D;AAC1D,SAAgB,WAAW,CAAC,QAAoB,EAAE,KAAoB;IACpE,MAAM,aAAa,GAAG,IAAA,cAAM,EAAC,QAAQ,CAAC,CAAC;IAEvC,8CAA8C;IAC9C,yBAAyB,CAAC,GAAG,EAAE;QAC7B,aAAa,CAAC,OAAO,GAAG,QAAQ,CAAC;IACnC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,uBAAuB;IACvB,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,2CAA2C;QAC3C,sCAAsC;QACtC,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,CAAC,EAAE;YACzB,OAAO;SACR;QAED,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QAE7D,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,CAAC;AApBD,kCAoBC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hyperlane-xyz/widgets",
|
|
3
|
+
"description": "Common react components for Hyperlane projects",
|
|
4
|
+
"version": "1.0.0-beta1",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"@hyperlane-xyz/sdk": "1.0.0",
|
|
7
|
+
"react": "^18",
|
|
8
|
+
"react-dom": "^18"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@babel/core": "^7.20.12",
|
|
12
|
+
"@hyperlane-xyz/sdk": "1.0.0",
|
|
13
|
+
"@mdx-js/react": "^1.6.22",
|
|
14
|
+
"@storybook/addon-actions": "^6.5.15",
|
|
15
|
+
"@storybook/addon-docs": "^6.5.15",
|
|
16
|
+
"@storybook/addon-essentials": "^6.5.15",
|
|
17
|
+
"@storybook/addon-interactions": "^6.5.15",
|
|
18
|
+
"@storybook/addon-links": "^6.5.15",
|
|
19
|
+
"@storybook/addon-postcss": "^2.0.0",
|
|
20
|
+
"@storybook/builder-webpack4": "^6.5.15",
|
|
21
|
+
"@storybook/manager-webpack4": "^6.5.15",
|
|
22
|
+
"@storybook/react": "^6.5.15",
|
|
23
|
+
"@storybook/testing-library": "^0.0.13",
|
|
24
|
+
"@trivago/prettier-plugin-sort-imports": "^3.2.0",
|
|
25
|
+
"@types/node": "^18.11.18",
|
|
26
|
+
"@types/react": "^18.0.27",
|
|
27
|
+
"@types/react-dom": "^18.0.10",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
|
29
|
+
"@typescript-eslint/parser": "^5.27.0",
|
|
30
|
+
"babel-loader": "^8.3.0",
|
|
31
|
+
"eslint": "^8.16.0",
|
|
32
|
+
"eslint-config-prettier": "^8.5.0",
|
|
33
|
+
"postcss": "^8.4.21",
|
|
34
|
+
"prettier": "^2.4.1",
|
|
35
|
+
"react": "^18.2.0",
|
|
36
|
+
"react-dom": "^18.2.0",
|
|
37
|
+
"tailwindcss": "^3.2.4",
|
|
38
|
+
"ts-node": "^10.8.0",
|
|
39
|
+
"typescript": "^4.7.2"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"/dist"
|
|
43
|
+
],
|
|
44
|
+
"main": "dist/index.js",
|
|
45
|
+
"types": "dist/index.d.ts",
|
|
46
|
+
"homepage": "https://www.hyperlane.xyz",
|
|
47
|
+
"keywords": [
|
|
48
|
+
"Hyperlane",
|
|
49
|
+
"Widgets",
|
|
50
|
+
"React",
|
|
51
|
+
"Components",
|
|
52
|
+
"Typescript"
|
|
53
|
+
],
|
|
54
|
+
"license": "Apache-2.0",
|
|
55
|
+
"packageManager": "yarn@3.2.0",
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "https://github.com/hyperlane-xyz/hyperlane-widgets"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "yarn build:ts && yarn build:css",
|
|
62
|
+
"build:ts": "tsc",
|
|
63
|
+
"build:css": "tailwindcss -i ./src/styles.css -o ./dist/styles.css --minify",
|
|
64
|
+
"clean": "rm -rf dist cache",
|
|
65
|
+
"lint": "eslint . --ext .ts",
|
|
66
|
+
"prettier": "prettier --write ./src",
|
|
67
|
+
"storybook": "start-storybook -p 6006",
|
|
68
|
+
"build-storybook": "build-storybook"
|
|
69
|
+
}
|
|
70
|
+
}
|