Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d2bbef6

Browse files
committedDec 13, 2022
initial magic.link support
1 parent a72fd34 commit d2bbef6

File tree

5 files changed

+980
-102
lines changed

5 files changed

+980
-102
lines changed
 

‎Assets/Thirdweb/Demo/ThirdwebDemoScene.unity

+218-3
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ RectTransform:
997997
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
998998
m_AnchorMin: {x: 0.5, y: 0.5}
999999
m_AnchorMax: {x: 0.5, y: 0.5}
1000-
m_AnchoredPosition: {x: -1, y: 0}
1000+
m_AnchoredPosition: {x: -200, y: 0}
10011001
m_SizeDelta: {x: 350, y: 65}
10021002
m_Pivot: {x: 0.5, y: 0.5}
10031003
--- !u!114 &259715465
@@ -1550,7 +1550,7 @@ RectTransform:
15501550
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
15511551
m_AnchorMin: {x: 0.5, y: 0.5}
15521552
m_AnchorMax: {x: 0.5, y: 0.5}
1553-
m_AnchoredPosition: {x: 397, y: 0}
1553+
m_AnchoredPosition: {x: 200, y: 0}
15541554
m_SizeDelta: {x: 350, y: 65}
15551555
m_Pivot: {x: 0.5, y: 0.5}
15561556
--- !u!114 &633987596
@@ -1741,6 +1741,140 @@ Transform:
17411741
m_Father: {fileID: 0}
17421742
m_RootOrder: 1
17431743
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
1744+
--- !u!1 &765549956
1745+
GameObject:
1746+
m_ObjectHideFlags: 0
1747+
m_CorrespondingSourceObject: {fileID: 0}
1748+
m_PrefabInstance: {fileID: 0}
1749+
m_PrefabAsset: {fileID: 0}
1750+
serializedVersion: 6
1751+
m_Component:
1752+
- component: {fileID: 765549957}
1753+
- component: {fileID: 765549960}
1754+
- component: {fileID: 765549959}
1755+
- component: {fileID: 765549958}
1756+
m_Layer: 5
1757+
m_Name: MagicLinkButton
1758+
m_TagString: Untagged
1759+
m_Icon: {fileID: 0}
1760+
m_NavMeshLayer: 0
1761+
m_StaticEditorFlags: 0
1762+
m_IsActive: 1
1763+
--- !u!224 &765549957
1764+
RectTransform:
1765+
m_ObjectHideFlags: 0
1766+
m_CorrespondingSourceObject: {fileID: 0}
1767+
m_PrefabInstance: {fileID: 0}
1768+
m_PrefabAsset: {fileID: 0}
1769+
m_GameObject: {fileID: 765549956}
1770+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
1771+
m_LocalPosition: {x: 0, y: 0, z: 0}
1772+
m_LocalScale: {x: 1, y: 1, z: 1}
1773+
m_ConstrainProportionsScale: 0
1774+
m_Children:
1775+
- {fileID: 1843937916}
1776+
m_Father: {fileID: 1912293259}
1777+
m_RootOrder: 3
1778+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1779+
m_AnchorMin: {x: 0.5, y: 0.5}
1780+
m_AnchorMax: {x: 0.5, y: 0.5}
1781+
m_AnchoredPosition: {x: 600, y: 0}
1782+
m_SizeDelta: {x: 350, y: 65}
1783+
m_Pivot: {x: 0.5, y: 0.5}
1784+
--- !u!114 &765549958
1785+
MonoBehaviour:
1786+
m_ObjectHideFlags: 0
1787+
m_CorrespondingSourceObject: {fileID: 0}
1788+
m_PrefabInstance: {fileID: 0}
1789+
m_PrefabAsset: {fileID: 0}
1790+
m_GameObject: {fileID: 765549956}
1791+
m_Enabled: 1
1792+
m_EditorHideFlags: 0
1793+
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
1794+
m_Name:
1795+
m_EditorClassIdentifier:
1796+
m_Navigation:
1797+
m_Mode: 3
1798+
m_WrapAround: 0
1799+
m_SelectOnUp: {fileID: 0}
1800+
m_SelectOnDown: {fileID: 0}
1801+
m_SelectOnLeft: {fileID: 0}
1802+
m_SelectOnRight: {fileID: 0}
1803+
m_Transition: 1
1804+
m_Colors:
1805+
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
1806+
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
1807+
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
1808+
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
1809+
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
1810+
m_ColorMultiplier: 1
1811+
m_FadeDuration: 0.1
1812+
m_SpriteState:
1813+
m_HighlightedSprite: {fileID: 0}
1814+
m_PressedSprite: {fileID: 0}
1815+
m_SelectedSprite: {fileID: 0}
1816+
m_DisabledSprite: {fileID: 0}
1817+
m_AnimationTriggers:
1818+
m_NormalTrigger: Normal
1819+
m_HighlightedTrigger: Highlighted
1820+
m_PressedTrigger: Pressed
1821+
m_SelectedTrigger: Selected
1822+
m_DisabledTrigger: Disabled
1823+
m_Interactable: 1
1824+
m_TargetGraphic: {fileID: 765549959}
1825+
m_OnClick:
1826+
m_PersistentCalls:
1827+
m_Calls:
1828+
- m_Target: {fileID: 354401067}
1829+
m_TargetAssemblyTypeName: ThirdwebSDKDemos, Assembly-CSharp
1830+
m_MethodName: MagicAuthLogin
1831+
m_Mode: 1
1832+
m_Arguments:
1833+
m_ObjectArgument: {fileID: 0}
1834+
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
1835+
m_IntArgument: 0
1836+
m_FloatArgument: 0
1837+
m_StringArgument:
1838+
m_BoolArgument: 0
1839+
m_CallState: 2
1840+
--- !u!114 &765549959
1841+
MonoBehaviour:
1842+
m_ObjectHideFlags: 0
1843+
m_CorrespondingSourceObject: {fileID: 0}
1844+
m_PrefabInstance: {fileID: 0}
1845+
m_PrefabAsset: {fileID: 0}
1846+
m_GameObject: {fileID: 765549956}
1847+
m_Enabled: 1
1848+
m_EditorHideFlags: 0
1849+
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
1850+
m_Name:
1851+
m_EditorClassIdentifier:
1852+
m_Material: {fileID: 0}
1853+
m_Color: {r: 1, g: 1, b: 1, a: 1}
1854+
m_RaycastTarget: 1
1855+
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
1856+
m_Maskable: 1
1857+
m_OnCullStateChanged:
1858+
m_PersistentCalls:
1859+
m_Calls: []
1860+
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
1861+
m_Type: 1
1862+
m_PreserveAspect: 0
1863+
m_FillCenter: 1
1864+
m_FillMethod: 4
1865+
m_FillAmount: 1
1866+
m_FillClockwise: 1
1867+
m_FillOrigin: 0
1868+
m_UseSpriteMesh: 0
1869+
m_PixelsPerUnitMultiplier: 1
1870+
--- !u!222 &765549960
1871+
CanvasRenderer:
1872+
m_ObjectHideFlags: 0
1873+
m_CorrespondingSourceObject: {fileID: 0}
1874+
m_PrefabInstance: {fileID: 0}
1875+
m_PrefabAsset: {fileID: 0}
1876+
m_GameObject: {fileID: 765549956}
1877+
m_CullTransparentMesh: 1
17441878
--- !u!1 &782628375
17451879
GameObject:
17461880
m_ObjectHideFlags: 0
@@ -2198,7 +2332,7 @@ RectTransform:
21982332
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
21992333
m_AnchorMin: {x: 0.5, y: 0.5}
22002334
m_AnchorMax: {x: 0.5, y: 0.5}
2201-
m_AnchoredPosition: {x: -397, y: 0}
2335+
m_AnchoredPosition: {x: -600, y: 0}
22022336
m_SizeDelta: {x: 350, y: 65}
22032337
m_Pivot: {x: 0.5, y: 0.5}
22042338
--- !u!114 &1114040582
@@ -3857,6 +3991,86 @@ MonoBehaviour:
38573991
m_VerticalOverflow: 0
38583992
m_LineSpacing: 1
38593993
m_Text: Fetch ERC721
3994+
--- !u!1 &1843937915
3995+
GameObject:
3996+
m_ObjectHideFlags: 0
3997+
m_CorrespondingSourceObject: {fileID: 0}
3998+
m_PrefabInstance: {fileID: 0}
3999+
m_PrefabAsset: {fileID: 0}
4000+
serializedVersion: 6
4001+
m_Component:
4002+
- component: {fileID: 1843937916}
4003+
- component: {fileID: 1843937918}
4004+
- component: {fileID: 1843937917}
4005+
m_Layer: 5
4006+
m_Name: MagicLinkText
4007+
m_TagString: Untagged
4008+
m_Icon: {fileID: 0}
4009+
m_NavMeshLayer: 0
4010+
m_StaticEditorFlags: 0
4011+
m_IsActive: 1
4012+
--- !u!224 &1843937916
4013+
RectTransform:
4014+
m_ObjectHideFlags: 0
4015+
m_CorrespondingSourceObject: {fileID: 0}
4016+
m_PrefabInstance: {fileID: 0}
4017+
m_PrefabAsset: {fileID: 0}
4018+
m_GameObject: {fileID: 1843937915}
4019+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
4020+
m_LocalPosition: {x: 0, y: 0, z: 0}
4021+
m_LocalScale: {x: 1, y: 1, z: 1}
4022+
m_ConstrainProportionsScale: 0
4023+
m_Children: []
4024+
m_Father: {fileID: 765549957}
4025+
m_RootOrder: 0
4026+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
4027+
m_AnchorMin: {x: 0, y: 0}
4028+
m_AnchorMax: {x: 1, y: 1}
4029+
m_AnchoredPosition: {x: 0, y: -1.5}
4030+
m_SizeDelta: {x: -4, y: -7}
4031+
m_Pivot: {x: 0.5, y: 0.5}
4032+
--- !u!114 &1843937917
4033+
MonoBehaviour:
4034+
m_ObjectHideFlags: 0
4035+
m_CorrespondingSourceObject: {fileID: 0}
4036+
m_PrefabInstance: {fileID: 0}
4037+
m_PrefabAsset: {fileID: 0}
4038+
m_GameObject: {fileID: 1843937915}
4039+
m_Enabled: 1
4040+
m_EditorHideFlags: 0
4041+
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
4042+
m_Name:
4043+
m_EditorClassIdentifier:
4044+
m_Material: {fileID: 0}
4045+
m_Color: {r: 0, g: 0, b: 0, a: 1}
4046+
m_RaycastTarget: 1
4047+
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
4048+
m_Maskable: 1
4049+
m_OnCullStateChanged:
4050+
m_PersistentCalls:
4051+
m_Calls: []
4052+
m_FontData:
4053+
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
4054+
m_FontSize: 14
4055+
m_FontStyle: 0
4056+
m_BestFit: 1
4057+
m_MinSize: 10
4058+
m_MaxSize: 40
4059+
m_Alignment: 4
4060+
m_AlignByGeometry: 0
4061+
m_RichText: 1
4062+
m_HorizontalOverflow: 0
4063+
m_VerticalOverflow: 0
4064+
m_LineSpacing: 1
4065+
m_Text: Magic.link
4066+
--- !u!222 &1843937918
4067+
CanvasRenderer:
4068+
m_ObjectHideFlags: 0
4069+
m_CorrespondingSourceObject: {fileID: 0}
4070+
m_PrefabInstance: {fileID: 0}
4071+
m_PrefabAsset: {fileID: 0}
4072+
m_GameObject: {fileID: 1843937915}
4073+
m_CullTransparentMesh: 1
38604074
--- !u!1 &1891838640
38614075
GameObject:
38624076
m_ObjectHideFlags: 0
@@ -4022,6 +4236,7 @@ RectTransform:
40224236
- {fileID: 633987595}
40234237
- {fileID: 259715464}
40244238
- {fileID: 1114040581}
4239+
- {fileID: 765549957}
40254240
m_Father: {fileID: 223974230}
40264241
m_RootOrder: 0
40274242
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

‎Assets/Thirdweb/Demo/ThirdwebSDKDemos.cs

+30-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ public void WalletConnectLogin()
4343
ConnectWallet(WalletProvider.WalletConnect);
4444
}
4545

46+
public void MagicAuthLogin()
47+
{
48+
// Requires passing a magic.link API key in the SDK options:
49+
// sdk = new ThirdwebSDK("goerli", new ThirdwebSDK.Options()
50+
// {
51+
// wallet = new ThirdwebSDK.WalletOptions()
52+
// {
53+
// appName = "Thirdweb SDK Demo",
54+
// extras = new Dictionary<string, object>()
55+
// {
56+
// {"apiKey", "your_api_key"}
57+
// }
58+
// }
59+
// });
60+
ConnectWallet(WalletProvider.MagicAuth);
61+
}
62+
4663
public async void DisconnectWallet()
4764
{
4865
await sdk.wallet.Disconnect();
@@ -55,19 +72,26 @@ private async void ConnectWallet(WalletProvider provider)
5572
connectButtonsContainer.SetActive(false);
5673
walletInfoContainer.SetActive(true);
5774
walletInfotext.text = "Connecting...";
58-
string address = await sdk.wallet.Connect(new WalletConnection()
75+
try
5976
{
60-
provider = provider,
61-
chainId = 5 // Switch the wallet Goerli on connection
62-
});
63-
walletInfotext.text = "Connected as: " + address;
77+
string address = await sdk.wallet.Connect(new WalletConnection()
78+
{
79+
provider = provider,
80+
chainId = 5 // Switch the wallet Goerli on connection
81+
});
82+
walletInfotext.text = "Connected as: " + address;
83+
}
84+
catch (System.Exception e)
85+
{
86+
walletInfotext.text = "Error (see console): " + e.Message;
87+
}
6488
}
6589

6690
public async void OnBalanceClick()
6791
{
6892
resultText.text = "Loading...";
6993
CurrencyValue balance = await sdk.wallet.GetBalance();
70-
resultText.text = "Balance: " + balance.displayValue.Substring(0, 3) + " " + balance.symbol;
94+
resultText.text = "Balance: " + balance.displayValue.Substring(0, 5) + " " + balance.symbol;
7195
}
7296

7397
public async void OnSignClick()

‎Assets/Thirdweb/Scripts/ThirdwebSDK.cs

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.Threading.Tasks;
23

34
namespace Thirdweb
@@ -13,9 +14,28 @@ public class ThirdwebSDK
1314
[System.Serializable]
1415
public struct Options
1516
{
16-
public string appName;
1717
public GaslessOptions? gasless;
18-
public string ipfsGatewayUrl;
18+
public StorageOptions? storage;
19+
public WalletOptions? wallet;
20+
}
21+
22+
/// <summary>
23+
/// Wallet configuration options.
24+
/// </summary>
25+
[System.Serializable]
26+
public struct WalletOptions
27+
{
28+
public string appName; // the app name that will show in different wallet providers
29+
public Dictionary<string, object> extras; // extra data to pass to the wallet provider
30+
}
31+
32+
/// <summary>
33+
/// Storage configuration options.
34+
/// </summary>
35+
[System.Serializable]
36+
public struct StorageOptions
37+
{
38+
public string ipfsGatewayUrl; // override the default ipfs gateway, should end in /ipfs/
1939
}
2040

2141
/// <summary>
@@ -83,14 +103,5 @@ public Contract GetContract(string address, string abi = null)
83103
{
84104
return new Contract(this.chainOrRPC, address, abi);
85105
}
86-
87-
/// <summary>
88-
/// Prompt the user to fund their wallet using one of the thirdweb pay providers (defaults to Coinbase Pay).
89-
/// </summary>
90-
/// <param name="options">The options like wallet address to fund, on which chain, etc</param>
91-
public async Task FundWallet(FundWalletOptions options)
92-
{
93-
await Bridge.FundWallet(options);
94-
}
95106
}
96107
}

‎Assets/Thirdweb/Scripts/Wallet.cs

+14
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ public async Task<TransactionResult> SendRawTransaction(TransactionRequest trans
113113
{
114114
return await Bridge.InvokeRoute<TransactionResult>(getRoute("sendRawTransaction"), Utils.ToJsonStringArray(transactionRequest));
115115
}
116+
117+
/// <summary>
118+
/// Prompt the user to fund their wallet using one of the thirdweb pay providers (defaults to Coinbase Pay).
119+
/// </summary>
120+
/// <param name="options">The options like wallet address to fund, on which chain, etc</param>
121+
public async Task FundWallet(FundWalletOptions options)
122+
{
123+
if (options.address == null)
124+
{
125+
options.address = await GetAddress();
126+
}
127+
await Bridge.FundWallet(options);
128+
}
116129
}
117130

118131
public struct WalletConnection
@@ -131,6 +144,7 @@ public class WalletProvider
131144
public static WalletProvider CoinbaseWallet { get { return new WalletProvider("coinbaseWallet"); } }
132145
public static WalletProvider WalletConnect { get { return new WalletProvider("walletConnect"); } }
133146
public static WalletProvider Injected { get { return new WalletProvider("injected"); } }
147+
public static WalletProvider MagicAuth { get { return new WalletProvider("magicAuth"); } }
134148

135149
public override string ToString()
136150
{

‎Assets/WebGLTemplates/Thirdweb/lib/thirdweb-unity-bridge.js

+696-82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.