Ejemplo n.º 1
0
    IEnumerator ShowLoadDialogCoroutine()
    {
        // Show a load file dialog and wait for a response from user
        // Load file/folder: file, Initial path: default (Documents), Title: "Load File", submit button text: "Load"
        yield return(FileBrowser.WaitForLoadDialog(false, null, "Load File", "Load"));

        // Dialog is closed
        // Print whether a file is chosen (FileBrowser.Success)
        // and the path to the selected file (FileBrowser.Result) (null, if FileBrowser.Success is false)
        Debug.Log(FileBrowser.Success + " " + FileBrowser.Result);

        if (FileBrowser.Success)
        {
            ModalDialog.Instance.Show("Processing File",
                                      "Please wait while your file is encoded into a txn and broadcast");
            try
            {
                BitIndexUtils.QueryUtxos(Authenticator.Instance.Identity.Address, utxos =>
                {
                    var utxo = utxos.First();
                    Debug.Log(JsonConvert.SerializeObject(utxo));

                    UtxoUtils.BuildTxnFromUtxo(
                        Authenticator.Instance.Identity.PrivateKey,
                        utxo.ToUTXO(),
                        OpReturns.MakeBlob(Encoding.UTF8.GetBytes(FileBrowser.Result)))
                    .Spend(txn =>
                    {
                        var value = $"https://bico.media/{txn}";
                        Debug.Log(value);
                        ModalDialog.Instance.Hide();
                        ModalDialog.Instance.Show("File successfully uploaded",
                                                  $"Check it out at: {value}", "View Online", "Ok");
                        ModalDialog.Instance.CallbackYes.RemoveAllListeners();
                        ModalDialog.Instance.CallbackYes.AddListener(() =>
                        {
                            Application.OpenURL(value);
                        });

                        InputField.text = value;
                    });
                });
            }
            catch (Exception e)
            {
                ModalDialog.Instance.Hide();
                ModalDialog.Instance.Show($"Something went wrong, try again later",
                                          $"{e.GetType()}: {e.Message}", "Ok");
            }
        }
        else
        {
            ModalDialog.Instance.Show("File Browser Error", "Could not pinpoint file to upload", "Ok");
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        var pix = Texture2D.GetPixels32();

        var tex = new Texture2D(Texture2D.width, Texture2D.height);

        tex.SetPixels32(pix);
        tex.Apply();

        // TODO: Refactor this after getting some sleep
        var       width   = 0;
        var       height  = 0;
        const int maxSize = 1024;

        if (tex.width > tex.height)
        {
            if (tex.width > maxSize)
            {
                width  = maxSize;
                height = (tex.height * maxSize) / tex.width;
            }
        }
        else
        {
            if (tex.height > maxSize)
            {
                height = maxSize;
                width  = (tex.width * maxSize) / tex.height;
            }
        }

        TextureScale.Point(tex, width, height);

        Debug.Log($"Texture is {tex.width}x{tex.height}");

        var buffer = tex.EncodeToJPG();

        Debug.Log(buffer.Length);

        BitIndexUtils.QueryUtxos(Identity.Address, utxos =>
        {
            var utxo = utxos.First();
            Debug.Log(JsonConvert.SerializeObject(utxo));

            UtxoUtils.BuildTxnFromUtxo(
                Identity.PrivateKey,
                utxo.ToUTXO(),
                OpReturns.MakeImg(buffer))
            .Spend(txn => { Debug.Log($"https://bico.media/{txn}"); });
        });
    }
Ejemplo n.º 3
0
    void SubmitForm(Dictionary <string, string> data)
    {
        Debug.Log(JsonConvert.SerializeObject(data));
        foreach (var item in data)
        {
            if (string.IsNullOrEmpty(item.Value))
            {
                ModalDialog.Instance.Show("Missing Fields",
                                          "Please fill in all the fields necessary to complete the task", "Ok");
                return;
            }
        }

        try
        {
            ModalDialog.Instance.Show("Submitting task",
                                      "Please wait while your task txn is being build and broadcast");

            Assert.IsTrue(!string.IsNullOrEmpty(stateId));
            Assert.IsNotNull(submitUTXO);
            UtxoUtils.BuildSubmitTxnFromUtxo(Authenticator.Instance.Identity.PrivateKey, submitUTXO,
                                             OpReturns.MakeSubmit(stateId, data), payeeAddr, funds).Spend(s =>
            {
                ModalDialog.Instance.Show("Transaction Successful",
                                          "You txn was broadcast and this task is completed. " +
                                          $"{funds} BSV sat have been delivered to the payee ({payeeAddr}). " +
                                          "Txn: " + s, "Ok");
                ModalDialog.Instance.CallbackYes.RemoveAllListeners();
                ModalDialog.Instance.CallbackYes.AddListener(() =>
                {
                    StartCoroutine(DelayedGoToMenu());
                });
            });
        }
        catch
        {
            ModalDialog.Instance.Show("Fatal Error", "Please try again", "Ok");
            ModalDialog.Instance.CallbackYes.AddListener(() => { SceneManager.LoadScene("Main"); });
        }
    }
Ejemplo n.º 4
0
    void OnCameraShotComplete(Texture2D texture2D, string path)
    {
        ModalDialog.Instance.Show("Processing Photo",
                                  "Please wait while your photo is encoded into a txn and broadcast");
        try
        {
            var pix = texture2D.GetPixels32();

            // Copy the reversed image data to a new texture.
            var tex = new Texture2D(texture2D.width, texture2D.height);
            tex.SetPixels32(pix);
            tex.Apply();

            // TODO: Duplicated code with UploadImage.cs
            var width   = 0;
            var height  = 0;
            var maxSize = 800;
            if (tex.width > tex.height)
            {
                if (tex.width > maxSize)
                {
                    width  = maxSize;
                    height = (tex.height * maxSize) / tex.width;
                }
            }
            else
            {
                if (tex.height > maxSize)
                {
                    height = maxSize;
                    width  = (tex.width * maxSize) / tex.height;
                }
            }

            TextureScale.Point(tex, width, height);

            Debug.Log($"Texture is {tex.width}x{tex.height}");

            var buffer = tex.EncodeToJPG();
            Debug.Log(buffer.Length);

            Debug.Log(JsonConvert.SerializeObject(UTXO));

            UtxoUtils.BuildTxnFromUtxo(
                Authenticator.Instance.Identity.PrivateKey,
                UTXO,
                OpReturns.MakeImg(buffer))
            .Spend(txn =>
            {
                var value = $"https://bico.media/{txn}";
                Debug.Log(value);
                ModalDialog.Instance.Hide();
                ModalDialog.Instance.Show("Image successfully uploaded",
                                          $"Check it out at: {value}", "View Online", "Ok");
                ModalDialog.Instance.CallbackYes.RemoveAllListeners();
                ModalDialog.Instance.CallbackYes.AddListener(() =>
                {
                    //UniClipboard.SetText( $"https://bico.media/{txn}" );
                    Application.OpenURL($"https://bico.media/{txn}");
                });

                InputField.text = txn;
                var sprite      = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f),
                                                100.0f);
                Image.sprite = sprite;
            });
        }
        catch (Exception e)
        {
            ModalDialog.Instance.Hide();
            ModalDialog.Instance.Show($"Something went wrong, try again later",
                                      $"{e.GetType()}: {e.Message}", "Ok");
        }
    }