@xswap-link/sdk 0.3.5 → 0.4.0

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.
Files changed (199) hide show
  1. package/.eslintrc.json +9 -5
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +2 -1
  4. package/dist/index.d.mts +106 -20
  5. package/dist/index.d.ts +106 -20
  6. package/dist/index.global.js +963 -164
  7. package/dist/index.global.js.map +1 -0
  8. package/dist/index.js +105 -3564
  9. package/dist/index.js.map +1 -0
  10. package/dist/index.mjs +105 -3534
  11. package/dist/index.mjs.map +1 -0
  12. package/nodemon.json +1 -1
  13. package/package.json +16 -9
  14. package/postcss.config.js +8 -1
  15. package/src/{components → assets}/icons/ArrowDownIcon.tsx +1 -2
  16. package/src/assets/icons/ArrowDownLongIcon.tsx +12 -0
  17. package/src/{components → assets}/icons/ArrowLeftIcon.tsx +1 -5
  18. package/src/{components → assets}/icons/ArrowRightIcon.tsx +1 -5
  19. package/src/assets/icons/ArrowUpIcon.tsx +12 -0
  20. package/src/{components → assets}/icons/ArrowUpRightIcon.tsx +1 -5
  21. package/src/assets/icons/CashbacklIcon.tsx +28 -0
  22. package/src/{components → assets}/icons/CheckIcon.tsx +1 -5
  23. package/src/assets/icons/ChevronDownIcon.tsx +12 -0
  24. package/src/assets/icons/ChevronUpIcon.tsx +7 -0
  25. package/src/{components → assets}/icons/CircularProgressIcon.tsx +1 -2
  26. package/src/assets/icons/CloseIcon.tsx +15 -0
  27. package/src/{components → assets}/icons/CoinsIcon.tsx +0 -2
  28. package/src/assets/icons/CopyIcon.tsx +15 -0
  29. package/src/assets/icons/DotGreenIcon.tsx +12 -0
  30. package/src/{components → assets}/icons/DownArrorIcon.tsx +0 -2
  31. package/src/{components → assets}/icons/ErrorIcon.tsx +0 -1
  32. package/src/assets/icons/ErrorModalStatusIcon.tsx +31 -0
  33. package/src/assets/icons/HelpIcon.tsx +21 -0
  34. package/src/assets/icons/HistoryGradientBgIcon.tsx +32 -0
  35. package/src/assets/icons/HistoryIcon.tsx +12 -0
  36. package/src/{components → assets}/icons/HourGlassIcon.tsx +1 -5
  37. package/src/assets/icons/Icon.tsx +5 -0
  38. package/src/{components → assets}/icons/InfoIcon.tsx +0 -1
  39. package/src/assets/icons/LinkExternalIcon.tsx +15 -0
  40. package/src/{components → assets}/icons/PercentageIcon.tsx +0 -1
  41. package/src/assets/icons/RankIcon.tsx +28 -0
  42. package/src/assets/icons/SettingsGradientBgIcon.tsx +32 -0
  43. package/src/assets/icons/SettingsIcon.tsx +12 -0
  44. package/src/{components → assets}/icons/SignIcon.tsx +0 -2
  45. package/src/{components → assets}/icons/SuccessIcon.tsx +0 -1
  46. package/src/assets/icons/SuccessModalStatusIcon.tsx +31 -0
  47. package/src/assets/icons/ThumbUpRoundedIcon.tsx +15 -0
  48. package/src/{components → assets}/icons/TimerIcon.tsx +0 -1
  49. package/src/assets/icons/TokensIcon.tsx +16 -0
  50. package/src/assets/icons/WaitingIcon.tsx +15 -0
  51. package/src/{components → assets}/icons/XMarkIcon.tsx +1 -5
  52. package/src/assets/icons/XPowerIcon.tsx +28 -0
  53. package/src/{components → assets}/icons/index.ts +16 -0
  54. package/src/components/Alert/index.tsx +1 -1
  55. package/src/components/Button/index.tsx +57 -0
  56. package/src/components/MessageBar/SnackMessage.tsx +32 -0
  57. package/src/components/MessageBar/index.tsx +44 -0
  58. package/src/components/Modal/index.tsx +52 -0
  59. package/src/components/PoweredBy/index.tsx +12 -0
  60. package/src/components/SafeInput/index.tsx +51 -0
  61. package/src/components/Skeleton/index.tsx +5 -9
  62. package/src/components/Spinner/index.tsx +6 -8
  63. package/src/components/Swap/Header/Controls/index.tsx +57 -0
  64. package/src/components/Swap/Header/index.tsx +16 -0
  65. package/src/components/Swap/HistoryView/index.tsx +34 -0
  66. package/src/components/Swap/SettingsView/Delivery/index.tsx +42 -0
  67. package/src/components/Swap/SettingsView/Slippage/index.tsx +80 -0
  68. package/src/components/Swap/SettingsView/index.tsx +11 -0
  69. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/ArrowIcon.tsx +13 -0
  70. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Header/index.tsx +37 -0
  71. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Steps/index.tsx +145 -0
  72. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/SwapPanel/index.tsx +61 -0
  73. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +291 -0
  74. package/src/components/Swap/SwapView/ConfirmationView/TxResult/TokenItem/index.tsx +24 -0
  75. package/src/components/Swap/SwapView/ConfirmationView/TxResult/index.tsx +84 -0
  76. package/src/components/Swap/SwapView/ConfirmationView/index.tsx +17 -0
  77. package/src/components/Swap/SwapView/FeesPanel/DeliveryInfo/index.tsx +25 -0
  78. package/src/components/Swap/SwapView/FeesPanel/Fee/index.tsx +18 -0
  79. package/src/components/Swap/SwapView/FeesPanel/Fees/index.tsx +71 -0
  80. package/src/components/Swap/SwapView/FeesPanel/index.tsx +67 -0
  81. package/src/components/Swap/SwapView/SwapButton/index.tsx +154 -0
  82. package/src/components/Swap/SwapView/SwapPanel/AmountPanel/Balance/index.tsx +23 -0
  83. package/src/components/Swap/SwapView/SwapPanel/AmountPanel/index.tsx +56 -0
  84. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/ChainPicker/ChainItem/index.tsx +70 -0
  85. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/ChainPicker/index.tsx +62 -0
  86. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/index.tsx +74 -0
  87. package/src/components/Swap/SwapView/SwapPanel/MaxPanel/index.tsx +35 -0
  88. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/QuickPickTokenItem/index.tsx +40 -0
  89. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/TokenItem/index.tsx +62 -0
  90. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/index.tsx +399 -0
  91. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/index.tsx +104 -0
  92. package/src/components/Swap/SwapView/SwapPanel/index.tsx +42 -0
  93. package/src/components/Swap/SwapView/index.tsx +20 -0
  94. package/src/components/Swap/index.tsx +34 -0
  95. package/src/components/TextInput/index.tsx +67 -0
  96. package/src/components/Timer/index.tsx +57 -0
  97. package/src/components/ToggleButton/index.tsx +24 -0
  98. package/src/components/{UnknownTokenLogo/UnknownTokenLogo.tsx → TokenLogo/Unknown/index.tsx} +3 -4
  99. package/src/components/TokenLogo/WithChain/index.tsx +34 -0
  100. package/src/components/TokenLogo/index.tsx +22 -0
  101. package/src/components/Tooltip/index.tsx +108 -0
  102. package/src/components/TxConfigForm/index.tsx +63 -42
  103. package/src/components/TxDataCard/TokenDetails/index.tsx +30 -0
  104. package/src/components/TxDataCard/TxDataCardUI/index.tsx +133 -0
  105. package/src/components/TxDataCard/index.tsx +30 -0
  106. package/src/components/TxStatusButton/index.tsx +64 -108
  107. package/src/components/global.css +115 -4
  108. package/src/components/index.ts +18 -1
  109. package/src/config/fonts.ts +114 -0
  110. package/src/config/global.d.ts +4 -0
  111. package/src/config/init.tsx +35 -31
  112. package/src/constants/crosschainEstimationTimes.ts +52 -0
  113. package/src/constants/index.ts +8 -0
  114. package/src/context/GlobalDataProvider.tsx +165 -0
  115. package/src/context/HistoryProvider.tsx +339 -0
  116. package/src/context/ModalProvider.tsx +47 -0
  117. package/src/context/SwapProvider.tsx +664 -0
  118. package/src/context/TransactionProvider.tsx +86 -0
  119. package/src/context/TxUIWrapper.tsx +388 -0
  120. package/src/context/index.ts +5 -0
  121. package/src/contracts/abi/CustomXSwapRouter.json +953 -0
  122. package/src/contracts/abi/StakingStableAPR.json +1438 -0
  123. package/src/contracts/abi/XSwapRouter.json +1242 -0
  124. package/src/contracts/abi/XSwapTokenFeeDistributor.json +350 -0
  125. package/src/contracts/abi/index.ts +8 -0
  126. package/src/contracts/addresses.ts +24 -6
  127. package/src/fonts/Satoshi-Black.woff2 +0 -0
  128. package/src/fonts/Satoshi-BlackItalic.woff2 +0 -0
  129. package/src/fonts/Satoshi-Bold.woff2 +0 -0
  130. package/src/fonts/Satoshi-BoldItalic.woff2 +0 -0
  131. package/src/fonts/Satoshi-Light.woff2 +0 -0
  132. package/src/fonts/Satoshi-LightItalic.woff2 +0 -0
  133. package/src/fonts/Satoshi-Medium.woff2 +0 -0
  134. package/src/fonts/Satoshi-MediumItalic.woff2 +0 -0
  135. package/src/fonts/Satoshi-Regular.woff2 +0 -0
  136. package/src/fonts/Satoshi-RegularItalic.woff2 +0 -0
  137. package/src/fonts/Satoshi-Variable.woff2 +0 -0
  138. package/src/fonts/Satoshi-VariableItalic.woff2 +0 -0
  139. package/src/hooks/index.ts +5 -0
  140. package/src/hooks/networkManagement/clientToSigner.tsx +17 -0
  141. package/src/hooks/networkManagement/useNetworks.ts +51 -0
  142. package/src/hooks/useBatchQuery.ts +46 -0
  143. package/src/hooks/useDebounce.tsx +28 -0
  144. package/src/hooks/useEvmContractApi.ts +85 -0
  145. package/src/hooks/usePortal.ts +79 -0
  146. package/src/hooks/useXPower.ts +58 -0
  147. package/src/models/Addresses.ts +8 -2
  148. package/src/models/TokenData.ts +13 -0
  149. package/src/models/TransactionHistory.ts +2 -0
  150. package/src/models/TxUIWrapper.ts +51 -0
  151. package/src/models/XSwapConfig.ts +1 -0
  152. package/src/models/index.ts +1 -0
  153. package/src/models/payloads/GetBalancesPayload.ts +3 -0
  154. package/src/models/payloads/GetFinishedLeaderboardQuestsPayload.ts +3 -0
  155. package/src/models/payloads/GetLeaderboardChangePayload.ts +4 -0
  156. package/src/models/payloads/{GetSwapTxPayload.ts → ModalIntegrationPayload.ts} +3 -1
  157. package/src/models/payloads/index.ts +5 -2
  158. package/src/services/api.ts +34 -5
  159. package/src/services/integrations/monitoring.ts +49 -37
  160. package/src/services/integrations/transactions.ts +50 -6
  161. package/src/utils/contracts.ts +29 -0
  162. package/src/utils/index.ts +3 -3
  163. package/src/utils/numbers.ts +14 -0
  164. package/src/utils/parseWeb3Error.ts +7 -3
  165. package/tailwind.config.js +15 -5
  166. package/tsconfig.json +7 -7
  167. package/tsup.config.ts +61 -0
  168. package/xswap.config.ts +1 -0
  169. package/dist/index.css +0 -1
  170. package/src/components/TxConfigForm/BalanceComponent.tsx +0 -52
  171. package/src/components/TxConfigForm/Button.tsx +0 -20
  172. package/src/components/TxConfigForm/ChainListElement.tsx +0 -36
  173. package/src/components/TxConfigForm/ConfirmationAmount.tsx +0 -91
  174. package/src/components/TxConfigForm/ConfirmationView/ErrorView.tsx +0 -38
  175. package/src/components/TxConfigForm/ConfirmationView/SuccessView.tsx +0 -159
  176. package/src/components/TxConfigForm/ConfirmationView/index.tsx +0 -149
  177. package/src/components/TxConfigForm/ConnectWalletPrompt.tsx +0 -21
  178. package/src/components/TxConfigForm/Description.tsx +0 -17
  179. package/src/components/TxConfigForm/ErrorField.tsx +0 -19
  180. package/src/components/TxConfigForm/FeesDetails.tsx +0 -117
  181. package/src/components/TxConfigForm/Form.tsx +0 -574
  182. package/src/components/TxConfigForm/History.tsx +0 -131
  183. package/src/components/TxConfigForm/HistoryCard.tsx +0 -182
  184. package/src/components/TxConfigForm/PoweredBy.tsx +0 -12
  185. package/src/components/TxConfigForm/Settings.tsx +0 -143
  186. package/src/components/TxConfigForm/Summary.tsx +0 -105
  187. package/src/components/TxConfigForm/SwapPanel.tsx +0 -185
  188. package/src/components/TxConfigForm/TokenPicker.tsx +0 -176
  189. package/src/components/TxConfigForm/TopBar.tsx +0 -58
  190. package/src/components/TxConfigForm/UsdPrice.tsx +0 -44
  191. package/src/components/icons/ChevronDownIcon.tsx +0 -15
  192. package/src/components/icons/ChevronUpIcon.tsx +0 -10
  193. package/src/components/icons/CloseIcon.tsx +0 -15
  194. package/src/components/icons/HistoryIcon.tsx +0 -16
  195. package/src/components/icons/SettingsIcon.tsx +0 -16
  196. /package/src/{components → assets}/icons/ChainlinkCCIPIcon.tsx +0 -0
  197. /package/src/{components → assets}/icons/SearchIcon.tsx +0 -0
  198. /package/src/{components → assets}/icons/XSwapBadgeIcon.tsx +0 -0
  199. /package/src/{components → assets}/icons/XSwapLogo.tsx +0 -0
@@ -2,7 +2,9 @@
2
2
  @tailwind components;
3
3
  @tailwind utilities;
4
4
 
5
- .xpay {
5
+ :host {
6
+ color: white;
7
+
6
8
  /* Works on Firefox */
7
9
  * {
8
10
  scrollbar-width: thin;
@@ -26,11 +28,120 @@
26
28
  }
27
29
 
28
30
  @layer components {
29
- .xpay-global-border {
30
- border: 1px solid rgba(255, 255, 255, 0.1);
31
+ .gradient-border-container-blue {
32
+ @apply bg-gradient-to-r from-x_blue_300 to-x_blue_400 p-[1px];
33
+ }
34
+
35
+ .gradient-sections-separator-container {
36
+ @apply bg-gradient-to-r from-transparent via-white/25 to-transparent;
37
+ }
38
+
39
+ .x-border {
40
+ @apply border border-solid border-white border-opacity-10;
31
41
  }
32
42
 
33
43
  .xpay-tx-status {
34
- @apply xpay-fixed xpay-bottom-5 xpay-right-2 xpay-flex xpay-flex-col xpay-gap-3 xpay-pl-9 xpay-items-end xpay-w-full xpay-z-50;
44
+ @apply fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50;
45
+ }
46
+
47
+ .x-border {
48
+ @apply border border-solid border-white border-opacity-10;
49
+ }
50
+
51
+ .selected-chain-item {
52
+ @apply bg-white bg-opacity-10 border-opacity-10 rounded-2xl;
53
+ }
54
+ .disabled-chain-item {
55
+ @apply bg-white bg-opacity-10 border-opacity-10 rounded-2xl opacity-70;
56
+ }
57
+
58
+ .horizontal-separator {
59
+ @apply h-0.5 bg-white bg-opacity-10 w-full;
60
+ }
61
+
62
+ .vertical-separator {
63
+ @apply w-0.5 bg-white bg-opacity-60 h-full;
64
+ }
65
+
66
+ .token-picker-container {
67
+ @apply flex gap-3 py-2 px-4 items-center cursor-pointer hover:bg-white hover:bg-opacity-10;
68
+ }
69
+
70
+ .btn {
71
+ @apply bg-transparent m-0 appearance-none border-none text-sm relative z-[1] text-white whitespace-nowrap;
72
+ }
73
+
74
+ .btn:hover {
75
+ @apply cursor-pointer;
76
+ }
77
+
78
+ .btn-disabled {
79
+ @apply opacity-50 text-white hover:cursor-not-allowed;
80
+ }
81
+
82
+ .btn-small {
83
+ @apply h-[26px] leading-[26px];
84
+ }
85
+
86
+ .btn-medium {
87
+ @apply h-[32px] leading-[32px];
88
+ }
89
+
90
+ .btn-large {
91
+ @apply h-[42px] leading-[42px];
92
+ }
93
+
94
+ .btn-contained {
95
+ @apply text-center border-2 border-[#375bd2] bg-white text-[#375bd2] rounded-xl px-8 hover:bg-[#375bd2] hover:text-white;
96
+ }
97
+
98
+ .btn-contained:before {
99
+ @apply content-[''] absolute transition-all duration-300 ease-out shadow-[0_0_4px_0_rgba(102,204,154,0.7)] rounded-xl bg-gradient-to-r from-x_swap_primary to-x_swap_secondary_active w-[calc(100%+4px)] h-[calc(100%+4px)] top-[-2px] left-[-2px] -z-[1] opacity-0;
100
+ }
101
+
102
+ .btn-contained-disabled {
103
+ @apply text-center opacity-50 bg-[#626262] text-white rounded-xl px-8;
35
104
  }
105
+
106
+ .btn-outlined {
107
+ @apply text-center text-white rounded-xl border border-white/20 px-8 hover:before:opacity-100;
108
+ }
109
+
110
+ .btn-outlined:before {
111
+ @apply content-[''] absolute transition-all duration-300 ease-out rounded-xl border-2 border-secondary-active w-full h-full top-[-2px] left-[-2px] -z-[1] opacity-0;
112
+ }
113
+
114
+ .btn-outlined-disabled {
115
+ @apply text-center opacity-50 border border-white/20 text-white rounded-xl px-8;
116
+ }
117
+
118
+ .btn--full-width {
119
+ @apply w-full;
120
+ }
121
+
122
+ .btn-default {
123
+ @apply px-8;
124
+ }
125
+
126
+ .btn-filled-rounded {
127
+ @apply flex items-center justify-center rounded-full text-white px-8 cursor-pointer whitespace-nowrap bg-gradient-to-r from-x_blue_400 to-x_blue_600;
128
+ }
129
+
130
+ .btn-filled-squared {
131
+ @apply flex items-center justify-center rounded-lg text-white px-8 cursor-pointer whitespace-nowrap bg-gradient-to-r from-x_blue_400 to-x_blue_600;
132
+ }
133
+
134
+ .btn-filled-rounded-secondary {
135
+ @apply flex items-center justify-center rounded-full text-white px-8 cursor-pointer whitespace-nowrap border border-blue;
136
+ }
137
+
138
+ .btn-filled-rounded-disabled {
139
+ @apply flex items-center justify-center opacity-50 border border-white/20 text-white bg-dark-grey rounded-full px-8 hover:cursor-not-allowed;
140
+ }
141
+ }
142
+
143
+ /* override notistack position */
144
+ .SnackbarContainer-top,
145
+ .notistack-SnackbarContainer {
146
+ top: 100px !important;
36
147
  }
@@ -1,4 +1,21 @@
1
1
  export * from "./Alert";
2
+ export * from "./Button";
3
+ export * from "./ToggleButton";
4
+ export * from "./MessageBar";
5
+ export * from "./MessageBar/SnackMessage";
6
+ export * from "./Modal";
7
+ export * from "./PoweredBy";
8
+ export * from "./SafeInput";
9
+ export * from "./Skeleton";
10
+ export * from "./Spinner";
11
+ export * from "./Swap";
12
+ export * from "./TextInput";
13
+ export * from "./Timer";
14
+ export * from "./TokenLogo";
15
+ export * from "./TokenLogo/WithChain";
16
+ export * from "./TokenLogo/Unknown";
17
+ export * from "./Tooltip";
2
18
  export * from "./TxConfigForm";
19
+ export * from "./TxDataCard";
3
20
  export * from "./TxStatusButton";
4
- export * from "./Skeleton";
21
+ export * from "./WaitingForInit";
@@ -0,0 +1,114 @@
1
+ // import SatoshiVariableWOFF2 from "../fonts/Satoshi-Variable.woff2";
2
+ // const Satosh1iVariable = `@font-face {
3
+ // font-family: "Satoshi-Variable";
4
+ // src: url(${SatoshiVariableWOFF2}) format("woff2");
5
+ // font-weight: 100 300 900;
6
+ // font-display: swap;
7
+ // font-style: normal;
8
+ // }`;
9
+
10
+ // import SatoshiVariableItalicWOFF2 from "../fonts/Satoshi-VariableItalic.woff2";
11
+ // const SatoshiVariableItalic = `@font-face {
12
+ // font-family: "Satoshi-VariableItalic";
13
+ // src: url(${SatoshiVariableItalicWOFF2}) format("woff2");
14
+ // font-weight: 300 900;
15
+ // font-display: swap;
16
+ // font-style: italic;
17
+ // }`;
18
+
19
+ // import SatoshiLightWOFF2 from "../fonts/Satoshi-Light.woff2";
20
+ // const SatoshiLight = `@font-face {
21
+ // font-family: "Satoshi-Light";
22
+ // src: url(${SatoshiLightWOFF2}) format("woff2");
23
+ // font-weight: 300;
24
+ // font-display: swap;
25
+ // font-style: normal;
26
+ // }`;
27
+
28
+ // import SatoshiLightItalicWOFF2 from "../fonts/Satoshi-LightItalic.woff2";
29
+ // const SatoshiLightItalic = `@font-face {
30
+ // font-family: "Satoshi-LightItalic";
31
+ // src: url(${SatoshiLightItalicWOFF2}) format("woff2");
32
+ // font-weight: 300;
33
+ // font-display: swap;
34
+ // font-style: italic;
35
+ // }`;
36
+
37
+ // import SatoshiRegularWOFF2 from "../fonts/Satoshi-Regular.woff2";
38
+ // const SatoshiRegular = `@font-face {
39
+ // font-family: "Satoshi-Regular";
40
+ // src: url(${SatoshiRegularWOFF2}) format("woff2");
41
+ // font-weight: 400;
42
+ // font-display: swap;
43
+ // font-style: normal;
44
+ // }`;
45
+
46
+ // import SatoshiRegularItalicWOFF2 from "../fonts/Satoshi-RegularItalic.woff2";
47
+ // const SatoshiRegularItalic = `@font-face {
48
+ // font-family: "Satoshi-RegularItalic";
49
+ // src: url(${SatoshiRegularItalicWOFF2}) format("woff2");
50
+ // font-weight: 400;
51
+ // font-display: swap;
52
+ // font-style: italic;
53
+ // }`;
54
+
55
+ import SatoshiMediumWOFF2 from "../fonts/Satoshi-Medium.woff2";
56
+ const SatoshiMedium = `@font-face {
57
+ font-family: "Satoshi-Medium";
58
+ src: url(${SatoshiMediumWOFF2}) format("woff2");
59
+ font-weight: 500;
60
+ font-display: swap;
61
+ font-style: normal;
62
+ }`;
63
+
64
+ // import SatoshiMediumItalicWOFF2 from "../fonts/Satoshi-MediumItalic.woff2";
65
+ // const SatoshiMediumItalic = `@font-face {
66
+ // font-family: "Satoshi-MediumItalic";
67
+ // src: url(${SatoshiMediumItalicWOFF2}) format("woff2");
68
+ // font-weight: 500;
69
+ // font-display: swap;
70
+ // font-style: italic;
71
+ // }`;
72
+
73
+ // import SatoshiBoldWOFF2 from "../fonts/Satoshi-Bold.woff2";
74
+ // const SatoshiBold = `@font-face {
75
+ // font-family: "Satoshi-Bold";
76
+ // src: url(${SatoshiBoldWOFF2}) format("woff2");
77
+ // font-weight: 700;
78
+ // font-display: swap;
79
+ // font-style: normal;
80
+ // }`;
81
+
82
+ // import SatoshiBoldItalicWOFF2 from "../fonts/Satoshi-BoldItalic.woff2";
83
+ // const SatoshiBoldItalic = `@font-face {
84
+ // font-family: "Satoshi-BoldItalic";
85
+ // src: url(${SatoshiBoldItalicWOFF2}) format("woff2");
86
+ // font-weight: 700;
87
+ // font-display: swap;
88
+ // font-style: italic;
89
+ // }`;
90
+
91
+ // import SatoshiBlackWOFF2 from "../fonts/Satoshi-Black.woff2";
92
+ // const SatoshiBlack = `@font-face {
93
+ // font-family: "Satoshi-Black";
94
+ // src: url(${SatoshiBlackWOFF2}) format("woff2");
95
+ // font-weight: 900;
96
+ // font-display: swap;
97
+ // font-style: normal;
98
+ // }`;
99
+
100
+ // import SatoshiBlackItalicWOFF2 from "../fonts/Satoshi-BlackItalic.woff2";
101
+ // const SatoshiBlackItalic = `@font-face {
102
+ // font-family: "Satoshi-BlackItalic";
103
+ // src: url(${SatoshiBlackItalicWOFF2}) format("woff2");
104
+ // font-weight: 900;
105
+ // font-display: swap;
106
+ // font-style: italic;
107
+ // }`;
108
+
109
+ // Fonts are inlined into JS bundle when we import them and they are added into DOM when we add them to this array.
110
+ // Use only fonts that you need.
111
+ // We don't want to increase the bundle size unnecessarily.
112
+ const enabledFonts = [SatoshiMedium];
113
+
114
+ export const fontDefinitions = enabledFonts.join("\n");
@@ -0,0 +1,4 @@
1
+ declare module "*.css";
2
+ declare module "*.ttf";
3
+ declare module "*.woff";
4
+ declare module "*.woff2";
@@ -1,9 +1,10 @@
1
- import { createRoot, Root } from "react-dom/client";
2
- import xswapConfig from "../../xswap.config";
3
- import { version } from "../../package.json";
4
1
  import { WaitingForInit } from "@src/components/WaitingForInit";
2
+ import { createRoot, Root } from "react-dom/client";
3
+ import CSS from "../components/global.css";
4
+ import { fontDefinitions } from "./fonts";
5
5
 
6
6
  export let xpayRoot: Root | null = null;
7
+ export let xpayShadowRoot: ShadowRoot | null = null;
7
8
  export let xpayInitIndicatorRoot: Root | null = null;
8
9
  export let xpayTxStatusRoot: Root | null = null;
9
10
 
@@ -17,11 +18,13 @@ export const initDocument = () => {
17
18
  }
18
19
  createXPayInitIndicatorRoot();
19
20
 
20
- Promise.all([
21
- createStyleElement(),
22
- createXPayRoot(),
23
- createXPayTxStatusRoot(),
24
- ]).then(() => {
21
+ setupFonts();
22
+
23
+ Promise.all([createXPayRoot(), createXPayTxStatusRoot()]).then((roots) => {
24
+ for (const root of roots) {
25
+ attachStyles(root);
26
+ }
27
+
25
28
  xPayInitCompleted = true;
26
29
  });
27
30
  };
@@ -36,47 +39,48 @@ export const waitForInitialization = async () => {
36
39
  }
37
40
  };
38
41
 
39
- const createStyleElement = async () => {
40
- if (isServer) {
42
+ const attachStyles = async (root: ShadowRoot) => {
43
+ const style = document.createElement("style");
44
+ style.appendChild(document.createTextNode(CSS));
45
+ root.appendChild(style);
46
+ };
47
+
48
+ /**
49
+ * To let Web Components use custom fonts, we need to define them on the page's document.
50
+ */
51
+ const setupFonts = () => {
52
+ const SELECTOR_KEY = "xpay-fonts";
53
+
54
+ if (document.querySelector(`style[data-name="${SELECTOR_KEY}"]`)) {
41
55
  return;
42
56
  }
43
- const css = await fetch(
44
- `${xswapConfig.apiUrl}/sdk/css?${new URLSearchParams({
45
- data: JSON.stringify({ version }),
46
- })}`,
47
- );
48
- const text = await css.text();
57
+
49
58
  const style = document.createElement("style");
50
- style.textContent = text;
51
- document.body.appendChild(style);
59
+ style.dataset.name = SELECTOR_KEY;
60
+
61
+ style.appendChild(document.createTextNode(fontDefinitions));
62
+ document.head.appendChild(style);
52
63
  };
53
64
 
54
65
  const createXPayRoot = async () => {
55
- if (isServer) {
56
- return;
57
- }
58
66
  const xswapElement = document.createElement("div");
67
+ xpayShadowRoot = xswapElement.attachShadow({ mode: "open" });
59
68
  xswapElement.setAttribute("id", "xpay-root");
60
- xswapElement.setAttribute("class", "xpay");
61
69
  document.body.appendChild(xswapElement);
62
- xpayRoot = createRoot(xswapElement);
70
+ xpayRoot = createRoot(xpayShadowRoot);
71
+ return xpayShadowRoot;
63
72
  };
64
73
 
65
74
  const createXPayTxStatusRoot = async () => {
66
- if (isServer) {
67
- return;
68
- }
69
75
  const txStatusElement = document.createElement("div");
76
+ const shadow = txStatusElement.attachShadow({ mode: "open" });
70
77
  txStatusElement.setAttribute("id", "xpay-tx-status");
71
- txStatusElement.setAttribute("class", "xpay-tx-status");
72
78
  document.body.appendChild(txStatusElement);
73
- xpayTxStatusRoot = createRoot(txStatusElement);
79
+ xpayTxStatusRoot = createRoot(shadow);
80
+ return shadow;
74
81
  };
75
82
 
76
83
  const createXPayInitIndicatorRoot = () => {
77
- if (isServer) {
78
- return;
79
- }
80
84
  const initIndicatorElement = document.createElement("div");
81
85
  initIndicatorElement.setAttribute("id", "xpay-init-indicator");
82
86
  document.body.appendChild(initIndicatorElement);
@@ -0,0 +1,52 @@
1
+ export const crosschainEstimationTimes = {
2
+ "1": {
3
+ "8453": 30 * 60 * 1000,
4
+ "42161": 30 * 60 * 1000,
5
+ "10": 30 * 60 * 1000,
6
+ "137": 30 * 60 * 1000,
7
+ "43114": 30 * 60 * 1000,
8
+ },
9
+ "8453": {
10
+ "42161": 30 * 60 * 1000,
11
+ "10": 30 * 60 * 1000,
12
+ "1": 30 * 60 * 1000,
13
+ "137": 30 * 60 * 1000,
14
+ "43114": 30 * 60 * 1000,
15
+ },
16
+ "42161": {
17
+ "8453": 30 * 60 * 1000,
18
+ "10": 30 * 60 * 1000,
19
+ "1": 30 * 60 * 1000,
20
+ "137": 30 * 60 * 1000,
21
+ "43114": 30 * 60 * 1000,
22
+ },
23
+ "10": {
24
+ "8453": 30 * 60 * 1000,
25
+ "42161": 30 * 60 * 1000,
26
+ "1": 30 * 60 * 1000,
27
+ "137": 30 * 60 * 1000,
28
+ "43114": 30 * 60 * 1000,
29
+ },
30
+ "137": {
31
+ "8453": 30 * 60 * 1000,
32
+ "42161": 30 * 60 * 1000,
33
+ "1": 30 * 60 * 1000,
34
+ "137": 30 * 60 * 1000,
35
+ "43114": 30 * 60 * 1000,
36
+ },
37
+ "43114": {
38
+ "8453": 30 * 60 * 1000,
39
+ "42161": 30 * 60 * 1000,
40
+ "1": 30 * 60 * 1000,
41
+ "137": 30 * 60 * 1000,
42
+ "43114": 30 * 60 * 1000,
43
+ },
44
+
45
+ // testnets
46
+ "43113": {
47
+ "80001": 30 * 60 * 1000,
48
+ },
49
+ "80001": {
50
+ "43113": 30 * 60 * 1000,
51
+ },
52
+ };
@@ -1,4 +1,5 @@
1
1
  import { Ecosystem } from "@src/models";
2
+ import { constants } from "ethers";
2
3
 
3
4
  export const DEFAULT_ECOSYSTEM = Ecosystem.EVM;
4
5
  export const NUMBER_INPUT_REGEX = /^[0-9]*[.,]?[0-9]*$/;
@@ -10,9 +11,14 @@ export const BALANCES_CHUNK_SIZE = 500;
10
11
  export const ROUTE_TIMEOUT_MS = 10000;
11
12
  export const MINIMUM_DISPLAYED_TOKEN_AMOUNT = 0.0001;
12
13
  export const DEFAULT_SOURCE_CHAIN_ID = "1";
14
+ export const DEFAULT_SOURCE_TOKEN_ADDR = constants.AddressZero;
13
15
  export const CCIP_EXPLORER = "https://ccip.chain.link/";
14
16
  export const TX_RECEIPT_STATUS_LIFETIME = 60000;
15
17
  export const DEFAULT_REQUEST_ABORT_MSG = "Request deprecated";
18
+ export const FALLBACK_CROSSCHAIN_ESTIMATION_TIME = 30 * 60 * 1000;
19
+ export const TOTAL_QUESTS_COUNT = 2;
20
+ export const XSWAP_STAKING_CHAIN_ID = "8453";
21
+ export const GAS_LIMIT_MULTIPLIER = 1.1;
16
22
 
17
23
  export const MSG_SENT_EVENT_SIG =
18
24
  "MessageSent(bytes32,uint64,address,bytes,address,uint256,uint256,address,uint256)";
@@ -26,3 +32,5 @@ export const MSG_RECEIVED_EVENT_SIG =
26
32
  export const MSG_RECEIVED_EVENT_ABI = [
27
33
  "event MessageReceived(bytes32 indexed messageId, uint64 indexed sourceChainSelector, address indexed sender, bytes data, address token, uint256 tokenAmount)",
28
34
  ];
35
+
36
+ export * from "./crosschainEstimationTimes";
@@ -0,0 +1,165 @@
1
+ import { ADDRESSES } from "@src/contracts";
2
+ import { TOTAL_QUESTS_COUNT, XSWAP_STAKING_CHAIN_ID } from "@src/constants";
3
+ import { useXPower } from "@src/hooks";
4
+ import {
5
+ Context,
6
+ Dispatch,
7
+ FC,
8
+ ReactNode,
9
+ SetStateAction,
10
+ createContext,
11
+ useCallback,
12
+ useContext,
13
+ useEffect,
14
+ useState,
15
+ } from "react";
16
+ import { useAccount } from "wagmi";
17
+ import { getFinishedLeaderboardQuests } from "@src/services";
18
+ import { getBalanceOf } from "@src/utils";
19
+ import { useSwapContext } from "@src/context/SwapProvider";
20
+ import { Ecosystem } from "@src/models";
21
+
22
+ export interface GlobalDataState {
23
+ rank: number;
24
+ setRank: Dispatch<SetStateAction<number>>;
25
+ xPower: string;
26
+ updateXPower: () => void;
27
+ xSwapBalance: string;
28
+ updateXSwapBalance: () => void;
29
+ unfinishedQuestsCount: number;
30
+ setUnfinishedQuestsCount: Dispatch<SetStateAction<number>>;
31
+ }
32
+
33
+ const initialValue: GlobalDataState = {
34
+ rank: 0,
35
+ setRank: () => {
36
+ throw new Error("GlobalDataState > setRank is not implemented");
37
+ },
38
+ xPower: "0",
39
+ updateXPower: () => {
40
+ throw new Error("GlobalDataState > updateXPower is not implemented");
41
+ },
42
+ xSwapBalance: "0",
43
+ updateXSwapBalance: () => {
44
+ throw new Error("GlobalDataState > updateXSwapBalance is not implemented");
45
+ },
46
+ unfinishedQuestsCount: 0,
47
+ setUnfinishedQuestsCount: () => {
48
+ throw new Error(
49
+ "GlobalDataState > setUnfinishedQuestsCount is not implemented",
50
+ );
51
+ },
52
+ };
53
+
54
+ const GlobalDataContext: Context<GlobalDataState> =
55
+ createContext<GlobalDataState>({
56
+ rank: initialValue.rank,
57
+ setRank: initialValue.setRank,
58
+ xPower: initialValue.xPower,
59
+ updateXPower: initialValue.updateXPower,
60
+ xSwapBalance: initialValue.xSwapBalance,
61
+ updateXSwapBalance: initialValue.updateXSwapBalance,
62
+ unfinishedQuestsCount: initialValue.unfinishedQuestsCount,
63
+ setUnfinishedQuestsCount: initialValue.setUnfinishedQuestsCount,
64
+ });
65
+
66
+ export const GlobalDataProvider: FC<{ children: ReactNode }> = ({
67
+ children,
68
+ }) => {
69
+ const { address } = useAccount();
70
+ const [unfinishedQuestsCount, setUnfinishedQuestsCount] = useState(
71
+ initialValue.unfinishedQuestsCount,
72
+ );
73
+ const [rank, setRank] = useState(initialValue.rank);
74
+ const [xPower, setXPower] = useState(initialValue.xPower);
75
+ const [xSwapBalance, setXSwapBalance] = useState(initialValue.xSwapBalance);
76
+ const { getXPower } = useXPower(XSWAP_STAKING_CHAIN_ID);
77
+
78
+ const { supportedChains } = useSwapContext();
79
+
80
+ const getFinishedQuests = useCallback(async () => {
81
+ if (!address) {
82
+ return;
83
+ }
84
+ const response = await getFinishedLeaderboardQuests({
85
+ walletAddress: address.toLowerCase(),
86
+ });
87
+
88
+ if (!response.ok) {
89
+ throw Error("Could not fetch quests statuses.");
90
+ }
91
+ const finishedQuestsResponse = await response.json();
92
+ if (finishedQuestsResponse.quests) {
93
+ const questsLeft = Math.max(
94
+ TOTAL_QUESTS_COUNT - (finishedQuestsResponse.quests.length || 0),
95
+ 0,
96
+ );
97
+ setUnfinishedQuestsCount(questsLeft);
98
+ }
99
+ }, [address]);
100
+
101
+ const fetchXPower = useCallback(async () => {
102
+ if (address) {
103
+ const response = await getXPower(address);
104
+ setXPower(response);
105
+ } else {
106
+ setXPower("0");
107
+ }
108
+ }, [getXPower, address]);
109
+
110
+ const fetchXSwapBalance = useCallback(async () => {
111
+ const rpcUrl = supportedChains.find(
112
+ (chain) =>
113
+ chain.ecosystem === Ecosystem.EVM &&
114
+ chain.chainId === XSWAP_STAKING_CHAIN_ID,
115
+ )?.publicRpcUrls[0];
116
+
117
+ if (
118
+ address &&
119
+ rpcUrl &&
120
+ ADDRESSES[XSWAP_STAKING_CHAIN_ID] &&
121
+ ADDRESSES[XSWAP_STAKING_CHAIN_ID].XSwapToken
122
+ ) {
123
+ const response = await getBalanceOf(
124
+ address,
125
+ ADDRESSES[XSWAP_STAKING_CHAIN_ID].XSwapToken,
126
+ rpcUrl,
127
+ );
128
+ setXSwapBalance(response);
129
+ } else {
130
+ setXSwapBalance("0");
131
+ }
132
+ }, []);
133
+
134
+ useEffect(() => {
135
+ getFinishedQuests();
136
+ }, [getFinishedQuests]);
137
+
138
+ useEffect(() => {
139
+ fetchXPower();
140
+ }, [fetchXPower]);
141
+
142
+ useEffect(() => {
143
+ fetchXSwapBalance();
144
+ }, [fetchXSwapBalance]);
145
+
146
+ return (
147
+ <GlobalDataContext.Provider
148
+ value={{
149
+ rank,
150
+ setRank,
151
+ xPower,
152
+ updateXPower: () => fetchXPower(),
153
+ xSwapBalance,
154
+ updateXSwapBalance: () => fetchXSwapBalance(),
155
+ unfinishedQuestsCount,
156
+ setUnfinishedQuestsCount,
157
+ }}
158
+ >
159
+ {children}
160
+ </GlobalDataContext.Provider>
161
+ );
162
+ };
163
+
164
+ export const useGlobalData = (): GlobalDataState =>
165
+ useContext(GlobalDataContext);