@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
44import 'package:walletconnect_flutter_dapp/models/chain_metadata.dart' ;
55import 'package:walletconnect_flutter_dapp/utils/constants.dart' ;
66import 'package:walletconnect_flutter_dapp/utils/crypto/chain_data.dart' ;
7- import 'package:walletconnect_flutter_dapp/utils/crypto/helpers.dart' ;
87import 'package:walletconnect_flutter_dapp/utils/string_constants.dart' ;
98import 'package:walletconnect_flutter_dapp/widgets/chain_button.dart' ;
109import '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