Skip to content

Commit

Permalink
fix: apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
shiki-tak committed Jul 18, 2024
1 parent ef5ffbf commit c319bfb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 41 deletions.
18 changes: 10 additions & 8 deletions flutter_bird_app/lib/controller/authentication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import 'package:http/http.dart' as http;
import 'package:nonce/nonce.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

import '../model/account.dart';
import '../model/wallet_provider.dart';

/// Manages the authentication process and communication with crypto wallets
abstract class AuthenticationService {
Future<void> initialize(bool isInLiff);

Expand Down Expand Up @@ -41,7 +43,7 @@ class AuthenticationServiceImpl implements AuthenticationService {
final Function() onAuthStatusChanged;
WalletProvider? _lastUsedWallet;

static const String projectId = String.fromEnvironment('WALLET_CONNECT_PROJECT_ID');
String projectId = dotenv.env['WALLET_CONNECT_PROJECT_ID'] ?? '';

AuthenticationServiceImpl({
required this.isInLiff,
Expand Down Expand Up @@ -69,9 +71,9 @@ class AuthenticationServiceImpl implements AuthenticationService {
@override
bool get isAuthenticated => isConnected && authenticatedAccount != null;

// The data to display in a QR Code for connections on Desktop / Browser.
@override
String? get webQrData => _webQrData;
String? _webQrData;
String? webQrData;

WalletProvider? get lastUsedWallet => _lastUsedWallet;

Expand Down Expand Up @@ -153,7 +155,7 @@ class AuthenticationServiceImpl implements AuthenticationService {
if (uri != null) {
// Web
if (kIsWeb && !isInLiff) {
_webQrData = uri.toString();
webQrData = uri.toString();
onAuthStatusChanged();
// LIFF
} else if(kIsWeb && isInLiff) {
Expand Down Expand Up @@ -246,7 +248,7 @@ class AuthenticationServiceImpl implements AuthenticationService {
}
_authenticatedAccount = null;
_connector = null;
_webQrData = null;
webQrData = null;
}

Future<void> _createConnector({WalletProvider? walletProvider}) async {
Expand All @@ -267,20 +269,20 @@ class AuthenticationServiceImpl implements AuthenticationService {
if (!isInLiff) {
log('connected: ' + session.toString(), name: 'AuthenticationService');
String? address = session?.session.namespaces['eip155']?.accounts.first.split(':').last;
_webQrData = null;
webQrData = null;
final authenticated = await _verifySignature(walletProvider: walletProvider, address: address);
if (authenticated) log('authenticated successfully: ' + session.toString(), name: 'AuthenticationService');
onAuthStatusChanged();
}
});
_connector?.onSessionUpdate.subscribe((SessionUpdate? payload) async {
log('session_update: ' + payload.toString(), name: 'AuthenticationService');
_webQrData = null;
webQrData = null;
onAuthStatusChanged();
});
_connector?.onSessionDelete.subscribe((SessionDelete? session) {
log('disconnect: ' + session.toString(), name: 'AuthenticationService');
_webQrData = null;
webQrData = null;
_authenticatedAccount = null;
onAuthStatusChanged();
});
Expand Down
7 changes: 1 addition & 6 deletions flutter_bird_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import 'package:flutter_line_liff/flutter_line_liff.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (const String.fromEnvironment('FLUTTER_ENV') != 'production') {
await dotenv.load(fileName: ".env");
}
await dotenv.load(fileName: ".env");

print("Starting application...");
const String liffId = String.fromEnvironment('LIFF_ID');

final String? os = FlutterLineLiff().os;
final bool isInClient = FlutterLineLiff().isInClient;
runApp(MyApp(isInClient: isInClient));
}
Expand Down
54 changes: 27 additions & 27 deletions flutter_bird_app/lib/view/main_menu_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,35 @@ class _MainMenuViewState extends State<MainMenuView> with AutomaticKeepAliveClie
birdSize = worldDimensions.height / 8;

try {
return Scaffold(
body: Consumer<FlutterBirdController>(builder: (context, web3Service, child) {
web3Service.authorizeUser();
if (web3Service.skins != null) {
birds = [
const Bird(),
...web3Service.skins!.map((e) => Bird(
skin: e,
))
];
if (web3Service.skins!.length < selectedBird) {
selectedBird = web3Service.skins!.length;
return Scaffold(
body: Consumer<FlutterBirdController>(builder: (context, web3Service, child) {
web3Service.authorizeUser();
if (web3Service.skins != null) {
birds = [
const Bird(),
...web3Service.skins!.map((e) => Bird(
skin: e,
))
];
if (web3Service.skins!.length < selectedBird) {
selectedBird = web3Service.skins!.length;
}
} else {
selectedBird = 0;
}
} else {
selectedBird = 0;
}

return Center(
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth),
child: Stack(alignment: Alignment.center, children: [
const Background(),
_buildBirdSelector(web3Service),
_buildMenu(web3Service),
]),
),
);
}),
);
return Center(
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth),
child: Stack(alignment: Alignment.center, children: [
const Background(),
_buildBirdSelector(web3Service),
_buildMenu(web3Service),
]),
),
);
}),
);
} catch(e, stackTrace) {
print("Error in MainMenuView: $e");
print("StackTrace: $stackTrace");
Expand Down

0 comments on commit c319bfb

Please sign in to comment.