Skip to content

Commit

Permalink
Fix native usdc balance not being taken into account in several places
Browse files Browse the repository at this point in the history
  • Loading branch information
danimoh committed Mar 28, 2024
1 parent 1ea4260 commit 625fd7e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 23 deletions.
8 changes: 6 additions & 2 deletions src/components/AddressList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ export default defineComponent({
setup(props, context) {
const { addressInfos, activeAddress, selectAddress } = useAddressStore();
const { availableExternalAddresses, accountBalance: btcAccountBalance } = useBtcAddressStore();
const { addressInfo: usdcAddressInfo, accountBalance: usdcAccountBalance } = useUsdcAddressStore();
const {
addressInfo: usdcAddressInfo,
accountBalance: usdcAccountBalance,
nativeAccountBalance: nativeUsdcAccountBalance,
} = useUsdcAddressStore();
const { activeCurrency, setActiveCurrency } = useAccountStore();
const { state: network$ } = useNetworkStore();
const { amountsHidden } = useSettingsStore();
Expand Down Expand Up @@ -177,7 +181,7 @@ export default defineComponent({
const usdcInfo = computed(() => ({
address: usdcAddressInfo.value?.address || 'usdc',
label: context.root.$t('USD Coin') as string,
balance: usdcAccountBalance.value,
balance: usdcAccountBalance.value + nativeUsdcAccountBalance.value,
type: CryptoCurrency.USDC,
}));
Expand Down
16 changes: 11 additions & 5 deletions src/components/layouts/AccountOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
preferredPosition="top"
v-if="activeAccountInfo.type !== AccountType.LEDGER
&& hasUsdcAddresses && $config.usdc.enabled
&& (nimAccountBalance > 0 || usdcAccountBalance > 0)"
&& (
nimAccountBalance > 0
|| nativeUsdcAccountBalance > 0 /* only swap with native USDC supported, not bridged */
)"
noFocus>
<button class="reset" slot="trigger"
@pointerdown="onSwapButtonPointerDown($event, 'NIM-USDC_MATIC')"
Expand Down Expand Up @@ -130,7 +133,10 @@
v-if="activeAccountInfo.type !== AccountType.LEDGER
&& hasBitcoinAddresses && hasUsdcAddresses
&& $config.enableBitcoin && $config.usdc.enabled
&& (btcAccountBalance > 0 || usdcAccountBalance > 0)"
&& (
btcAccountBalance > 0
|| nativeUsdcAccountBalance > 0 /* only swap with native USDC supported, not bridged */
)"
noFocus>
<button class="reset" slot="trigger"
@pointerdown="onSwapButtonPointerDown($event, 'BTC-USDC_MATIC')"
Expand All @@ -157,7 +163,7 @@
<div class="usdc-account-item reset flex-column" @click="selectUsdc">
<div class="usdc-account-item-name flex-row"><UsdcIcon/>{{ $t('USD Coin') }}</div>
<div class="balances" v-if="hasUsdcAddresses">
<template v-if="usdcAccountBalance !== null">
<template v-if="usdcAccountBalance !== null && nativeUsdcAccountBalance !== null">
<div class="flex-row">
<AlertTriangleIcon v-if="usdcConsensus === 'connecting'" />
<Amount
Expand Down Expand Up @@ -289,12 +295,12 @@ export default defineComponent({
hasBitcoinAddresses,
hasUsdcAddresses,
} = useAccountStore();
const { accountBalance: nimAccountBalance } = useAddressStore();
const { accountBalance: btcAccountBalance } = useBtcAddressStore();
const {
accountBalance: usdcAccountBalance,
nativeAccountBalance: nativeUsdcAccountBalance,
} = useUsdcAddressStore();
const { accountBalance: nimAccountBalance } = useAddressStore();
const { config } = useConfig();
const isLegacyAccount = computed(() => (activeAccountInfo.value || false)
Expand Down Expand Up @@ -475,10 +481,10 @@ export default defineComponent({
addAddress,
activeAccountId,
onAddressSelected,
nimAccountBalance,
btcAccountBalance,
usdcAccountBalance,
nativeUsdcAccountBalance,
nimAccountBalance,
showFullLegacyAccountNotice,
showModalLegacyAccountNotice,
selectBitcoin,
Expand Down
2 changes: 1 addition & 1 deletion src/components/layouts/AddressOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
@click="$router.push(`/send/${activeCurrency}`)" @mousedown.prevent
:disabled="(activeCurrency === 'nim' && (!activeAddressInfo || !activeAddressInfo.balance))
|| (activeCurrency === 'btc' && !btcAccountBalance)
|| (activeCurrency === 'usdc' && !nativeUsdcAccountBalance)"
|| (activeCurrency === 'usdc' && !nativeUsdcAccountBalance /* can only send native usdc */)"
>
<ArrowRightSmallIcon />{{ $t('Send') }}
</button>
Expand Down
8 changes: 5 additions & 3 deletions src/components/layouts/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ export default defineComponent({
...(config.usdc.enabled && hasUsdcAddresses.value ? [CryptoCurrency.USDC] : []),
]);
const hasBalance = computed(() => [useAddressStore, useBtcAddressStore, useUsdcAddressStore].some((useStore) =>
!!useStore().accountBalance.value,
));
const hasBalance = computed(() => [useAddressStore, useBtcAddressStore, useUsdcAddressStore].some((use) => {
const store = use();
return !!(store.accountBalance.value
|| ('nativeAccountBalance' in store && store.nativeAccountBalance.value));
}));
const { activeSwap } = useSwapsStore();
const hasActiveSwap = computed(() => activeSwap.value !== null);
Expand Down
2 changes: 1 addition & 1 deletion src/components/swap/SwapModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ export default defineComponent({
switch (asset) { // eslint-disable-line default-case
case SwapAsset.NIM: return activeAddressInfo.value?.balance ?? 0;
case SwapAsset.BTC: return accountBtcBalance.value;
case SwapAsset.USDC: return 0;
case SwapAsset.USDC: return 0; // not supported for swapping
case SwapAsset.USDC_MATIC: return accountUsdcBalance.value;
case SwapAsset.EUR: return 0;
}
Expand Down
20 changes: 10 additions & 10 deletions src/i18n/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ msgstr ""
msgid "Accounts"
msgstr ""

#: src/components/layouts/AccountOverview.vue:124
#: src/components/layouts/AccountOverview.vue:182
#: src/components/layouts/AccountOverview.vue:127
#: src/components/layouts/AccountOverview.vue:188
msgid "Activate"
msgstr ""

Expand Down Expand Up @@ -269,7 +269,7 @@ msgstr ""
msgid "All countries"
msgstr ""

#: src/components/layouts/AccountOverview.vue:220
#: src/components/layouts/AccountOverview.vue:226
#: src/components/LegacyAccountNotice.vue:37
msgid "All new features are exclusive to new accounts. Upgrade now, it only takes seconds."
msgstr ""
Expand Down Expand Up @@ -387,8 +387,8 @@ msgstr ""
msgid "BIC works, too."
msgstr ""

#: src/components/AddressList.vue:172
#: src/components/layouts/AccountOverview.vue:105
#: src/components/AddressList.vue:176
#: src/components/layouts/AccountOverview.vue:108
#: src/components/layouts/AddressOverview.vue:80
#: src/components/layouts/Settings.vue:119
#: src/components/LegacyAccountNotice.vue:21
Expand Down Expand Up @@ -2122,7 +2122,7 @@ msgstr ""
msgid "Swap"
msgstr ""

#: src/components/layouts/AccountOverview.vue:143
#: src/components/layouts/AccountOverview.vue:149
msgid "Swap BTC {arrowIcon} USDC"
msgstr ""

Expand Down Expand Up @@ -2158,7 +2158,7 @@ msgstr ""
msgid "Swap NIM {arrowIcon} BTC"
msgstr ""

#: src/components/layouts/AccountOverview.vue:92
#: src/components/layouts/AccountOverview.vue:95
msgid "Swap NIM {arrowIcon} USDC"
msgstr ""

Expand Down Expand Up @@ -2476,8 +2476,8 @@ msgstr ""
msgid "Update now"
msgstr ""

#: src/components/AddressList.vue:179
#: src/components/layouts/AccountOverview.vue:158
#: src/components/AddressList.vue:183
#: src/components/layouts/AccountOverview.vue:164
#: src/components/layouts/AddressOverview.vue:81
#: src/components/UsdcAddressInfo.vue:12
#: src/composables/useBtcTransactionInfo.ts:124
Expand Down Expand Up @@ -2578,7 +2578,7 @@ msgstr ""
msgid "You can receive more free NIM in {waitTime} hours."
msgstr ""

#: src/components/layouts/Sidebar.vue:274
#: src/components/layouts/Sidebar.vue:276
msgid ""
"You can sell NIM\n"
"- in the Wallet by swapping NIM to BTC or USDC first, which can then be sold.\n"
Expand Down
2 changes: 1 addition & 1 deletion src/stores/UsdcAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useUsdcAddressStore = createStore({
const { activeAccountInfo } = useAccountStore();
if (!activeAccountInfo.value?.polygonAddresses?.length) return undefined;

// TODO: Subtract pending outgoing balance from addressInfo.balance
// TODO: Subtract pending outgoing balance from addressInfo.balance / nativeBalance
// const { pendingTransactionsBySender } = useUsdcTransactionsStore();

// Only supports one USDC address per account for now
Expand Down

0 comments on commit 625fd7e

Please sign in to comment.