< Summary

Class:RPC.Services.RestrictedActionsServiceImpl
Assembly:RPC.Service.RestrictedActions
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/RPC/Services/RestrictedActionsService/RestrictedActionsServiceImpl.cs
Covered lines:25
Uncovered lines:23
Coverable lines:48
Total lines:106
Line coverage:52% (25 of 48)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:5
Method coverage:60% (3 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RestrictedActionsServiceImpl()0%110100%
RegisterService(...)0%2100%
TeleportTo()0%30500%
OpenExternalUrl()0%11.388062.5%
OpenNftDialog()0%10.378066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/RPC/Services/RestrictedActionsService/RestrictedActionsServiceImpl.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Helpers.NFT;
 3using Decentraland.Renderer.RendererServices;
 4using rpc_csharp;
 5using RPC.Context;
 6using System;
 7using System.Threading;
 8using UnityEngine;
 9
 10namespace RPC.Services
 11{
 12    public class RestrictedActionsServiceImpl : IRestrictedActionsService<RPCContext>
 13    {
 114        private static readonly OpenModalResponse OPEN_MODAL_SUCCESS_RESPONSE = new OpenModalResponse() { Success = true
 115        private static readonly OpenModalResponse OPEN_MODAL_FAIL_RESPONSE = new OpenModalResponse() { Success = false }
 116        private static readonly TeleportToResponse TELEPORT_TO_RESPONSE = new TeleportToResponse() { };
 17
 18        public static void RegisterService(RpcServerPort<RPCContext> port)
 19        {
 020            RestrictedActionsServiceCodeGen.RegisterService(port, new RestrictedActionsServiceImpl());
 021        }
 22
 23        public async UniTask<TeleportToResponse> TeleportTo(TeleportToRequest request, RPCContext context, CancellationT
 24        {
 025            await UniTask.SwitchToMainThread(ct);
 026            RestrictedActionsContext restrictedActions = context.restrictedActions;
 27
 028            int sceneNumber = request.SceneNumber;
 29
 30            try
 31            {
 032                ct.ThrowIfCancellationRequested();
 33
 034                if (restrictedActions.IsSceneRestrictedActionEnabled(sceneNumber))
 035                    restrictedActions.TeleportToPrompt?.Invoke((int)request.WorldCoordinates.X, (int)request.WorldCoordi
 036            }
 037            catch (OperationCanceledException _)
 38            { // ignored
 039            }
 40            catch (Exception e)
 41            {
 042                Debug.LogException(e);
 043            }
 44
 045            return TELEPORT_TO_RESPONSE;
 046        }
 47
 48        public async UniTask<OpenModalResponse> OpenExternalUrl(OpenExternalUrlRequest request, RPCContext context, Canc
 49        {
 250            await UniTask.SwitchToMainThread(ct);
 251            RestrictedActionsContext restrictedActions = context.restrictedActions;
 52
 253            bool success = false;
 254            int sceneNumber = request.SceneNumber;
 55
 56            try
 57            {
 258                ct.ThrowIfCancellationRequested();
 59
 260                if (restrictedActions.IsSceneRestrictedActionEnabled(sceneNumber))
 161                    success = restrictedActions.OpenExternalUrlPrompt?.Invoke(request.Url, sceneNumber) ?? false;
 262            }
 063            catch (OperationCanceledException _)
 64            { // ignored
 065            }
 66            catch (Exception e)
 67            {
 068                Debug.LogException(e);
 069            }
 70
 271            return success ? OPEN_MODAL_SUCCESS_RESPONSE : OPEN_MODAL_FAIL_RESPONSE;
 272        }
 73
 74        public async UniTask<OpenModalResponse> OpenNftDialog(OpenNftDialogRequest request, RPCContext context, Cancella
 75        {
 376            await UniTask.SwitchToMainThread(ct);
 377            RestrictedActionsContext restrictedActions = context.restrictedActions;
 78
 379            bool success = false;
 380            int sceneNumber = request.SceneNumber;
 81
 82            try
 83            {
 384                ct.ThrowIfCancellationRequested();
 85
 386                if (restrictedActions.IsSceneRestrictedActionEnabled(sceneNumber))
 87                {
 288                    if (NFTUtils.TryParseUrn(request.Urn, out string chain, out string contractAddress, out string token
 89                    {
 190                        restrictedActions.OpenNftPrompt?.Invoke(chain, contractAddress, tokenId);
 191                        success = true;
 92                    }
 93                }
 394            }
 095            catch (OperationCanceledException _)
 96            { // ignored
 097            }
 98            catch (Exception e)
 99            {
 0100                Debug.LogException(e);
 0101            }
 102
 3103            return success ? OPEN_MODAL_SUCCESS_RESPONSE : OPEN_MODAL_FAIL_RESPONSE;
 3104        }
 105    }
 106}