Skip to content

Commit 7c66485

Browse files
Added remove federated account intent and corresponding test (#292)
* Added remove federated account intent and corresponding test * Fix intellisence summary
1 parent be4084e commit 7c66485

File tree

10 files changed

+149
-0
lines changed

10 files changed

+149
-0
lines changed

Assets/SequenceSDK/WaaS/Tests/MockWaaSWallet.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,11 @@ public string GetEmail()
105105
{
106106
throw new NotImplementedException();
107107
}
108+
109+
public event Action<string, bool> OnFederatedAccountRemovedComplete;
110+
public Task<bool> RemoveFederatedAccount(Account account)
111+
{
112+
throw new NotImplementedException();
113+
}
108114
}
109115
}

Assets/SequenceSDK/WaaS/Tests/WaaSFederatedAuthTests.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class WaaSFederatedAuthTests
1515
private TaskCompletionSource<bool> _tcs;
1616
private string _walletAddress;
1717
SequenceLogin _login;
18+
private IWallet _wallet;
19+
private Account _federatedAccount;
1820

1921
[Test]
2022
public async Task TestAccountAssociation()
@@ -152,5 +154,73 @@ private void OnAccountFederated(Account account)
152154
_tcs.SetResult(true);
153155
SequenceWallet.OnAccountFederated -= OnAccountFederated;
154156
}
157+
158+
[Test]
159+
public async Task TestRemoveFederatedAccount()
160+
{
161+
_login = SequenceLogin.GetInstance();
162+
SequenceWallet.OnAccountFederated += OnAccountFederatedBeforeDeletion;
163+
_tcs = new TaskCompletionSource<bool>();
164+
EndToEndTestHarness testHarness = new EndToEndTestHarness(_login);
165+
166+
await testHarness.Login(async wallet =>
167+
{
168+
_wallet = wallet;
169+
try
170+
{
171+
_walletAddress = wallet.GetWalletAddress();
172+
_email = WaaSEndToEndTestConfig.GetConfig().PlayFabEmail;
173+
string titleId = WaaSEndToEndTestConfig.GetConfig().PlayFabTitleId;
174+
175+
if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.TitleId))
176+
{
177+
PlayFabSettings.staticSettings.TitleId = titleId;
178+
}
179+
180+
var request = new LoginWithEmailAddressRequest
181+
{
182+
Email = _email,
183+
Password = WaaSEndToEndTestConfig.GetConfig().PlayFabPassword
184+
};
185+
PlayFabClientAPI.LoginWithEmailAddress(request, PlayFabLoginResult, PlayFabLoginFailed);
186+
}
187+
catch (Exception e)
188+
{
189+
_tcs.TrySetException(e);
190+
}
191+
}, (error, method, email, methods) =>
192+
{
193+
_tcs.TrySetException(new Exception(error));
194+
});
195+
196+
await _tcs.Task;
197+
}
198+
199+
private void OnAccountFederatedBeforeDeletion(Account account)
200+
{
201+
if (account.email != _email.ToLower())
202+
{
203+
_tcs.TrySetException(new Exception($"Emails do not match {_email} != {account.email}"));
204+
}
205+
SequenceWallet.OnAccountFederated -= OnAccountFederatedBeforeDeletion;
206+
207+
_wallet.OnFederatedAccountRemovedComplete += OnFederatedAccountRemoved;
208+
_federatedAccount = account;
209+
_wallet.RemoveFederatedAccount(account);
210+
}
211+
212+
private void OnFederatedAccountRemoved(string accountId, bool success)
213+
{
214+
if (accountId == _federatedAccount.id)
215+
{
216+
_tcs.SetResult(true);
217+
}
218+
else
219+
{
220+
_tcs.TrySetException(new Exception($"Account ids do not match {_federatedAccount.id} != {accountId}"));
221+
}
222+
223+
_wallet.OnFederatedAccountRemovedComplete -= OnFederatedAccountRemoved;
224+
}
155225
}
156226
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using UnityEngine.Scripting;
3+
4+
namespace Sequence.EmbeddedWallet
5+
{
6+
[Serializable]
7+
internal class IntentDataRemoveAccount
8+
{
9+
public string accountId;
10+
public string wallet;
11+
12+
[Preserve]
13+
public IntentDataRemoveAccount(string wallet, string accountId)
14+
{
15+
this.wallet = wallet;
16+
this.accountId = accountId;
17+
}
18+
}
19+
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataRemoveAccount.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentPayload.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public IntentPayload(string version, IntentType type, JObject data, Signature[]
7171
{IntentType.FederateAccount, "federateAccount"},
7272
{IntentType.ListAccounts, "listAccounts"},
7373
{IntentType.GetIdToken, "getIdToken"},
74+
{IntentType.RemoveAccount, "removeAccount"},
7475
};
7576
}
7677

@@ -91,6 +92,7 @@ public enum IntentType
9192
FederateAccount,
9293
ListAccounts,
9394
GetIdToken,
95+
RemoveAccount,
9496
None
9597
}
9698
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace Sequence.EmbeddedWallet
4+
{
5+
[Serializable]
6+
public class IntentResponseAccountRemoved
7+
{
8+
9+
}
10+
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountRemoved.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/EOAWalletToSequenceWalletAdapter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ public string GetEmail()
324324
{
325325
throw new NotSupportedException();
326326
}
327+
328+
public event Action<string, bool> OnFederatedAccountRemovedComplete;
329+
public Task<bool> RemoveFederatedAccount(Account account)
330+
{
331+
throw new NotSupportedException();
332+
}
327333
}
328334
#endregion
329335

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/IWallet.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,16 @@ public Task<TransactionReturn> SendTransactionWithFeeOptions(Chain network, Tran
172172
/// </summary>
173173
/// <returns></returns>
174174
public string GetEmail();
175+
176+
public event Action<string, bool> OnFederatedAccountRemovedComplete;
177+
178+
/// <summary>
179+
/// Remove a federated account association
180+
///
181+
/// Can be awaited directly and/or you can subscribe to the OnFederatedAccountRemovedComplete event
182+
/// </summary>
183+
/// <param name="dropSessionId"></param>
184+
/// <returns></returns>
185+
public Task<bool> RemoveFederatedAccount(Account account);
175186
}
176187
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceWallet.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,5 +463,24 @@ public string GetEmail()
463463
{
464464
return _email;
465465
}
466+
467+
public event Action<string, bool> OnFederatedAccountRemovedComplete;
468+
public async Task<bool> RemoveFederatedAccount(Account account)
469+
{
470+
IntentDataRemoveAccount args = new IntentDataRemoveAccount(account.wallet, account.id);
471+
try
472+
{
473+
var response =
474+
await _intentSender.SendIntent<IntentResponseAccountRemoved, IntentDataRemoveAccount>(args,
475+
IntentType.RemoveAccount);
476+
OnFederatedAccountRemovedComplete?.Invoke(account.id, true);
477+
return true;
478+
}
479+
catch (Exception e)
480+
{
481+
OnFederatedAccountRemovedComplete?.Invoke($"Failed to remove federated account with id {account.id}, reason: {e.Message}", false);
482+
return false;
483+
}
484+
}
466485
}
467486
}

0 commit comments

Comments
 (0)