getNonce method

Future<DeepLinkParamSignin> getNonce(
  1. DeepLinkParamSignin deepLinkParam
)

Implementation

Future<DeepLinkParamSignin> getNonce(
    DeepLinkParamSignin deepLinkParam) async {
  final http.Response response = await http.post(
    Uri.parse(deepLinkParam.nonceEndpoint),
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(<String, String>{
      'token': deepLinkParam.token,
      'address': deepLinkParam.address,
    }),
  );
  if (response.statusCode == 200) {
    NonceEndpointResponse nonceEndpointResponse =
        NonceEndpointResponse.fromJson(json.decode(response.body));
    if (nonceEndpointResponse.success &&
        nonceEndpointResponse.data.nonce.startsWith('signin-')) {
      deepLinkParam.nonce = nonceEndpointResponse.data.nonce;
      return deepLinkParam;
    } else {
      return null;
    }
  } else {
    return null;
  }
}