From b38eb26f41fdf18d5cf06270a17cec3dc1692338 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Mon, 20 Jan 2025 12:28:55 +1300 Subject: [PATCH] feat: swap, bridge --- .../Prefabs/UI/AddFunds/AddFundsView.prefab | 282 +++++++++++++++++- .../Scripts/Domain/GetTokenBalanceUseCase.cs | 1 - Assets/Shared/Scripts/UI/AddFunds/AddFunds.cs | 28 +- Packages/packages-lock.json | 4 +- ProjectSettings/ProjectSettings.asset | 2 +- 5 files changed, 303 insertions(+), 14 deletions(-) diff --git a/Assets/Shared/Prefabs/UI/AddFunds/AddFundsView.prefab b/Assets/Shared/Prefabs/UI/AddFunds/AddFundsView.prefab index 6d64d48e..f9ed7387 100644 --- a/Assets/Shared/Prefabs/UI/AddFunds/AddFundsView.prefab +++ b/Assets/Shared/Prefabs/UI/AddFunds/AddFundsView.prefab @@ -135,6 +135,143 @@ MonoBehaviour: m_hasFontAssetChanged: 0 m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!1 &1767258633686331833 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2173049430205213948} + - component: {fileID: 3068992101707791516} + - component: {fileID: 3996362775458937883} + - component: {fileID: 6365084079384241397} + - component: {fileID: 408387550970373338} + m_Layer: 5 + m_Name: Bridge Button + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2173049430205213948 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1767258633686331833} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 7969633959797431265} + m_Father: {fileID: 7177077492089312687} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 400, y: 80} + m_Pivot: {x: 0.5, y: 0} +--- !u!222 &3068992101707791516 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1767258633686331833} + m_CullTransparentMesh: 1 +--- !u!114 &3996362775458937883 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1767258633686331833} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: a7b4b8207be2c4ad19974afa7ca5cd91, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!114 &6365084079384241397 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1767258633686331833} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 3996362775458937883} + m_OnClick: + m_PersistentCalls: + m_Calls: [] +--- !u!114 &408387550970373338 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1767258633686331833} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b5e87ca911816437f846b3f0d738b485, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Button: {fileID: 6365084079384241397} + m_ButtonSound: 3 --- !u!1 &1767334457667686318 GameObject: m_ObjectHideFlags: 0 @@ -170,6 +307,7 @@ RectTransform: - {fileID: 3133734374320710578} - {fileID: 4956603440870209634} - {fileID: 7798443803515428275} + - {fileID: 2173049430205213948} - {fileID: 1165059358673368351} m_Father: {fileID: 5464304629124346698} m_RootOrder: 0 @@ -323,7 +461,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Swap or Bridge Tokens + m_text: Swap tokens m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -527,6 +665,141 @@ MonoBehaviour: m_hasFontAssetChanged: 0 m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!1 &2914252301972737648 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7969633959797431265} + - component: {fileID: 3440831668349587754} + - component: {fileID: 3153474911111393459} + m_Layer: 5 + m_Name: Text (TMP) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &7969633959797431265 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2914252301972737648} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2173049430205213948} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: -0.000030517578} + m_SizeDelta: {x: -48, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &3440831668349587754 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2914252301972737648} + m_CullTransparentMesh: 1 +--- !u!114 &3153474911111393459 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2914252301972737648} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: Bridge tokens + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 24 + m_fontSizeBase: 24 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 1 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} --- !u!1 &3910282061138255774 GameObject: m_ObjectHideFlags: 0 @@ -541,7 +814,7 @@ GameObject: - component: {fileID: 4476008866051575491} - component: {fileID: 1082315832006481771} m_Layer: 5 - m_Name: Token Button + m_Name: Swap Button m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -726,7 +999,8 @@ MonoBehaviour: m_EditorClassIdentifier: m_Options: {fileID: 1767334457667686318} m_FiatButton: {fileID: 5497729094643045049} - m_TokenButton: {fileID: 4476008866051575491} + m_SwapButton: {fileID: 4476008866051575491} + m_BridgeButton: {fileID: 6365084079384241397} m_CancelButton: {fileID: 3979097821289202964} m_TransakView: {fileID: 2253209125222071253} --- !u!1 &7087042878566949568 @@ -1035,7 +1309,7 @@ RectTransform: m_Children: - {fileID: 7492764391848221150} m_Father: {fileID: 7177077492089312687} - m_RootOrder: 3 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} diff --git a/Assets/Shared/Scripts/Domain/GetTokenBalanceUseCase.cs b/Assets/Shared/Scripts/Domain/GetTokenBalanceUseCase.cs index b5f42860..917c3bad 100644 --- a/Assets/Shared/Scripts/Domain/GetTokenBalanceUseCase.cs +++ b/Assets/Shared/Scripts/Domain/GetTokenBalanceUseCase.cs @@ -6,7 +6,6 @@ using Immutable.Orderbook.Client; using Immutable.Passport; using Nethereum.Web3; -using UnityEngine; namespace HyperCasual.Runner { diff --git a/Assets/Shared/Scripts/UI/AddFunds/AddFunds.cs b/Assets/Shared/Scripts/UI/AddFunds/AddFunds.cs index ee1993f6..315f29be 100644 --- a/Assets/Shared/Scripts/UI/AddFunds/AddFunds.cs +++ b/Assets/Shared/Scripts/UI/AddFunds/AddFunds.cs @@ -3,7 +3,9 @@ using UnityEngine.UI; using System.Collections.Generic; using System.Linq; +using Immutable.Marketplace.Bridge; using Immutable.Marketplace.OnRamp; +using Immutable.Marketplace.Swap; using Immutable.Passport; namespace HyperCasual.Runner @@ -15,7 +17,8 @@ public class AddFunds : MonoBehaviour { [SerializeField] GameObject m_Options; [SerializeField] Button m_FiatButton; - [SerializeField] Button m_TokenButton; + [SerializeField] Button m_SwapButton; + [SerializeField] Button m_BridgeButton; [SerializeField] Button m_CancelButton; [SerializeField] TransakView m_TransakView; @@ -29,8 +32,11 @@ public void Show(Action onDismiss) m_FiatButton.onClick.RemoveListener(OnFiatButtonClicked); m_FiatButton.onClick.AddListener(OnFiatButtonClicked); - m_TokenButton.onClick.RemoveListener(OnTokenButtonClicked); - m_TokenButton.onClick.AddListener(OnTokenButtonClicked); + m_SwapButton.onClick.RemoveListener(OnSwapButtonClicked); + m_SwapButton.onClick.AddListener(OnSwapButtonClicked); + + m_BridgeButton.onClick.RemoveListener(OnBridgeButtonClicked); + m_BridgeButton.onClick.AddListener(OnBridgeButtonClicked); m_CancelButton.onClick.RemoveListener(OnCancelButtonClicked); m_CancelButton.onClick.AddListener(OnCancelButtonClicked); @@ -47,7 +53,7 @@ private async void OnFiatButtonClicked() var walletAddress = await Passport.Instance.ZkEvmRequestAccounts(); var onRamp = new OnRamp(environment, email, walletAddress.FirstOrDefault()); - var link = await onRamp.GetLink(); + var link = onRamp.GetLink(); Debug.Log($"onRamp.GetOnRampLink: {link}"); m_TransakView.Show(link, () => @@ -57,9 +63,19 @@ private async void OnFiatButtonClicked() }); } - private void OnTokenButtonClicked() + private void OnSwapButtonClicked() + { + var swap = new Swap(Immutable.Passport.Model.Environment.SANDBOX); + var link = swap.GetLink(fromTokenAddress: Contract.USDC, toTokenAddress: Contract.TOKEN); + Application.OpenURL(link); + } + + private void OnBridgeButtonClicked() { - Application.OpenURL($"https://checkout-playground.sandbox.immutable.com/checkout/swap/?publishableKey=pk_imapik-test-7-hfC5T$W$eEDE8Mc5mp&fromTokenAddress={Contract.USDC}&toTokenAddress={Contract.TOKEN}"); + // On supports mainnet + var bridge = new Bridge(Immutable.Passport.Model.Environment.PRODUCTION); + var link = bridge.GetLink(toChain: "13371"); + Application.OpenURL(link); } private void OnCancelButtonClicked() diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index c1a87045..e6a046b0 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -23,7 +23,7 @@ "dependencies": { "com.cysharp.unitask": "2.3.3" }, - "hash": "01fdea8065a855144ab98514d95f70e8d9a2f74e" + "hash": "4a4c96fad53e7f0c40ac73e68e564b131e1a6d4a" }, "com.immutable.orderbook": { "version": "https://github.com/immutable/unity-immutable-sdk.git?path=/src/Packages/Orderbook", @@ -42,7 +42,7 @@ "com.unity.nuget.newtonsoft-json": "3.2.0", "com.cysharp.unitask": "2.3.3" }, - "hash": "9ed3136ecf878ee1cf229fdf8c7f064bdb6e6cda" + "hash": "66f25ffb133c920467597f32dde7e719bb7f9652" }, "com.nethereum.unity": { "version": "4.19.2", diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index cbee7220..1427a836 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -779,7 +779,7 @@ PlayerSettings: additionalIl2CppArgs: scriptingRuntimeVersion: 1 gcIncremental: 0 - assemblyVersionValidation: 1 + assemblyVersionValidation: 0 gcWBarrierValidation: 0 apiCompatibilityLevelPerPlatform: {} m_RenderingPath: 1