Skip to content

Commit

Permalink
initial magic.link support
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Dec 13, 2022
1 parent a72fd34 commit d2bbef6
Show file tree
Hide file tree
Showing 5 changed files with 980 additions and 102 deletions.
221 changes: 218 additions & 3 deletions Assets/Thirdweb/Demo/ThirdwebDemoScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -1, y: 0}
m_AnchoredPosition: {x: -200, y: 0}
m_SizeDelta: {x: 350, y: 65}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &259715465
Expand Down Expand Up @@ -1550,7 +1550,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 397, y: 0}
m_AnchoredPosition: {x: 200, y: 0}
m_SizeDelta: {x: 350, y: 65}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &633987596
Expand Down Expand Up @@ -1741,6 +1741,140 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &765549956
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 765549957}
- component: {fileID: 765549960}
- component: {fileID: 765549959}
- component: {fileID: 765549958}
m_Layer: 5
m_Name: MagicLinkButton
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &765549957
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 765549956}
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: 1843937916}
m_Father: {fileID: 1912293259}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 600, y: 0}
m_SizeDelta: {x: 350, y: 65}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &765549958
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 765549956}
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: 765549959}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 354401067}
m_TargetAssemblyTypeName: ThirdwebSDKDemos, Assembly-CSharp
m_MethodName: MagicAuthLogin
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &765549959
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 765549956}
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: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
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!222 &765549960
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 765549956}
m_CullTransparentMesh: 1
--- !u!1 &782628375
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2198,7 +2332,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -397, y: 0}
m_AnchoredPosition: {x: -600, y: 0}
m_SizeDelta: {x: 350, y: 65}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1114040582
Expand Down Expand Up @@ -3857,6 +3991,86 @@ MonoBehaviour:
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Fetch ERC721
--- !u!1 &1843937915
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1843937916}
- component: {fileID: 1843937918}
- component: {fileID: 1843937917}
m_Layer: 5
m_Name: MagicLinkText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1843937916
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1843937915}
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: 765549957}
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: -1.5}
m_SizeDelta: {x: -4, y: -7}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1843937917
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1843937915}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, 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_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Magic.link
--- !u!222 &1843937918
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1843937915}
m_CullTransparentMesh: 1
--- !u!1 &1891838640
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4022,6 +4236,7 @@ RectTransform:
- {fileID: 633987595}
- {fileID: 259715464}
- {fileID: 1114040581}
- {fileID: 765549957}
m_Father: {fileID: 223974230}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down
36 changes: 30 additions & 6 deletions Assets/Thirdweb/Demo/ThirdwebSDKDemos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ public void WalletConnectLogin()
ConnectWallet(WalletProvider.WalletConnect);
}

public void MagicAuthLogin()
{
// Requires passing a magic.link API key in the SDK options:
// sdk = new ThirdwebSDK("goerli", new ThirdwebSDK.Options()
// {
// wallet = new ThirdwebSDK.WalletOptions()
// {
// appName = "Thirdweb SDK Demo",
// extras = new Dictionary<string, object>()
// {
// {"apiKey", "your_api_key"}
// }
// }
// });
ConnectWallet(WalletProvider.MagicAuth);
}

public async void DisconnectWallet()
{
await sdk.wallet.Disconnect();
Expand All @@ -55,19 +72,26 @@ private async void ConnectWallet(WalletProvider provider)
connectButtonsContainer.SetActive(false);
walletInfoContainer.SetActive(true);
walletInfotext.text = "Connecting...";
string address = await sdk.wallet.Connect(new WalletConnection()
try
{
provider = provider,
chainId = 5 // Switch the wallet Goerli on connection
});
walletInfotext.text = "Connected as: " + address;
string address = await sdk.wallet.Connect(new WalletConnection()
{
provider = provider,
chainId = 5 // Switch the wallet Goerli on connection
});
walletInfotext.text = "Connected as: " + address;
}
catch (System.Exception e)
{
walletInfotext.text = "Error (see console): " + e.Message;
}
}

public async void OnBalanceClick()
{
resultText.text = "Loading...";
CurrencyValue balance = await sdk.wallet.GetBalance();
resultText.text = "Balance: " + balance.displayValue.Substring(0, 3) + " " + balance.symbol;
resultText.text = "Balance: " + balance.displayValue.Substring(0, 5) + " " + balance.symbol;
}

public async void OnSignClick()
Expand Down
33 changes: 22 additions & 11 deletions Assets/Thirdweb/Scripts/ThirdwebSDK.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Thirdweb
Expand All @@ -13,9 +14,28 @@ public class ThirdwebSDK
[System.Serializable]
public struct Options
{
public string appName;
public GaslessOptions? gasless;
public string ipfsGatewayUrl;
public StorageOptions? storage;
public WalletOptions? wallet;
}

/// <summary>
/// Wallet configuration options.
/// </summary>
[System.Serializable]
public struct WalletOptions
{
public string appName; // the app name that will show in different wallet providers
public Dictionary<string, object> extras; // extra data to pass to the wallet provider
}

/// <summary>
/// Storage configuration options.
/// </summary>
[System.Serializable]
public struct StorageOptions
{
public string ipfsGatewayUrl; // override the default ipfs gateway, should end in /ipfs/
}

/// <summary>
Expand Down Expand Up @@ -83,14 +103,5 @@ public Contract GetContract(string address, string abi = null)
{
return new Contract(this.chainOrRPC, address, abi);
}

/// <summary>
/// Prompt the user to fund their wallet using one of the thirdweb pay providers (defaults to Coinbase Pay).
/// </summary>
/// <param name="options">The options like wallet address to fund, on which chain, etc</param>
public async Task FundWallet(FundWalletOptions options)
{
await Bridge.FundWallet(options);
}
}
}
14 changes: 14 additions & 0 deletions Assets/Thirdweb/Scripts/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ public async Task<TransactionResult> SendRawTransaction(TransactionRequest trans
{
return await Bridge.InvokeRoute<TransactionResult>(getRoute("sendRawTransaction"), Utils.ToJsonStringArray(transactionRequest));
}

/// <summary>
/// Prompt the user to fund their wallet using one of the thirdweb pay providers (defaults to Coinbase Pay).
/// </summary>
/// <param name="options">The options like wallet address to fund, on which chain, etc</param>
public async Task FundWallet(FundWalletOptions options)
{
if (options.address == null)
{
options.address = await GetAddress();
}
await Bridge.FundWallet(options);
}
}

public struct WalletConnection
Expand All @@ -131,6 +144,7 @@ public class WalletProvider
public static WalletProvider CoinbaseWallet { get { return new WalletProvider("coinbaseWallet"); } }
public static WalletProvider WalletConnect { get { return new WalletProvider("walletConnect"); } }
public static WalletProvider Injected { get { return new WalletProvider("injected"); } }
public static WalletProvider MagicAuth { get { return new WalletProvider("magicAuth"); } }

public override string ToString()
{
Expand Down
Loading

0 comments on commit d2bbef6

Please sign in to comment.