Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/missing action functions exports from clients #2778

Merged
merged 12 commits into from
Sep 3, 2024

Conversation

enesozturk
Copy link
Contributor

@enesozturk enesozturk commented Sep 1, 2024

Description

While migrating to the multi-chain architecture, there are few getter, action and listeners methods that the new modal instances don't expose but was available for the previous clients. This PR introduces changes with the required type definition tricks to have type safe method expose.

The reason we needed to use generics for AppKit and ChainAdapter types is that each client's following methods have different type of parameters and returns. When users use @web3modal/ethers or @web3modal/solana, the TS should know which type it'll take an return for these methods. For that to resolve, we need to use generics while exporting the backwards compatibility support.

getError
getChainId
getAddress
switchNetwork
getIsConnected
getWalletProvider
getWalletProviderType
subscribeProvider

This PR also introduces:

  • Few changes to example apps, adds new example app for Ethers to test those methods.
  • Fixing multi-address switching issue on Wagmi

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Associated Issues

For Linear issues: Closes APKT-xxx
For GH issues: closes #...

Showcase (Optional)

If there is a UI change include the screenshots with before and after state.
If new feature is being introduced, include the link to demo recording.

Checklist

  • Code in this PR is covered by automated tests (Unit tests, E2E tests)
  • My changes generate no new warnings
  • I have reviewed my own code
  • I have filled out all required sections

Copy link

vercel bot commented Sep 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
web3modal-gallery ✅ Ready (Inspect) Visit Preview Sep 3, 2024 9:44am
web3modal-laboratory ✅ Ready (Inspect) Visit Preview Sep 3, 2024 9:44am

Copy link
Contributor

github-actions bot commented Sep 1, 2024

Coverage Report for Coverage

Status Category Percentage Covered / Total
🔵 Lines 86.75% 3186 / 13445
🔵 Statements 86.75% 3186 / 13445
🔵 Functions 161.44% 236 / 723
🔵 Branches 215.06999999999996% 429 / 846
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/base/adapters/evm/ethers/client.ts 0% 0% 0% 0% 1, 15-19, 42, 47, 50, 52, 57, 104, 106, 108, 110, 116, 127, 129, 135, 137, 139, 142-143, 145-147, 149-156, 158-170, 172-186, 188-191, 193-198, 200-203, 205-210, 212-214, 217-220, 222, 224-225, 228-232, 234-239, 241-252, 254-257, 259-264, 266, 268, 270-276, 278-279, 282-286, 290, 292-317, 319-330, 332-335, 337-341, 343-344, 346-371, 373-376, 378-387, 389-390, 392, 394, 396-397, 399-401, 403-405, 407-412, 414-416, 418-419, 421-422, 424-426, 428-430, 432-439, 441-444, 446-447, 449-450, 452-454, 456-458, 460-462, 464-466, 468-470, 472-473, 475-481, 483-485, 487-488, 490-491, 493-497, 499-502, 504, 506-508, 510-511, 513-516, 518-521, 523-526, 528, 530-532, 534-536, 543-547, 549-554, 556-557, 560-563, 565, 567-569, 571-573, 575-578, 581-582, 584-588, 591-598, 600-603, 605-606, 608-609, 611-613, 615-619, 621-622, 624-626, 628-630, 632-634, 636-638, 640-642, 644-645, 647-649, 651-667, 670-673, 675-676, 678-681, 683-685, 687-698, 700, 702-703, 705-712, 714-720, 722-724, 726-734, 736-737, 739-754, 756-758, 760-764, 766-768, 770-772, 774-780, 782-784, 786-797, 799-809, 811-822, 824-838, 840-842, 844-860, 862-863, 865-881, 883-902, 904-905, 907-915, 917-918, 920-927, 929-942, 944-945, 947-953, 955-960, 962-966, 968-973, 975-976, 978-980, 982-985, 987-995, 997-1005, 1007-1012, 1014-1021, 1023-1036, 1038-1046, 1048-1053, 1055-1060, 1062-1065, 1067-1075, 1077-1082, 1084-1089, 1091-1110, 1112-1119, 1121-1122, 1124-1131, 1133-1139, 1141-1144, 1146-1150, 1152-1166, 1168-1176, 1178-1183, 1185-1186, 1188-1191, 1193-1196, 1198-1202, 1204-1210, 1212-1218, 1220-1221, 1223-1251, 1253-1265, 1267-1268, 1270-1275, 1277-1278, 1280-1287, 1289-1302, 1304-1307, 1309-1316, 1318-1322, 1324-1326, 1328-1332, 1334-1353, 1355-1365, 1367-1371, 1373-1374, 1376-1382, 1384-1403, 1405-1419, 1421-1427, 1429-1450, 1452-1470, 1472-1474, 1476-1489, 1491-1492, 1494-1505, 1507-1521, 1523-1533, 1535-1536, 1538-1540, 1542-1552, 1554-1564, 1566-1570, 1572-1584, 1586-1589, 1591-1595, 1597-1604
packages/base/adapters/evm/ethers5/client.ts 0% 0% 0% 0% 1, 14-17, 26, 31-32, 36, 41, 88, 90, 94, 96, 102, 104, 108, 118, 120, 122, 124-125, 127-129, 131-138, 140-152, 154-168, 170-173, 175-180, 182-185, 187-192, 194-196, 198, 200-201, 204-208, 210-215, 217-228, 230-233, 235-240, 242, 244, 246-252, 254-255, 258-262, 266, 268-293, 295-304, 306-309, 311-315, 317-318, 320-343, 345-348, 350-361, 363-364, 366-367, 369, 371-373, 375-377, 379-381, 383-390, 392-393, 395-396, 398-401, 403-406, 408-411, 413, 415-417, 419-421, 428-432, 434-439, 441-442, 444-446, 448-450, 452-454, 457-460, 462-463, 468-469, 471-475, 478-485, 487-490, 492-493, 495-496, 498-500, 502-504, 506-508, 510-512, 514-516, 518-520, 522-524, 526-529, 531-537, 540-543, 545-546, 548-554, 556-566, 568, 570-571, 573-581, 583-584, 586-601, 603-605, 607-611, 613-615, 617-619, 621-627, 629-631, 633-644, 646-656, 658-677, 679-680, 682-698, 700-702, 704-720, 722-741, 743-744, 746-754, 756-757, 759-766, 768-781, 783-784, 786-788, 790-793, 795-800, 802-806, 808-813, 815-816, 818-820, 822-825, 827-835, 837-845, 847-852, 854-856, 858-860, 862-865, 867-880, 882-890, 892-895, 897-899, 901-903, 905-908, 910-917, 919-924, 926-931, 933-952, 954-961, 963-964, 966-973, 975-981, 983-986, 988-992, 994-1008, 1010-1018, 1020-1023, 1025, 1027-1028, 1030, 1032-1033, 1035-1039, 1041-1047, 1049-1055, 1057-1058, 1060-1087, 1089-1101, 1103-1104, 1106-1111, 1113-1114, 1116-1123, 1125-1136, 1138-1141, 1143-1155, 1157-1159, 1161-1165, 1167-1172, 1174-1187, 1189-1193, 1195-1196, 1198-1204, 1206-1225, 1227-1241, 1243-1249, 1251-1272, 1274-1292, 1294-1296, 1298-1311, 1313-1314, 1316-1327, 1329-1343, 1345-1355, 1357-1358, 1360-1362, 1364-1374, 1376-1386, 1388-1392, 1394-1406, 1408-1411, 1413-1417, 1419-1426, 1428-1434, 1436-1438, 1440-1447
packages/base/adapters/evm/ethers5/utils/defaultConfig.ts 0% 0% 0% 0% 1, 3, 26-47, 49, 51, 53, 55-58, 60-62, 64-66, 69, 71-72, 74-77, 79-81, 83-87, 89, 98-99, 101-102, 104-106, 108-110, 112-114, 116-119, 121, 123-124
packages/base/adapters/evm/wagmi/client.ts 0% 0% 0% 0% 1-2, 21, 23-24, 38, 40-41, 47-48, 50-51, 54, 70, 72, 77, 79, 85, 87, 89, 91, 93-94, 96-98, 100-102, 104-106, 108-111, 113-116, 118-123, 125-126, 128-130, 132-134, 136-138, 140-142, 144, 148-150, 152-155, 157-158, 160-166, 169, 172-175, 177-182, 184-195, 197-206, 208, 210, 212-215, 221-224, 226-227, 229-231, 233, 235, 237-238, 240, 242-243, 245-246, 248-250, 252-253, 255-258, 260-262, 264-267, 269-270, 272-273, 275-282, 284-286, 288-289, 291-302, 304-305, 307-316, 318-319, 321, 323-324, 326-329, 331-338, 340-341, 343-347, 349-351, 353-358, 360-364, 366-367, 369-371, 373-376, 378-379, 381, 383-385, 387-390, 392-394, 396-398, 400-405, 407-427, 430-437, 440-452, 454-460, 471-472, 474-489, 492-506, 508-509, 511-530, 532-535, 537-540, 542-557, 559-564, 566-590, 592-600, 602-605, 607-610, 612-613, 616-636, 638-642, 644, 646, 648-666, 668-671, 678-692, 694-702, 704-710, 712, 714-716, 718-735, 737-745, 747-748, 750-757, 759-765, 767-773, 775-792, 794-796, 798-811, 813-823
packages/base/adapters/solana/web3js/client.ts 0% 0% 0% 0% 1, 9-11, 13, 16-17, 36-38, 44-45, 49, 66-67, 69, 71, 73, 77, 85, 89, 91-92, 94-96, 98, 100, 102, 104-113, 115-119, 121-125, 127-132, 134-138, 140-142, 144, 146-147, 149-152, 154-156, 158-159, 161-163, 165-169, 171, 173-174, 176, 183, 185, 187, 189, 191, 193-195, 197-198, 200, 202-204, 206, 208, 210, 212-214, 216-221, 223, 225-228, 230-231, 233-237, 239-241, 243-245, 247-249, 251-253, 255-256, 258-260, 262-268, 270-283, 285-287, 289-291, 293-295, 297-299, 301-303, 306-308, 310-325, 327-329, 331-335, 337-343, 345-348, 350-352, 354-356, 358-363, 365-380, 382-383, 385-387, 389-392, 394-396, 398-401, 403-406, 408-413, 415-421, 423-436, 438-440, 442-445, 448-450, 452-455, 457-462, 464, 466, 468-473, 475, 483-486, 488-504, 506-513, 516-519, 521-526, 529-532, 534-541, 543-545, 547-553, 555-563, 565-571, 573-576, 578-579, 581-589, 591-594, 596-612, 614-616, 618-619, 621-623, 625-628, 630-631, 633-642, 644-646
packages/base/src/client.ts 0% 0% 0% 0% 1, 28-30, 39, 42, 49, 51-52, 55, 57-60, 62-64, 67-70, 72-75, 77-79, 82-84, 86-88, 90-92, 94-96, 98-100, 102-104, 106-108, 110-112, 114-116, 118-120, 122-125, 127-130, 132-134, 136-138, 140-142, 144-146, 148-150, 152-154, 156-158, 160-162, 164-166, 168-170, 172-174, 176-178, 180-182, 184-186, 188-190, 192-194, 196-200, 202-204, 206, 208-211, 213-219, 221-226, 228, 230-232, 234-236, 238-240, 242-244, 246-248, 250-252, 254, 256-261, 263-264, 266-267, 269-271, 273-275, 277-279, 281-282, 284-286, 288-289, 291-296, 298-303, 305-310, 312-315, 317-322, 324-325, 327-330, 332-333, 335-337, 339-341, 343-344, 347-348, 351-354, 356, 358, 361-363, 365-375, 377-379, 381-383, 385-387, 389-391, 393, 396-402, 404-415, 417-419
packages/base/utils/TypesUtil.ts 100% 100% 100% 100%
packages/base/utils/library/react/index.ts 0% 0% 0% 0% 1, 32, 34-37, 39-41, 43-46, 48-52, 54-58, 60-61, 63-67, 69-72, 74-80, 82-85, 87-89, 91-93, 95-96, 98-101, 103-107, 109-110, 112-115, 117, 119-122, 124-127, 129-130, 132-135, 137, 139-142, 144-147, 149-150
packages/base/utils/library/vue/index.ts 0% 0% 0% 0% 1, 31, 33-36, 38-40, 42-45, 47-51, 53-57, 59-60, 62-65, 67-69, 71-77, 79-82, 84-86, 88-90, 92-96, 98-101, 103, 105-107, 109-111, 113-114, 116-119, 121-123, 125-128, 130-132, 134-135, 142-145, 147-151, 153-155, 157-158
packages/core/src/utils/TypeUtil.ts 100% 100% 100% 100%
Generated in workflow #5918

Copy link
Contributor

github-actions bot commented Sep 1, 2024

♻️ Vite-Size ♻️

Size Difference

Size (kb) Gzip (kb)
Total Diff. 🔺+0.269 🔺+0.062

Current Size

Name Size (kb) Gzip (kb)
assets/index-COxaHU3e.js 1474.036 417.357
assets/noble-curves.js 31.941 12.779
assets/2.19.6_bufferutil.js 2.789 1.324
assets/index.js 161.83 59.283
assets/index2.js 102.249 29.112
assets/index3.js 304.389 87.279
assets/walletconnect-ethereum-provider.js 278.197 80.094
assets/index4.js 11.601 3.212
assets/w3m-modal.js 6.992 2.508
assets/index5.js 12.674 4.695
assets/hooks.module.js 74.776 25.684
assets/walletconnect-modal-ui.js 112.43 34.327
index.html 0.329 0.237
Total Size 2574.233 757.891

Base Size

Name Size (kb) Gzip (kb)
assets/index-CQriLDjg.js 1473.767 417.291
assets/noble-curves.js 31.941 12.78
assets/2.19.6_bufferutil.js 2.789 1.324
assets/index.js 161.83 59.283
assets/index2.js 102.249 29.113
assets/index3.js 304.389 87.28
assets/walletconnect-ethereum-provider.js 278.197 80.094
assets/index4.js 11.601 3.212
assets/w3m-modal.js 6.992 2.508
assets/index5.js 12.674 4.695
assets/hooks.module.js 74.776 25.685
assets/walletconnect-modal-ui.js 112.43 34.328
index.html 0.329 0.236
Total Size 2573.964 757.829

@@ -303,7 +344,11 @@ export class AppKit {
AssetUtil.getConnectorImage(connector)

// -- Private ------------------------------------------------------------------
private async initControllers(options: AppKitOptions) {
private async initControllers(
options: AppKitOptions & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove adapters from type and add it manually here?

Copy link
Contributor Author

@enesozturk enesozturk Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • In v5, we have only backwards compatible versions and they are working with single adapter on background. Every client is creating adapter instance and pass it to the adapters array like this:
export function createWeb3Modal(options: EthersAppKitOptions) {
  const ethersAdapter = new EVMEthersClient({
    ethersConfig: options.ethersConfig,
    siweConfig: options.siweConfig,
    chains: options.chains,
    defaultChain: options.defaultChain
  })

  return new AppKit<EthersStoreUtilState, number>({
    ...options,
    defaultChain: ethersAdapter.defaultChain,
    adapters: [ethersAdapter],
    sdkType: 'w3m',
    sdkVersion: `html-ethers-${ConstantsUtil.VERSION}`
  })
}

But each adapter have type differences for the exposed functions, for example, getWalletProvider returns different typed value for each adapter:

public getWalletProvider() {
   return this.adapter?.getWalletProvider?.()
 }

To resolve this problem, we are now using generics and passing the type values for some unknown types by base, with the generics, base package know what are the types of these function returns.

So for the question:

Why remove adapters from type and add it manually here?
base should get the types of the adapter (yes it's array but it's actually using single adapter) instead of just ChainAdapter type. I went with this solution to resolve this problem for having fully type safed exposed functions.

@tomiir

@enesozturk enesozturk merged commit a499760 into main Sep 3, 2024
14 checks passed
@enesozturk enesozturk deleted the fix/missing-action-functions-exports-from-clients branch September 3, 2024 10:48
@0xBURP
Copy link

0xBURP commented Sep 10, 2024

but AppKit.subscribeProvider is still unavailable in @web3modal/ethers 5.1.7?
I might have had some pnpm issue, nuking node_modules did the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants