-
Notifications
You must be signed in to change notification settings - Fork 1
/
ramp_flutter.dart
72 lines (61 loc) · 2.25 KB
/
ramp_flutter.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:ramp_flutter/offramp_sale.dart';
import 'package:ramp_flutter/onramp_purchase.dart';
import 'package:ramp_flutter/send_crypto_payload.dart';
import 'configuration.dart';
/// Wrapper class for Ramp Network Flutter widget
class RampFlutter {
final MethodChannel _channel = const MethodChannel('ramp_flutter');
Function(OnrampPurchase, String, String)? onOnrampPurchaseCreated;
Function(SendCryptoPayload payload)? onSendCryptoRequested;
Function(OfframpSale, String, String)? onOfframpSaleCreated;
Function()? onRampClosed;
void _handleOnOnrampPurchaseCreated(dynamic arguments) {
dynamic payload = arguments[0];
String purchaseViewToken = arguments[1];
String apiUrl = arguments[2];
OnrampPurchase purchase = OnrampPurchase.fromArguments(payload);
onOnrampPurchaseCreated!(purchase, purchaseViewToken, apiUrl);
}
void _handleOnSendCryptoRequested(dynamic arguments) {
dynamic payload = arguments[0];
SendCryptoPayload sendCrypto = SendCryptoPayload.fromArguments(payload);
onSendCryptoRequested!(sendCrypto);
}
void _handleOnOfframpSaleCreated(dynamic arguments) {
dynamic payload = arguments[0];
String saleViewToken = arguments[1];
String apiUrl = arguments[2];
OfframpSale sale = OfframpSale.fromArguments(payload);
onOfframpSaleCreated!(sale, saleViewToken, apiUrl);
}
void _handleOnRampClosed() {
onRampClosed!();
}
Future<void> _didRecieveMethodCall(MethodCall call) async {
switch (call.method) {
case "onOnrampPurchaseCreated":
_handleOnOnrampPurchaseCreated(call.arguments);
break;
case "onSendCryptoRequested":
_handleOnSendCryptoRequested(call.arguments);
break;
case "onOfframpSaleCreated":
_handleOnOfframpSaleCreated(call.arguments);
break;
case "onRampClosed":
_handleOnRampClosed();
break;
}
}
Future<void> showRamp(
Configuration configuration,
) async {
_channel.setMethodCallHandler(_didRecieveMethodCall);
await _channel.invokeMethod('showRamp', configuration.toMap());
}
Future<void> sendCrypto(String? transactionHash) async {
await _channel.invokeMethod('sendCrypto', transactionHash);
}
}