Skip to content

Commit 5d227ee

Browse files
Feature/get account list (#166)
* Added get account list intent - this allows a user to check the accounts/login methods associated with a wallet address; useful for account federation * increment package version
1 parent ced06ba commit 5d227ee

File tree

11 files changed

+107
-3
lines changed

11 files changed

+107
-3
lines changed

Assets/SequenceSDK/WaaS/Tests/MockWaaSWallet.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,12 @@ public Task<IntentResponseSessionAuthProof> GetSessionAuthProof(Chain network, s
8282
{
8383
throw new NotImplementedException();
8484
}
85+
86+
public event Action<IntentResponseAccountList> OnAccountListGenerated;
87+
public event Action<string> OnFailedToGenerateAccountList;
88+
public Task<IntentResponseAccountList> GetAccountList()
89+
{
90+
throw new NotImplementedException();
91+
}
8592
}
8693
}

Assets/SequenceSDK/WaaS/Tests/WaaSSessionManagementTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,35 @@ public async Task TestGetSessionAuthProof()
127127

128128
await tcs.Task;
129129
}
130+
131+
[Test]
132+
public async Task TestListAccounts()
133+
{
134+
var tcs = new TaskCompletionSource<bool>();
135+
EndToEndTestHarness testHarness = new EndToEndTestHarness();
136+
137+
testHarness.Login(async wallet =>
138+
{
139+
try
140+
{
141+
IntentResponseAccountList list = await wallet.GetAccountList();
142+
Assert.IsNotNull(list);
143+
Assert.False(string.IsNullOrWhiteSpace(list.currentAccountId));
144+
Assert.IsNotNull(list.accounts);
145+
Assert.Greater(list.accounts.Length, 0);
146+
147+
tcs.TrySetResult(true);
148+
}
149+
catch (System.Exception e)
150+
{
151+
tcs.TrySetException(e);
152+
}
153+
}, (error, method, email, methods) =>
154+
{
155+
tcs.TrySetException(new Exception(error));
156+
});
157+
158+
await tcs.Task;
159+
}
130160
}
131161
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace Sequence.EmbeddedWallet
5+
{
6+
[Serializable]
7+
public class IntentDataListAccounts
8+
{
9+
public string wallet;
10+
11+
public IntentDataListAccounts(string walletAddress)
12+
{
13+
this.wallet = walletAddress;
14+
}
15+
}
16+
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ParameterTypes/IntentDataListAccounts.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
@@ -66,6 +66,7 @@ public IntentPayload(string version, IntentType type, JObject data, Signature[]
6666
{IntentType.SessionAuthProof, "sessionAuthProof"},
6767
{IntentType.InitiateAuth, "initiateAuth"},
6868
{IntentType.FederateAccount, "federateAccount"},
69+
{IntentType.ListAccounts, "listAccounts"},
6970
};
7071
}
7172

@@ -84,6 +85,7 @@ public enum IntentType
8485
SessionAuthProof,
8586
InitiateAuth,
8687
FederateAccount,
88+
ListAccounts,
8789
None
8890
}
8991
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/Account.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ public class Account
66
public IdentityType identityType;
77
public string issuer;
88

9-
public Account(string id, string identityType, string issuer, string email)
9+
public Account(string id, string type, string issuer, string email)
1010
{
1111
this.id = id;
12-
this.identityType = identityType.GetIdentityType();
12+
this.identityType = type.GetIdentityType();
1313
this.issuer = issuer;
1414
this.email = email;
1515
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Sequence.EmbeddedWallet
2+
{
3+
public class IntentResponseAccountList
4+
{
5+
public Account[] accounts;
6+
public string currentAccountId;
7+
8+
public IntentResponseAccountList(Account[] accounts, string currentAccountId)
9+
{
10+
this.accounts = accounts;
11+
this.currentAccountId = currentAccountId;
12+
}
13+
}
14+
}

Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/DataTypes/ReturnTypes/IntentResponseAccountList.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/IWallet.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,16 @@ public Task<TransactionReturn> SendTransactionWithFeeOptions(Chain network, Tran
144144
/// <param name="nonce"></param>
145145
/// <returns></returns>
146146
public Task<IntentResponseSessionAuthProof> GetSessionAuthProof(Chain network, string nonce = null);
147+
148+
public event Action<IntentResponseAccountList> OnAccountListGenerated;
149+
public event Action<string> OnFailedToGenerateAccountList;
150+
151+
/// <summary>
152+
/// Get a list of Accounts associated with this wallet
153+
///
154+
/// Can be awaited directly or you can subscribe to the OnAccountListGenerated and OnFailedToGenerateAccountList events to get success and failed responses respectively
155+
/// </summary>
156+
/// <returns></returns>
157+
public Task<IntentResponseAccountList> GetAccountList();
147158
}
148159
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,5 +392,23 @@ public async Task<IntentResponseSessionAuthProof> GetSessionAuthProof(Chain netw
392392
return null;
393393
}
394394
}
395+
396+
public event Action<IntentResponseAccountList> OnAccountListGenerated;
397+
public event Action<string> OnFailedToGenerateAccountList;
398+
399+
public async Task<IntentResponseAccountList> GetAccountList()
400+
{
401+
try
402+
{
403+
var result = await _intentSender.SendIntent<IntentResponseAccountList, IntentDataListAccounts>(new IntentDataListAccounts(_address), IntentType.ListAccounts);
404+
OnAccountListGenerated?.Invoke(result);
405+
return result;
406+
}
407+
catch (Exception e)
408+
{
409+
OnFailedToGenerateAccountList?.Invoke("Failed to generate account list: " + e.Message);
410+
return null;
411+
}
412+
}
395413
}
396414
}

0 commit comments

Comments
 (0)