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

Issue with Subscription with Phoenix #87

Closed
redDwarf03 opened this issue May 17, 2022 · 1 comment
Closed

Issue with Subscription with Phoenix #87

redDwarf03 opened this issue May 17, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@redDwarf03
Copy link
Member

redDwarf03 commented May 17, 2022

What happened?

When I click on the button confirm, a method _doSend is called.
This method call a HTTP POST request (the method sends a transaction to a blockchain and waits the result). HTTP POST response contains the status of the response (“pending”) and we get the “ok” status with the Subscription with Phoenix.
So when I receive “ok”, I want to display the nb of confirmations from my subscription.

 final subscriptionDocument = gql(
      """subscription { transactionConfirmed(address: "00005b97bd47bb11af2e17732fe355c18731d30035066b43d4788c189014f6807090") { nbConfirmations } }""");

With the following code, i obtain:

logs from HTTP request and response:

[log] sendTx: requestHttp.body={"version":1,"address":"0…c62d75a51d8c53187fc1f3f50ed885666c60b17941a3f0e"}
[log] sendTx: responseHttp.body={"status":"pending","tra…1794E1A1D69C4184B3D3D58C823E778549F139361F1C0ED"}

logs from network

Screenshot 2022-05-17 at 23 36 23

The status is ok => ok

But i should obtain normally

Screenshot 2022-05-18 at 10 10 37

BUT I don't find how to get the nb of confirmations from subscription .... with __absinthe__doc

My Code:

/// SPDX-License-Identifier: AGPL-3.0-or-later

// Dart imports:
import 'dart:async';

// Flutter imports:
import 'package:aewallet/ui/views/transactions/phoenix_link.dart';
import 'package:flutter/material.dart';

// Package imports:
import 'package:aeuniverse/ui/widgets/components/buttons.dart';
import 'package:core/localization.dart';
import 'package:core/service/app_service.dart';
import 'package:core/util/get_it_instance.dart';
import 'package:core_ui/ui/util/dimens.dart';

// Project imports:
import 'package:graphql_flutter/graphql_flutter.dart';

class TransferConfirmSheet extends StatefulWidget {
  const TransferConfirmSheet({super.key});

  @override
  State<TransferConfirmSheet> createState() => _TransferConfirmSheetState();
}

class _TransferConfirmSheetState extends State<TransferConfirmSheet> {
  PhoenixLink? link;
  ValueNotifier<GraphQLClient>? client;

  // your subscription query
  final subscriptionDocument = gql(
      """subscription { transactionConfirmed(address: "0000D2690135438EF7842075DCEB62E42F46614B6E3478FCE01A943EC7E699AC74C3") { nbConfirmations } }""");

  Future<void> initGraphQLChannel() async {
    // my absinthe plug api location
    final HttpLink phoenixHttpLink = HttpLink(
      'http://localhost:4000/socket/websocket',
    );

    // my websocket location
    String websocketUri = "ws://localhost:4000/socket/websocket";

    // creation of phoenixChannel for use in PhoenixLink
    final phoenixChannel =
        await PhoenixLink.createChannel(websocketUri: websocketUri);

    final phoenixLink = PhoenixLink(
      channel: phoenixChannel,
    );
    var _link = Link.split(
        (request) => request.isSubscription, phoenixLink, phoenixHttpLink);

    client = ValueNotifier(
      GraphQLClient(
        link: _link,
        cache: GraphQLCache(),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      minimum:
          EdgeInsets.only(bottom: MediaQuery.of(context).size.height * 0.035),
      child: Column(
        children: <Widget>[
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                client == null
                    ? const SizedBox()
                    : Center(
                        child: GraphQLProvider(
                          client: client,
                          child: Subscription(
                              options: SubscriptionOptions(
                                document: subscriptionDocument,
                              ),
                              builder: (result) {
                                if (result.hasException) {
                                  return Text(result.exception.toString());
                                }
                                if (result.isLoading) {
                                  return const Center(
                                    child: CircularProgressIndicator(),
                                  );
                                }
                                return ResultAccumulator.appendUniqueEntries(
                                    latest: result.data,
                                    builder: (context, {results}) =>
                                        Text(result.data.toString()));
                              }),
                        ),
                      ),
              ],
            ),
          ),
          Container(
            margin: const EdgeInsets.only(top: 10.0),
            child: Column(
              children: <Widget>[
                Row(
                  children: <Widget>[
                    AppButton.buildAppButton(
                      const Key('confirm'),
                      context,
                      AppButtonType.primary,
                      AppLocalization.of(context)!.confirm,
                      Dimens.buttonTopDimens,
                      onPressed: () async {
                        _doSend();
                      },
                    ),
                  ],
                ),
                Row(
                  children: <Widget>[
                    AppButton.buildAppButton(
                        const Key('cancel'),
                        context,
                        AppButtonType.primary,
                        AppLocalization.of(context)!.cancel,
                        Dimens.buttonBottomDimens, onPressed: () {
                      Navigator.of(context).pop();
                    }),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Future<void> _doSend() async {
    await initGraphQLChannel();
    await sl.get<AppService>().send();
  }
}

What is expected ?

get the result from Subscription

@redDwarf03 redDwarf03 added the bug Something isn't working label May 17, 2022
@redDwarf03 redDwarf03 self-assigned this May 17, 2022
@redDwarf03
Copy link
Member Author

problem has been found.. i use phoenix socket and i fix the address in suscription

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant