Skip to content

Commit

Permalink
Add native USDC balance to displayed account balance
Browse files Browse the repository at this point in the history
But continue to only use "old" bridged USDC balance for sending and swapping limits.
  • Loading branch information
sisou committed Oct 31, 2023
1 parent cf70353 commit 7fa585e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/components/AccountBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export default defineComponent({
setup(props, context) {
const { accountBalance } = useAddressStore();
const { accountBalance: btcAccountBalance } = useBtcAddressStore();
const { accountBalance: usdcAccountBalance } = useUsdcAddressStore();
const {
accountBalance: usdcAccountBalance,
nativeAccountBalance: nativeUsdcAccountBalance,
} = useUsdcAddressStore();
const { currency: fiatCurrency, exchangeRates } = useFiatStore();
const { config } = useConfig();
Expand All @@ -67,7 +70,7 @@ export default defineComponent({
if (config.usdc.enabled) {
const usdcFiatAmount = usdcExchangeRate.value !== undefined
? (usdcAccountBalance.value / 1e6) * usdcExchangeRate.value
? ((usdcAccountBalance.value + nativeUsdcAccountBalance.value) / 1e6) * usdcExchangeRate.value
: undefined;
if (usdcFiatAmount === undefined) return undefined;
amount += usdcFiatAmount;
Expand Down
6 changes: 5 additions & 1 deletion src/components/AccountMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export default defineComponent({
? usdcAddressState.addressInfos[polygonAddress.value]?.balance || 0
: 0,
);
const nativeUsdcAccountBalance = computed(() => polygonAddress.value
? usdcAddressState.addressInfos[polygonAddress.value]?.nativeBalance || 0
: 0,
);
// TODO: Dedupe double code with AccountBalance
const { currency: fiatCurrency, exchangeRates } = useFiatStore();
Expand All @@ -131,7 +135,7 @@ export default defineComponent({
}
if (config.usdc.enabled) {
const usdcFiatAmount = usdcExchangeRate.value !== undefined
? (usdcAccountBalance.value / 1e6) * usdcExchangeRate.value
? ((usdcAccountBalance.value + nativeUsdcAccountBalance.value) / 1e6) * usdcExchangeRate.value
: undefined;
if (usdcFiatAmount === undefined) return undefined;
amount += usdcFiatAmount;
Expand Down
9 changes: 7 additions & 2 deletions src/components/layouts/AddressOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<Amount v-if="activeCurrency === 'nim'" :amount="activeAddressInfo.balance" value-mask/>
<Amount v-if="activeCurrency === 'btc'" :amount="btcAccountBalance" currency="btc" value-mask/>
<Amount v-if="activeCurrency === 'usdc'"
:amount="usdcAccountBalance" currency="usdc" value-mask/>
:amount="usdcAccountBalance + nativeUsdcAccountBalance" currency="usdc" value-mask/>
</div>
<div class="flex-row">
<!-- We need to key the Copyable component, so that the tooltip disappears when
Expand Down Expand Up @@ -264,7 +264,11 @@ export default defineComponent({
const { activeAccountId, activeCurrency } = useAccountStore();
const { activeAddressInfo, activeAddress } = useAddressStore();
const { accountBalance: btcAccountBalance } = useBtcAddressStore();
const { accountBalance: usdcAccountBalance, addressInfo: usdcAddressInfo } = useUsdcAddressStore();
const {
accountBalance: usdcAccountBalance,
nativeAccountBalance: nativeUsdcAccountBalance,
addressInfo: usdcAddressInfo,
} = useUsdcAddressStore();
const { promoBoxVisible, setPromoBoxVisible } = useSwapsStore();
const searchString = ref('');
Expand Down Expand Up @@ -360,6 +364,7 @@ export default defineComponent({
hideUnclaimedCashlinkList,
btcAccountBalance,
usdcAccountBalance,
nativeUsdcAccountBalance,
usdcAddressInfo,
CryptoCurrency,
promoBoxVisible,
Expand Down
5 changes: 5 additions & 0 deletions src/stores/UsdcAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export const useUsdcAddressStore = createStore({
if (!ai || ai.balance === null) return 0;
return ai.balance;
},
nativeAccountBalance: (state, { addressInfo }) => {
const ai = addressInfo.value as UsdcAddressInfo | undefined;
if (!ai || ai.nativeBalance === null) return 0;
return ai.nativeBalance;
},
},
actions: {
addAddressInfo(addressInfo: UsdcAddressInfo) {
Expand Down

0 comments on commit 7fa585e

Please sign in to comment.