Skip to content

Commit 5d9cd9a

Browse files
committed
added samples for solana and polkadot
1 parent 2016ab4 commit 5d9cd9a

15 files changed

Lines changed: 353 additions & 190 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.1.16
2+
3+
- Updated dependencies
4+
- Support for Solana and Polkadot in sample dapp
5+
16
## 2.1.15
27

38
- Updated dependencies

example/sign/lib/models/chain_metadata.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ enum ChainType {
55
eip155,
66
solana,
77
kadena,
8+
polkadot,
89
}
910

1011
class ChainMetadata {

example/sign/lib/pages/wcm_page.dart

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
44
import 'package:walletconnect_flutter_dapp/models/chain_metadata.dart';
55
import 'package:walletconnect_flutter_dapp/utils/constants.dart';
66
import 'package:walletconnect_flutter_dapp/utils/crypto/chain_data.dart';
7-
import 'package:walletconnect_flutter_dapp/utils/crypto/helpers.dart';
87
import 'package:walletconnect_flutter_dapp/utils/string_constants.dart';
98
import 'package:walletconnect_flutter_dapp/widgets/chain_button.dart';
109
import 'package:walletconnect_flutter_dapp/widgets/session_widget.dart';
@@ -185,7 +184,11 @@ class _WCMPageState extends State<WCMPage> with SingleTickerProviderStateMixin {
185184
session: session,
186185
web3App: widget.web3App,
187186
launchRedirect: () {
188-
_walletConnectModalService!.launchCurrentWallet();
187+
final redirect = _walletConnectModalService
188+
?.session?.peer.metadata.redirect;
189+
if (redirect != null) {
190+
_walletConnectModalService!.launchCurrentWallet();
191+
}
189192
},
190193
),
191194
),
@@ -212,56 +215,70 @@ class _WCMPageState extends State<WCMPage> with SingleTickerProviderStateMixin {
212215
_selectedChains.add(chain);
213216
}
214217
});
215-
_updateRequiredNamespaces();
218+
_updateNamespaces();
216219
}
217220

218-
void _updateRequiredNamespaces() {
221+
void _updateNamespaces() {
219222
final Map<String, RequiredNamespace> requiredNamespaces = {};
220-
if (_firstChain != null) {
221-
requiredNamespaces[_firstChain!.type.name] = RequiredNamespace(
222-
chains: [_firstChain!.namespace],
223-
methods: getChainMethods(_firstChain!.type),
224-
events: getChainEvents(_firstChain!.type),
225-
);
223+
for (var chainData in _selectedChains) {
224+
for (var key in chainData.requiredNamespaces.keys) {
225+
final chains = chainData.requiredNamespaces[key]!.chains ?? [];
226+
final methods = chainData.requiredNamespaces[key]!.methods;
227+
final events = chainData.requiredNamespaces[key]!.events;
228+
229+
// Adds every requiredNamespaces from every selected chain
230+
231+
requiredNamespaces[key] = RequiredNamespace(
232+
chains: <String>{
233+
...(requiredNamespaces[key]?.chains ?? []),
234+
...chains
235+
}.toList(),
236+
methods: <String>{
237+
...(requiredNamespaces[key]?.methods ?? []),
238+
...methods
239+
}.toList(),
240+
events: <String>{
241+
...(requiredNamespaces[key]?.events ?? []),
242+
...events
243+
}.toList(),
244+
);
245+
}
226246
}
227-
final Map<String, RequiredNamespace> optionalNamespaces =
228-
_getOtionalNamespaces();
229247

230248
_walletConnectModalService?.setRequiredNamespaces(
231249
requiredNamespaces: requiredNamespaces,
232250
);
233-
_walletConnectModalService?.setOptionalNamespaces(
234-
optionalNamespaces: optionalNamespaces,
235-
);
236-
237-
LoggerUtil.logger.i(
238-
'_updateRequiredNamespaces, requiredNamespaces: $requiredNamespaces, optionalNamespaces: $optionalNamespaces',
239-
);
240-
}
241-
242-
Map<String, RequiredNamespace> _getOtionalNamespaces() {
243-
final Map<String, RequiredNamespace> requiredNamespaces = {};
244-
final Map<ChainType, Set<String>> chains = {};
245-
246-
// Construct our list of chains for each type of blockchain
247-
for (final chain in _selectedChains) {
248-
if (!chains.containsKey(chain.type)) {
249-
chains[chain.type] = {};
251+
debugPrint('WCM Page, requiredNamespaces: $requiredNamespaces');
252+
253+
final Map<String, RequiredNamespace> optionalNamespaces = {};
254+
for (var chainData in _selectedChains) {
255+
for (var key in chainData.optionalNamespaces.keys) {
256+
final chains = chainData.optionalNamespaces[key]!.chains ?? [];
257+
final methods = chainData.optionalNamespaces[key]!.methods;
258+
final events = chainData.optionalNamespaces[key]!.events;
259+
260+
// Adds every optionalNamespaces from every selected chain
261+
262+
optionalNamespaces[key] = RequiredNamespace(
263+
chains: <String>{
264+
...(optionalNamespaces[key]?.chains ?? []),
265+
...chains
266+
}.toList(),
267+
methods: <String>{
268+
...(optionalNamespaces[key]?.methods ?? []),
269+
...methods
270+
}.toList(),
271+
events: <String>{
272+
...(optionalNamespaces[key]?.events ?? []),
273+
...events
274+
}.toList(),
275+
);
250276
}
251-
chains[chain.type]!.add(chain.namespace);
252-
}
253-
254-
for (final entry in chains.entries) {
255-
// Create the required namespaces
256-
requiredNamespaces[entry.key.name] = RequiredNamespace(
257-
chains: entry.value.toList(),
258-
methods: getOptionalChainMethods(entry.key),
259-
events: getChainEvents(entry.key),
260-
);
261277
}
262278

263-
LoggerUtil.logger
264-
.i('WCM Page, _getRequiredNamespaces: $requiredNamespaces');
265-
return requiredNamespaces;
279+
_walletConnectModalService?.setOptionalNamespaces(
280+
optionalNamespaces: optionalNamespaces,
281+
);
282+
debugPrint('WCM Page, optionalNamespaces: $optionalNamespaces');
266283
}
267284
}

0 commit comments

Comments
 (0)