Skip to content

Commit bc78eff

Browse files
committed
PlayerProfile can show custom erc20 currency
1 parent a8beac9 commit bc78eff

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, IWal
4545
/// <param name="parent">Transform inside of a Canvas object.</param>
4646
/// <param name="wallet">This Wallet instance will perform transactions.</param>
4747
/// <param name="chain">Chain used to get balances and send transactions.</param>
48-
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
4948
/// <param name="currency">Define a custom ERC20 currency. Leave it null to use the chains native token.</param>
49+
/// <param name="currencySymbol">The symbol of your custom currency, such as 'ETH'.</param>
50+
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
5051
/// <returns>Instance of SequencePlayerProfile which was instantiated as a child of <paramref name="parent"/></returns>
51-
public static SequencePlayerProfile OpenSequencePlayerProfile(Transform parent, IWallet wallet, Chain chain, Address currency, Action onClose = null)
52+
public static SequencePlayerProfile OpenSequencePlayerProfile(Transform parent, IWallet wallet, Chain chain, Address currency = null, string currencySymbol = null, Action onClose = null)
5253
{
5354
return GetOrSpawnBoilerplate<SequencePlayerProfile>("PlayerProfile/SequencePlayerProfile", parent,
54-
b => b.Show(wallet, chain, currency, onClose));
55+
b => b.Show(wallet, chain, currency, currencySymbol, onClose));
5556
}
5657

5758
/// <summary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private void ShowPrimarySaleButton(PrimarySaleConfig sale)
211211
private void OpenPlayerProfilePanel()
212212
{
213213
HideFeatureSelection();
214-
_playerProfile = BoilerplateFactory.OpenSequencePlayerProfile(transform, _wallet, _chain, null, ShowDefaultWindow);
214+
_playerProfile = BoilerplateFactory.OpenSequencePlayerProfile(transform, _wallet, _chain, new Address("0x85acb5646a9d73952347174ef928c2c9a174156f"), "STB", ShowDefaultWindow);
215215
}
216216

217217
private void OpenDailyRewardsPanel()

Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/PlayerProfile/SequencePlayerProfile.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Hide()
4444
/// <param name="chain">Chain used to get balances and send transactions.</param>
4545
/// <param name="currency">Define a custom ERC20 currency. Leave it null to use the chains native token.</param>
4646
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
47-
public async void Show(IWallet wallet, Chain chain, Address currency = null, Action onClose = null)
47+
public async void Show(IWallet wallet, Chain chain, Address currency = null, string currencySymbol = null, Action onClose = null)
4848
{
4949
_wallet = wallet;
5050
_chain = chain;
@@ -53,13 +53,24 @@ public async void Show(IWallet wallet, Chain chain, Address currency = null, Act
5353
_transactionPool.Cleanup();
5454

5555
SetOverviewState();
56-
SetBalance(0);
57-
58-
var walletAddress = _wallet.GetWalletAddress();
59-
var indexer = new ChainIndexer(_chain);
60-
var balanceResponse = await indexer.GetNativeTokenBalance(walletAddress);
56+
SetBalance(0, string.Empty);
6157

62-
SetBalance(balanceResponse.balanceWei);
58+
var indexer = new ChainIndexer(_chain);
59+
var walletAddress = _wallet.GetWalletAddress();
60+
61+
if (currency == null)
62+
{
63+
var balanceResponse = await indexer.GetNativeTokenBalance(walletAddress);
64+
SetNativeBalance(balanceResponse.balanceWei);
65+
}
66+
else
67+
{
68+
var response = await indexer.GetTokenBalances(new GetTokenBalancesArgs(walletAddress, currency, true));
69+
var balances = response.balances;
70+
var balance = balances.Length > 0 ? balances[0].balance : 0;
71+
SetBalance(balance, currencySymbol);
72+
}
73+
6374
_messagePopup.gameObject.SetActive(false);
6475
EnableLoading(false);
6576

@@ -168,10 +179,15 @@ private async void UnlinkWallet(LinkedWalletData wallet)
168179
_messagePopup.Show(success ? "Unlinked." : "Failed to unlink", !success);
169180
}
170181

171-
private void SetBalance(BigInteger amount)
182+
private void SetNativeBalance(BigInteger balance)
172183
{
173-
var decimals = DecimalNormalizer.ReturnToNormalString(amount);
174184
var symbol = ChainDictionaries.GasCurrencyOf[_chain];
185+
SetBalance(balance, symbol);
186+
}
187+
188+
private void SetBalance(BigInteger balance, string symbol)
189+
{
190+
var decimals = DecimalNormalizer.ReturnToNormalString(balance);
175191
_etherBalanceText.text = $"{decimals} {symbol}";
176192
}
177193
}

0 commit comments

Comments
 (0)