Beispiel #1
0
        private void ProcessDeepLink(bool isExternalBrowser, string url = "")
        {
            string linkUrl = url;

            #if UNITY_ANDROID
            //overriden linkUrl if deep link comes from external browser, due to limitations of Android plugins implementation
            if (isExternalBrowser)
            {
                linkUrl = CustomUrlSchemeAndroid.GetLaunchedUrl(true);
                CustomUrlSchemeAndroid.ClearSavedData();
            }
            #endif


            #if UNITY_IOS
            //there is no link override on iOS
            #endif


            if (!string.IsNullOrEmpty(linkUrl))
            {
                Debug.Log("Unity URL returned: " + linkUrl);

                Dictionary <string, string> urlParams = linkUrl.ParseURI();

                //blindcode as unable to test this without API update
                if (urlParams.ContainsKey("code"))
                {
                    //string code = split[1];
                    AuthorizationCodeReceived(urlParams["code"]);
                }
                else if (linkUrl.Contains("requestId="))
                {
                    string transferId = urlParams["requestId"];

                    foreach (TransferAPIRequest r in currentTransferAPIRequests)
                    {
                        Debug.Log("Current requests id: " + r.requestId);
                    }

                    //get request from ongoing
                    TransferAPIRequest transferRequest = currentTransferAPIRequests.Find(t => t.requestId == transferId);
                    if (transferRequest == null)
                    {
                        Debug.LogError("Transfer id is invalid: " + transferId);
                        transferRequest.failedDelegate("Invalid transfer id: " + transferId);
                    }

                    if (urlParams.ContainsKey("error"))
                    {
                        //all requests are validated positivelly currently
                        transferRequest.failedDelegate(urlParams["error"]);
                    }
                    else
                    {
                        transferRequest.txId = urlParams["txId"];
                        Debug.Log("tx id:" + transferRequest.txId);

                        transferRequest.successDelegate(transferRequest.txId);
                    }

                    currentTransferAPIRequests.Remove(transferRequest);
                }
                else
                {
                    Debug.Log("NOT IMPLEMENTED URL: " + linkUrl);
                }
            }
        }
Beispiel #2
0
        private IEnumerator AutoApproveTransfer(TransferAPIRequest request)
        {
            Debug.Log("AutoApproveTransfer");

            Dictionary <string, string> headers = new Dictionary <string, string>(AuthorizationHeader);

            headers.Add("Authorization", "Bearer " + QuartersInit.Instance.SERVER_API_TOKEN);


            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("clientId", QuartersInit.Instance.APP_ID);
            data.Add("userId", CurrentUser.userId);
            data.Add("address", CurrentUser.accounts[0].address);


            string dataJson = JsonConvert.SerializeObject(data);

            byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(dataJson);


            WWW www = new WWW(API_URL + "/requests/" + request.requestId + "/autoApprove", dataBytes, headers);

            Debug.Log(www.url);
            Debug.Log(dataJson);

            while (!www.isDone)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogError(www.error);
                Debug.Log(www.text);
                if (www.error.StartsWith("40"))
                {
                    //bad request check for reason
                    if (www.error.StartsWith("400") && !string.IsNullOrEmpty(www.text))
                    {
                        //bad request, possibly out of quarters
                        Dictionary <string, string> responseData = JsonConvert.DeserializeObject <Dictionary <string, string> >(www.text);
                        if (responseData.ContainsKey("message"))
                        {
                            request.failedDelegate(responseData["message"]);
                        }
                        else
                        {
                            StartCoroutine(CreateTransferRequestCall(request));
                        }
                    }
                    else
                    {
                        //fallback to normal transfer automatically
                        StartCoroutine(CreateTransferRequestCall(request));
                    }
                }
                else
                {
                    Debug.LogError(www.error);
                    request.failedDelegate(www.error);
                }
            }
            else
            {
                Debug.Log(www.text);

                string response = www.text;
                Debug.Log("Autoapprove response: " + response);

                Dictionary <string, string> responseData = JsonConvert.DeserializeObject <Dictionary <string, string> >(response);

                request.txId = responseData["txId"];

                Debug.Log("Autoapproved request txId is: " + request.txId);

                request.successDelegate(request.txId);
            }
        }