Skip to content

Commit d3bfc54

Browse files
authored
Merge pull request #314 from 0xsequence/quickstart-assembly
Added EmbeddedWalletAdapter for quickstart integrations
2 parents 637e610 + da10296 commit d3bfc54

File tree

27 files changed

+763
-252
lines changed

27 files changed

+763
-252
lines changed

Assets/SequenceSDK/Authentication/Tests/MockLogin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void TryToRestoreSession()
9191

9292
}
9393

94-
public void GuestLogin()
94+
public Task GuestLogin()
9595
{
9696
throw new System.NotImplementedException();
9797
}

Assets/SequenceSDK/Authentication/Tests/MockLoginCustomEventTiming.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void TryToRestoreSession()
8080

8181
}
8282

83-
public void GuestLogin()
83+
public Task GuestLogin()
8484
{
8585
throw new System.NotImplementedException();
8686
}

Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/BoilerplateFactory.cs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,77 +30,68 @@ public static void CleanUp()
3030
/// Open the Login UI Boilerplate from a Prefab inside the Resources folder.
3131
/// </summary>
3232
/// <param name="parent">Transform inside of a Canvas object.</param>
33-
/// <param name="wallet">Wallet to use for account federation.</param>
3433
/// <param name="onClose">(Optional) Callback when the user closes this window or when an account was successfully federated.</param>
3534
/// <returns></returns>
36-
public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, IWallet wallet = null, Action onClose = null)
35+
public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, Action onClose = null)
3736
{
3837
return GetOrSpawnBoilerplate<SequenceLoginWindow>("Login/SequenceLoginWindow", parent,
39-
b => b.Show(wallet, onClose));
38+
b => b.Show(onClose));
4039
}
4140

4241
/// <summary>
4342
/// Open the Player Profile UI Boilerplate from a Prefab inside the Resources folder.
4443
/// </summary>
4544
/// <param name="parent">Transform inside of a Canvas object.</param>
46-
/// <param name="wallet">This Wallet instance will perform transactions.</param>
47-
/// <param name="chain">Chain used to get balances and send transactions.</param>
4845
/// <param name="currency">Define a custom ERC20 currency. Leave it null to use the chains native token.</param>
4946
/// <param name="currencySymbol">The symbol of your custom currency, such as 'ETH'.</param>
5047
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
5148
/// <returns>Instance of SequencePlayerProfile which was instantiated as a child of <paramref name="parent"/></returns>
52-
public static SequencePlayerProfile OpenSequencePlayerProfile(Transform parent, IWallet wallet, Chain chain, Address currency = null, string currencySymbol = null, Action onClose = null)
49+
public static SequencePlayerProfile OpenSequencePlayerProfile(Transform parent, Address currency = null, string currencySymbol = null, Action onClose = null)
5350
{
5451
return GetOrSpawnBoilerplate<SequencePlayerProfile>("PlayerProfile/SequencePlayerProfile", parent,
55-
b => b.Show(wallet, chain, currency, currencySymbol, onClose));
52+
b => b.Show(currency, currencySymbol, onClose));
5653
}
5754

5855
/// <summary>
5956
/// Open the Daily Rewards UI Boilerplate from a Prefab inside the Resources folder.
6057
/// </summary>
6158
/// <param name="parent">Transform inside of a Canvas object.</param>
62-
/// <param name="wallet">This Wallet instance will perform transactions.</param>
63-
/// <param name="chain">Chain used to get balances and send transactions.</param>
6459
/// <param name="apiUrl">API Url you deployed using the server boilerplate.</param>
6560
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
6661
/// <returns>Instance of SequenceDailyRewards which was instantiated as a child of <paramref name="parent"/></returns>
67-
public static SequenceDailyRewards OpenSequenceDailyRewards(Transform parent, IWallet wallet, Chain chain, string apiUrl, Action onClose = null)
62+
public static SequenceDailyRewards OpenSequenceDailyRewards(Transform parent, string apiUrl, Action onClose = null)
6863
{
6964
return GetOrSpawnBoilerplate<SequenceDailyRewards>("DailyRewards/SequenceDailyRewards", parent,
70-
b => b.Show(wallet, chain, apiUrl, onClose));
65+
b => b.Show(apiUrl, onClose));
7166
}
7267

7368
/// <summary>
7469
/// Open the Inventory UI Boilerplate from a Prefab inside the Resources folder.
7570
/// </summary>
7671
/// <param name="parent">Transform inside of a Canvas object.</param>
77-
/// <param name="wallet">This Wallet instance will perform transactions.</param>
78-
/// <param name="chain">Chain used to get balances and send transactions.</param>
7972
/// <param name="collections">The inventory will show items from these contracts.</param>
8073
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
8174
/// <returns>Instance of SequenceInventory which was instantiated as a child of <paramref name="parent"/></returns>
82-
public static SequenceInventory OpenSequenceInventory(Transform parent, IWallet wallet, Chain chain, string[] collections, Action onClose = null)
75+
public static SequenceInventory OpenSequenceInventory(Transform parent, string[] collections, Action onClose = null)
8376
{
8477
return GetOrSpawnBoilerplate<SequenceInventory>("Inventory/SequenceInventory", parent,
85-
b => b.Show(wallet, chain, collections, onClose));
78+
b => b.Show(collections, onClose));
8679
}
8780

8881
/// <summary>
8982
/// Open the In-Game Shop UI Boilerplate from a Prefab inside the Resources folder.
9083
/// </summary>
9184
/// <param name="parent">Transform inside of a Canvas object.</param>
92-
/// <param name="wallet">This Wallet instance will perform transactions.</param>
93-
/// <param name="chain">Chain used to get balances and send transactions.</param>
9485
/// <param name="tokenContractAddress">ERC1155 Contract you deployed on Sequence's Builder.</param>
9586
/// <param name="saleContractAddress">ERC1155 Sale Contract you deployed on Sequence's Builder.</param>
9687
/// <param name="itemsForSale">Define the token Ids you want to sell from your collection.</param>
9788
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
9889
/// <returns>Instance of SequenceInGameShop which was instantiated as a child of <paramref name="parent"/></returns>
99-
public static SequenceInGameShop OpenSequenceInGameShop(Transform parent, IWallet wallet, Chain chain,
100-
string tokenContractAddress, string saleContractAddress, int[] itemsForSale, Action onClose = null)
90+
public static SequenceInGameShop OpenSequenceInGameShop(Transform parent, string tokenContractAddress,
91+
string saleContractAddress, int[] itemsForSale, Action onClose = null)
10192
{
10293
return GetOrSpawnBoilerplate<SequenceInGameShop>("InGameShop/SequenceInGameShop", parent,
103-
b => b.Show(wallet, chain, tokenContractAddress, saleContractAddress, itemsForSale, onClose));
94+
b => b.Show(tokenContractAddress, saleContractAddress, itemsForSale, onClose));
10495
}
10596

10697
/// <summary>
@@ -138,9 +129,7 @@ public static ListItemPage OpenListItemPanel(Transform parent, ICheckout checkou
138129
{
139130
return GetOrSpawnBoilerplate<ListItemPage>("Checkout/ListItemPanel", parent, b => b.Open(checkout, item));
140131
}
141-
142-
143-
132+
144133
public static CreateOfferPage OpenCreateOfferPanel(Transform parent, ICheckout checkout, TokenBalance item, Action onClose = null)
145134
{
146135
return GetOrSpawnBoilerplate<CreateOfferPage>("Checkout/CreateOfferPanel", parent, b => b.Open(checkout, item));
@@ -162,10 +151,10 @@ public static SellOfferPage OpenSellOfferPanel(Transform parent, ICheckout check
162151
/// <param name="chain">Chain used to get balances and send transactions.</param>
163152
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
164153
/// <returns>Instance of SequenceSignMessage which was instantiated as a child of <paramref name="parent"/></returns>
165-
public static SequenceSignMessage OpenSequenceSignMessage(Transform parent, IWallet wallet, Chain chain, Action onClose = null)
154+
public static SequenceSignMessage OpenSequenceSignMessage(Transform parent, Action onClose = null)
166155
{
167156
return GetOrSpawnBoilerplate<SequenceSignMessage>("SignMessage/SequenceSignMessage", parent,
168-
b => b.Show(wallet, chain, onClose));
157+
b => b.Show(onClose));
169158
}
170159

171160
private static T GetOrSpawnBoilerplate<T>(string path, Transform parent, Action<T> show) where T : MonoBehaviour

Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/BoilerplateController.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Text;
33
using Newtonsoft.Json;
4+
using Sequence.Adapter;
45
using Sequence.Boilerplates.Login;
56
using Sequence.Boilerplates.PlayerProfile;
67
using Sequence.Contracts;
@@ -30,7 +31,8 @@ public class BoilerplateController : MonoBehaviour
3031
[SerializeField] private string _marketplaceDescription = "Browse and interact with listings on a Peer-to-Peer, Secondary Sales marketplace.";
3132
[SerializeField] private string _checkoutDescription = "Buy an ERC1155 token via a Primary Sales contract using the Checkout Panel - pay with crypto or fiat.";
3233

33-
private IWallet _wallet;
34+
private EmbeddedWalletAdapter _adapter;
35+
3436
private SequenceLoginWindow _loginWindow;
3537
private SequencePlayerProfile _playerProfile;
3638
private Chain _chain;
@@ -40,10 +42,8 @@ public class BoilerplateController : MonoBehaviour
4042

4143
private void Awake()
4244
{
43-
SequenceWallet.OnFailedToRecoverSession += OnFailedToRecoverSession;
4445
SequenceWallet.OnWalletCreated += wallet =>
4546
{
46-
_wallet = wallet;
4747
ShowDefaultWindow();
4848

4949
if (_loginWindow)
@@ -60,6 +60,8 @@ private void Awake()
6060
}
6161
};
6262
};
63+
64+
_adapter = EmbeddedWalletAdapter.GetInstance();
6365
}
6466

6567
private void Start()
@@ -100,9 +102,8 @@ private async void TryRecoverSessionToOpenLoginWindow()
100102
{
101103
HideFeatureSelection();
102104

103-
var loginHandler = SequenceLogin.GetInstance();
104-
var (storageEnabled, wallet) = await loginHandler.TryToRestoreSessionAsync();
105-
if (!storageEnabled)
105+
var recovered = await _adapter.TryRecoverWalletFromStorage();
106+
if (!recovered)
106107
OnFailedToRecoverSession("Secure storage is disabled");
107108
}
108109

@@ -211,32 +212,32 @@ private void ShowPrimarySaleButton(PrimarySaleConfig sale)
211212
private void OpenPlayerProfilePanel()
212213
{
213214
HideFeatureSelection();
214-
_playerProfile = BoilerplateFactory.OpenSequencePlayerProfile(transform, _wallet, _chain, new Address("0x85acb5646a9d73952347174ef928c2c9a174156f"), "STB", ShowDefaultWindow);
215+
_playerProfile = BoilerplateFactory.OpenSequencePlayerProfile(transform, new Address("0x85acb5646a9d73952347174ef928c2c9a174156f"), "STB", ShowDefaultWindow);
215216
}
216217

217218
private void OpenDailyRewardsPanel()
218219
{
219220
HideFeatureSelection();
220-
BoilerplateFactory.OpenSequenceDailyRewards(transform, _wallet, _chain, _config.rewardsApi, ShowDefaultWindow);
221+
BoilerplateFactory.OpenSequenceDailyRewards(transform, _config.rewardsApi, ShowDefaultWindow);
221222
}
222223

223224
private void OpenInventoryPanel()
224225
{
225226
HideFeatureSelection();
226-
BoilerplateFactory.OpenSequenceInventory(transform, _wallet, _chain, _config.collections, ShowDefaultWindow);
227+
BoilerplateFactory.OpenSequenceInventory(transform, _config.collections, ShowDefaultWindow);
227228
}
228229

229230
private void OpenInGameShopPanel(PrimarySaleConfig sale)
230231
{
231232
HideFeatureSelection();
232-
BoilerplateFactory.OpenSequenceInGameShop(transform, _wallet, _chain, sale.collectionAddress,
233+
BoilerplateFactory.OpenSequenceInGameShop(transform, sale.collectionAddress,
233234
sale.saleAddress, sale.itemsForSale, ShowDefaultWindow);
234235
}
235236

236237
private void OpenSignMessage()
237238
{
238239
HideFeatureSelection();
239-
BoilerplateFactory.OpenSequenceSignMessage(transform, _wallet, _chain, ShowDefaultWindow);
240+
BoilerplateFactory.OpenSequenceSignMessage(transform, ShowDefaultWindow);
240241
}
241242

242243
public void OpenCheckoutPanel(ICheckoutHelper checkoutHelper, IFiatCheckout fiatCheckout)
@@ -248,7 +249,7 @@ public void OpenCheckoutPanel(ICheckoutHelper checkoutHelper, IFiatCheckout fiat
248249
public void OpenViewMarketplaceListingsPage()
249250
{
250251
HideFeatureSelection();
251-
BoilerplateFactory.OpenViewMarketplaceListingsPanel(transform, _wallet, _marketplaceChain, new Address(_marketplaceCollectionAddress), ShowDefaultWindow);
252+
BoilerplateFactory.OpenViewMarketplaceListingsPanel(transform, _adapter.Wallet, _marketplaceChain, new Address(_marketplaceCollectionAddress), ShowDefaultWindow);
252253
}
253254

254255
public void OpenCheckoutPanel()
@@ -288,13 +289,13 @@ private async void DoShowCheckoutPanel()
288289
string imageUrl = metadata.image.Replace(".webp", ".png");
289290
Sprite collectibleImage = await AssetHandler.GetSpriteAsync(imageUrl);
290291
ICheckoutHelper checkoutHelper = await ERC1155SaleCheckout.Create(saleContract, collection, "1", 1, Chain.Polygon,
291-
_wallet, "Demo Token Sale",
292+
_adapter.Wallet, "Demo Token Sale",
292293
"https://cryptologos.cc/logos/usd-coin-usdc-logo.png",
293294
collectibleImage);
294295

295296
HideLoadingScreen();
296297
BoilerplateFactory.OpenCheckoutPanel(transform, _chain, checkoutHelper,
297-
new SequenceCheckout(_wallet, Chain.Polygon, saleContract, collection, "1", 1), ShowDefaultWindow);
298+
new SequenceCheckout(_adapter.Wallet, Chain.Polygon, saleContract, collection, "1", 1), ShowDefaultWindow);
298299
}
299300
}
300301
}

Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/DailyRewards/SequenceDailyRewards.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Newtonsoft.Json;
6+
using Sequence.Adapter;
67
using Sequence.EmbeddedWallet;
78
using Sequence.Utils;
89
using UnityEngine;
@@ -18,13 +19,18 @@ public class SequenceDailyRewards : MonoBehaviour
1819
[SerializeField] private MessagePopup _messagePopup;
1920
[SerializeField] private GenericObjectPool<SequenceDailyRewardTile> _tilePool;
2021

21-
private IWallet _wallet;
22-
private Chain _chain;
22+
private EmbeddedWalletAdapter _adapter;
23+
2324
private string _apiUrl;
2425
private Action _onClose;
2526
private DailyRewardsStatusData _rewardsData;
2627
private Dictionary<string, TokenSupply[]> _supplies;
2728

29+
private void Awake()
30+
{
31+
_adapter = EmbeddedWalletAdapter.GetInstance();
32+
}
33+
2834
/// <summary>
2935
/// This function is called when the user clicks the close button.
3036
/// </summary>
@@ -41,10 +47,8 @@ public void Hide()
4147
/// <param name="chain">Chain used to get balances and send transactions.</param>
4248
/// <param name="apiUrl">API Url you deployed using the server boilerplate.</param>
4349
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
44-
public void Show(IWallet wallet, Chain chain, string apiUrl, Action onClose = null)
50+
public void Show(string apiUrl, Action onClose = null)
4551
{
46-
_wallet = wallet;
47-
_chain = chain;
4852
_apiUrl = apiUrl;
4953
_onClose = onClose;
5054
gameObject.SetActive(true);
@@ -98,8 +102,8 @@ private async Task<bool> CallRewardsAsync(string method)
98102
var request = UnityWebRequest.Get(_apiUrl);
99103
request.method = method;
100104

101-
var idToken = await _wallet.GetIdToken();
102-
request.SetRequestHeader("Authorization", $"Bearer {idToken.IdToken}");
105+
var idToken = await _adapter.GetIdToken();
106+
request.SetRequestHeader("Authorization", $"Bearer {idToken}");
103107

104108
try
105109
{
@@ -127,7 +131,7 @@ private async Task<bool> CallRewardsAsync(string method)
127131
.Distinct()
128132
.ToArray());
129133

130-
var indexer = new ChainIndexer(_chain);
134+
var indexer = new ChainIndexer(_adapter.Chain);
131135
var args = new GetTokenSuppliesMapArgs
132136
{
133137
tokenMap = dict,

0 commit comments

Comments
 (0)