Skip to content

Commit

Permalink
Merge pull request focustree#326 from focustree/add-strk
Browse files Browse the repository at this point in the history
add strk token
  • Loading branch information
PaulRbl authored Feb 19, 2024
2 parents 11a5e27 + b0173a7 commit d0202eb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/wallet_kit/assets/images/crypto/STRK.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/wallet_kit/lib/services/token_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ enum TokenSymbol {
FOCUS,
USDC,
USDT,
STRK
}
60 changes: 60 additions & 0 deletions packages/wallet_kit/lib/wallet_state/wallet_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,41 @@ class Wallets extends _$Wallets with PersistedState<WalletsState> {
)
});
}

refreshStrkBalance(String walletId, int accountId) async {
final accountAddress =
state.wallets[walletId]?.accounts[accountId]?.address;
if (accountAddress == null) {
throw Exception('Account address is null');
}
final provider = WalletKit().provider;
final strkBalance = await getStrkBalance(
provider: provider,
accountAddress: s.Felt.fromHexString(accountAddress),
);
final wallet = state.wallets[walletId];
if (wallet == null) {
throw Exception("Wallet not found");
}
final account = wallet.accounts[accountId];
if (account == null) {
throw Exception("Account not found");
}
state = state.copyWith(wallets: {
...state.wallets,
walletId: wallet.copyWith(
accounts: {
...wallet.accounts,
accountId: account.copyWith(
balances: {
...account.balances,
'STRK': double.parse(strkBalance.toStringAsFixed(4)),
},
),
},
)
});
}
}

Future<double> getEthBalance(
Expand Down Expand Up @@ -233,3 +268,28 @@ Future<double> getEthBalance(
},
);
}

Future<double> getStrkBalance(
{required sp.Provider provider, required s.Felt accountAddress}) async {
final strkContractAddress = s.Felt.fromHexString(
'0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d');
const strkDecimals = 18;
final response = await provider.call(
request: sp.FunctionCall(
contractAddress: strkContractAddress,
entryPointSelector: s.getSelectorByName('balanceOf'),
calldata: [accountAddress],
),
blockId: const sp.BlockId.blockTag("latest"),
);
return response.when<double>(
error: (error) {
throw Exception(error);
},
result: (result) {
final strkBalance = s.Uint256.fromFeltList(result).toBigInt() /
BigInt.from(10).pow(strkDecimals);
return strkBalance;
},
);
}

0 comments on commit d0202eb

Please sign in to comment.