Esempio n. 1
0
 public void PostSuccess(MatryxRound newRound, Async.EventDelegate onReturn = null)
 {
     SetStatus("Successfully created round " + newRound.index);
     severalMinutesText.gameObject.SetActive(false);
     mayReturn.gameObject.SetActive(true);
     StartCoroutine(ReturnToCalcflowAfterSeconds(3f, onReturn));
 }
Esempio n. 2
0
    public void PostFailure(MatryxRound newRound, string message = null, Async.EventDelegate onReturn = null)
    {
        if (message != null)
        {
            SetStatus(message);
        }
        else
        {
            SetStatus("Failed to create round " + newRound.index);
        }

        severalMinutesText.gameObject.SetActive(false);
        mayReturn.gameObject.SetActive(true);
        tryAgainButton.gameObject.SetActive(true);
        StartCoroutine(ReturnToCalcflowAfterSeconds(3f, onReturn));
    }
Esempio n. 3
0
    public IEnumerator runCreateRound()
    {
        InvalidLabel.gameObject.SetActive(false);

        if (!InputsValid().Equals(string.Empty))
        {
            yield break;
        }

        gameObject.SetActive(false);
        InvalidLabel.gameObject.SetActive(false);

        resultsCanvasObject.SetActive(true);

        var start          = new BigInteger(Utils.Time.ToUnixTime(startDatePicker.fecha));
        var duration       = new BigInteger((endDatePicker.fecha - startDatePicker.fecha).TotalSeconds);
        var reviewDuration = new BigInteger((reviewEndDatePicker.fecha - endDatePicker.fecha).TotalSeconds);
        var bounty         = new BigInteger(Convert.ToDecimal(bountyPicker.CurrentValue));

        MatryxRound.RoundDetails details = new MatryxRound.RoundDetails()
        {
            Start    = start,
            Duration = duration,
            Review   = reviewDuration,
            Bounty   = bounty * new BigInteger(1e18)
        };
        MatryxRound newRound = new MatryxRound(tournament.currentRound.index + 1, details);

        newRound.tournament = TournamentMenu.Tournament;

        ManageTournamentMenu.SetButtonsEnabled(false);

        resultsMenu.SetStatus("Checking MTX balance and platform allowance...");
        var allowance = new Utils.CoroutineWithData <BigInteger>(MatryxCortex.Instance, MatryxToken.allowance(NetworkSettings.currentAddress, MatryxPlatform.address));

        yield return(allowance);

        var balance = new Utils.CoroutineWithData <BigInteger>(MatryxCortex.Instance, MatryxToken.balanceOf(NetworkSettings.currentAddress));

        yield return(balance);

        if (balance.result < details.Bounty)
        {
            ResultsMenu.Instance.SetStatus("Insufficient MTX. Please visit <link=https://app.matryx.ai/><u>our Matryx Dapp</u></link> for MTX Tokens.", true);
            ResultsMenu.Instance.ReturnToCalcflowAfterSeconds(8f);
            yield break;
        }

        if (allowance.result < details.Bounty)
        {
            ResultsMenu.Instance.SetStatus("Approving MatryxPlatform for " + bounty + " MTX...");

            if (allowance.result != BigInteger.Zero)
            {
                var approveZero = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, MatryxToken.approve(MatryxPlatform.address, BigInteger.Zero));
                yield return(approveZero);

                if (!approveZero.result)
                {
                    resultsMenu.PostFailure(newRound, "Failed to reset the platform allowance to zero");
                    yield break;
                }
            }

            var approveBounty = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, MatryxToken.approve(MatryxPlatform.address, details.Bounty));
            yield return(approveBounty);

            if (!approveBounty.result)
            {
                resultsMenu.PostFailure(newRound, "Failed to give the platform an MTX allowance");
                yield break;
            }
        }

        resultsMenu.SetStatus("Adding to Tournament bounty...");
        var addToBountyCoroutine = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, TournamentMenu.Tournament.addToBounty(details.Bounty));

        yield return(addToBountyCoroutine);

        if (!addToBountyCoroutine.result)
        {
            resultsMenu.PostFailure(newRound, "Could not add to tournament bounty");
            yield break;
        }

        resultsMenu.SetStatus("Creating new round...");
        var submissions = ManageTournamentMenu.winningSubmissions.Select(sub => Utils.HexStringToByteArray(sub.hash)).ToList();

        if (TournamentMenu.Tournament.currentRound.winningSubmissions.Count == 0)
        {
            IEnumerator selectWinnersCoroutine     = tournament.selectWinners(submissions, ManageTournamentMenu.distribution, new BigInteger((int)MatryxTournament.SelectWinnerAction.StartNextRound), details.Start, details.Duration, details.Review, details.Bounty);
            var         selectWinnersDataCoroutine = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, selectWinnersCoroutine);
            yield return(selectWinnersDataCoroutine);

            ClearInputs();
            gameObject.SetActive(false);
            ManageTournamentMenu.SetButtonsEnabled(true);
            ManageTournamentMenu.Instance.PressButton("NewRoundButton");
            ResultsMenu.transactionObject = newRound;
            Debug.Log((bool)selectWinnersDataCoroutine.result ? "Successfully created new round!" : "Round creation unsuccessful.");

            if (selectWinnersDataCoroutine.result)
            {
                StatisticsTracking.EndEvent("Matryx", "New Round Creation", new Dictionary <string, object>()
                {
                    { "success", true }
                });
                tournament.currentRound = newRound;
                resultsMenu.PostSuccess(newRound,
                                        delegate(object nothin)
                {
                    TournamentMenu.Instance.SetRound(newRound.index);
                    TournamentMenu.Instance.UpdateActionState();
                    ManageTournamentMenu.Close();

                    TournamentMenu.Instance.actionState = TournamentMenu.ActionState.NoAction;
                    TournamentMenuCenterButton.Instance.updateState();
                });
            }
            else
            {
                StatisticsTracking.EndEvent("Matryx", "New Round Creation", new Dictionary <string, object>()
                {
                    { "success", false }
                });
                resultsMenu.PostFailure(newRound, "Failed to create new round");
            }
        }
        else
        {
            resultsMenu.SetStatus("Updating next round...");
            IEnumerator updateNextRoundCoroutine     = tournament.updateNextRound(details);
            var         updateNextRoundDataCoroutine = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, updateNextRoundCoroutine);
            yield return(updateNextRoundDataCoroutine);

            ClearInputs();
            gameObject.SetActive(false);
            ManageTournamentMenu.SetButtonsEnabled(true);
            ManageTournamentMenu.Instance.PressButton("NewRoundButton");

            if (updateNextRoundDataCoroutine.result)
            {
                StatisticsTracking.EndEvent("Matryx", "New Round Creation", new Dictionary <string, object>()
                {
                    { "success", true }
                });
                tournament.currentRound = newRound;

                resultsMenu.PostSuccess(newRound, (nothin) =>
                {
                    TournamentMenu.Instance.actionState = TournamentMenu.ActionState.ManageTournament;
                    TournamentMenuCenterButton.Instance.updateState();
                });
            }
            else
            {
                StatisticsTracking.EndEvent("Matryx", "New Round Creation", new Dictionary <string, object>()
                {
                    { "success", false }
                });
                resultsMenu.PostFailure(newRound, "Failed to create new round");
            }
        }
    }