Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry refactor hook up #570

Merged
merged 55 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
ec9d673
Use map wording instead of dictionary
garethfuller Jul 8, 2021
6af28ba
Add allowances query
garethfuller Jul 8, 2021
ba56078
Refactor for use select token modal
garethfuller Jul 10, 2021
0bad533
Lint fix
garethfuller Jul 10, 2021
c1e8c12
Merge branch 'develop' into gareth/registry-refactor
garethfuller Jul 15, 2021
b4261a9
Init implement provider pattern
garethfuller Jul 17, 2021
25d7ff6
Lint fixes
garethfuller Jul 17, 2021
aea7afb
Merge branch 'develop' into gareth/registry-refactor
garethfuller Jul 19, 2021
0d86bf8
Working tokenlist/tokens provider implementation
garethfuller Jul 20, 2021
137dcb2
Refactor sg service
garethfuller Jul 21, 2021
9d4a926
Use new providers exclusively on the Home page
garethfuller Jul 21, 2021
e3ba38b
Lint fixes
garethfuller Jul 21, 2021
90211e8
Merge branch 'develop' into gareth/registry-refactor
garethfuller Jul 22, 2021
25eb646
Fix where icons come from
garethfuller Jul 22, 2021
c1698d5
Fix merge bug
garethfuller Jul 22, 2021
4bb61ea
Minor style change
garethfuller Jul 23, 2021
2ce807a
Display loading numbers when dynamic data fetching
garethfuller Jul 25, 2021
5e1b957
Change file names to avoid conflicts with Ansaf's providers
garethfuller Jul 26, 2021
5753ae3
Merge branch 'develop' into gareth/registry-refactor
garethfuller Jul 26, 2021
ab6dc25
Only track default + injected tokens
garethfuller Jul 28, 2021
8a6cb69
Remove log
garethfuller Jul 28, 2021
c29c932
Add native asset to dynamic data maps
garethfuller Jul 28, 2021
6b77187
Purge & fix
garethfuller Jul 29, 2021
b000d02
Fix all references to old composables
garethfuller Jul 29, 2021
4f047c7
Fix references to currency
garethfuller Jul 29, 2021
15e489a
More efficient dynamic data fetching
garethfuller Jul 30, 2021
b8ac08c
Lint fix
garethfuller Jul 30, 2021
1edaacd
Fix tokens search list
garethfuller Aug 1, 2021
5d161b1
Cleanup
garethfuller Aug 1, 2021
564b46f
Revert to computed for all tokens
garethfuller Aug 1, 2021
fd4e3c6
Remove unused method reference
garethfuller Aug 1, 2021
45d2c07
Fix remaining references to market vuex module
garethfuller Aug 1, 2021
474bae7
Merge branch 'develop' into gareth/registry-refactor
garethfuller Aug 1, 2021
e422417
Remove references to old registry
garethfuller Aug 1, 2021
da62773
Lint fixes from merge
garethfuller Aug 1, 2021
ba0d883
Rename new composables/providers
garethfuller Aug 1, 2021
93b3b3f
Add kovan stable pool to allowed pools
garethfuller Aug 1, 2021
3f8e945
Fix balances and remove logs
garethfuller Aug 1, 2021
67cc379
Append injected tokens
garethfuller Aug 1, 2021
e67c651
Wording change
garethfuller Aug 1, 2021
9398735
Rename queries
garethfuller Aug 2, 2021
ebc1d69
Comments
garethfuller Aug 2, 2021
33c71f4
Cleanup query keys
garethfuller Aug 2, 2021
27144ed
Comments
garethfuller Aug 2, 2021
8e030c0
Fix references to old constant
garethfuller Aug 2, 2021
2e1fd2d
Revert config change
garethfuller Aug 2, 2021
a0174da
Update logs
garethfuller Aug 2, 2021
bc5f4fc
Fix spelling
garethfuller Aug 3, 2021
d4c3687
Move function outside composable
garethfuller Aug 3, 2021
fde9bfe
Creat usePool composable
garethfuller Aug 3, 2021
45fbfe5
Remove comment
garethfuller Aug 3, 2021
009d5cc
Fix balance fetching in withdrawal form
garethfuller Aug 3, 2021
0bc070a
Revert back to isUnlocked
garethfuller Aug 3, 2021
8fef344
Contantise fetch once options for vue query
garethfuller Aug 3, 2021
8f0b214
Merge branch 'develop' into gareth/registry-refactor
garethfuller Aug 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/components/_global/BalAsset/BalAsset.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<img
v-if="iconURL && !error"
:src="_url(iconURL)"
v-if="iconSRC && !error"
:src="iconSRC"
:style="{
width: `${size}px`,
height: `${size}px`
Expand All @@ -16,6 +16,7 @@
import { defineComponent, toRefs, ref, computed, watch } from 'vue';
import useTokens from '@/composables/useTokens';
import Avatar from '../../images/Avatar.vue';
import useUrls from '@/composables/useUrls';

export default defineComponent({
name: 'BalAsset',
Expand All @@ -29,32 +30,45 @@ export default defineComponent({
type: String,
required: true
},
iconURI: { type: String },
size: {
type: Number,
default: 24
}
},
setup(props) {
// COMPOSABLES
/**
* COMPOSABLES
*/
const { tokens } = useTokens();
const { resolve } = useUrls();

// DATA
/**
* STATE
*/
const { address } = toRefs(props);
const error = ref(false);

// COMPUTED
const iconURL = computed(() => {
/**
* COMPUTED
*/
const iconSRC = computed(() => {
if (props.iconURI) return resolve(props.iconURI);

const token = tokens.value[address.value];
if (!token) return '';
return token.logoURI;
return resolve(token.logoURI);
});

watch(iconURL, newURL => {
/**
* WATCHERS
*/
watch(iconSRC, newURL => {
if (newURL !== '') error.value = false;
});

return {
iconURL,
iconSRC,
error
};
}
Expand Down
48 changes: 43 additions & 5 deletions src/components/_global/BalLoadingBlock/BalLoadingBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,28 @@ export default defineComponent({

props: {
white: { type: Boolean, default: false },
square: { type: Boolean, default: false }
darker: { type: Boolean, default: false },
rounded: {
type: String,
default: 'lg',
validator: (val: string): boolean => ['sm', 'md', 'lg'].includes(val)
}
},

setup(props) {
const { darkMode } = useDarkMode();

const bgClass = computed(() => {
if (props.white) return 'shimmer-white';
return darkMode.value ? 'shimmer-dark' : 'shimmer';
if (darkMode.value) {
return props.darker ? 'shimmer-dark-mode-darker' : 'shimmer-dark-mode';
}
return props.darker ? 'shimmer-light-mode-darker' : 'shimmer-light-mode';
});

const classes = computed(() => {
return {
['rounded-lg']: !props.square,
[`rounded-${props.rounded}`]: true,
[bgClass.value]: true
};
});
Expand Down Expand Up @@ -63,7 +71,7 @@ export default defineComponent({
background-size: 1000px 100%;
}

.shimmer {
.shimmer-light-mode {
--startColor: theme('colors.gray.50');
--midColor: theme('colors.gray.100');
--endColor: theme('colors.gray.50');
Expand All @@ -78,7 +86,22 @@ export default defineComponent({
background-size: 1000px 100%;
}

.shimmer-dark {
.shimmer-light-mode-darker {
--startColor: theme('colors.gray.100');
--midColor: theme('colors.gray.200');
--endColor: theme('colors.gray.100');

animation: shimmerBackground 10s infinite;
background: linear-gradient(
to right,
var(--startColor) 4%,
var(--midColor) 25%,
var(--endColor) 36%
);
background-size: 1000px 100%;
}

.shimmer-dark-mode {
--startColor: theme('colors.gray.850');
--midColor: theme('colors.gray.800');
--endColor: theme('colors.gray.850');
Expand All @@ -92,4 +115,19 @@ export default defineComponent({
);
background-size: 1000px 100%;
}

.shimmer-dark-mode-darker {
--startColor: theme('colors.gray.700');
--midColor: theme('colors.gray.600');
--endColor: theme('colors.gray.700');

animation: shimmerBackground 10s infinite;
background: linear-gradient(
to right,
var(--startColor) 4%,
var(--midColor) 25%,
var(--endColor) 36%
);
background-size: 1000px 100%;
}
</style>
62 changes: 62 additions & 0 deletions src/components/_global/BalLoadingNumber/BalLoadingNumber.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<template>
<div class="flex items-center">
<template v-if="type === 'token'">
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
<span class="text-gray-300 dark:text-gray-500">.</span>
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
</template>
<template v-else-if="type === 'fiat'">
<span class="text-gray-300 dark:text-gray-500 mr-px">
{{ currencySymbol }}
</span>
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
<span class="text-gray-300 dark:text-gray-500">.</span>
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
<BalLoadingBlock :class="blockClasses" rounded="sm" darker />
</template>
</div>
</template>

<script lang="ts">
import useUserSettings from '@/composables/useUserSettings';
import { FiatSymbol } from '@/constants/currency';
import { defineComponent, computed } from 'vue';
import BalLoadingBlock from '../BalLoadingBlock/BalLoadingBlock.vue';

export default defineComponent({
name: 'BalLoadingNumber',

components: {
BalLoadingBlock
},

props: {
type: {
type: String,
default: 'token',
validator: (val: string): boolean => ['token', 'fiat'].includes(val)
},
numberWidth: { type: String, default: '3' },
numberHeight: { type: String, default: '5' }
},

setup(props) {
const { currency } = useUserSettings();

const currencySymbol = computed(() => FiatSymbol[currency.value]);

const blockClasses = computed(() => [
`w-${props.numberWidth}`,
`h-${props.numberHeight}`,
'mr-px'
]);

return { blockClasses, currencySymbol };
}
});
</script>
19 changes: 9 additions & 10 deletions src/components/cards/TradeCard/GasReimbursement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<script lang="ts">
import { PropType, defineComponent, computed, onBeforeMount, ref } from 'vue';
import { useStore } from 'vuex';
import { ETHER } from '@/constants/tokenlists';
import BigNumber from 'bignumber.js';
import { SorReturn } from '@/lib/utils/balancer/helpers/sor/sorManager';
import { isBudgetLeft } from '@/lib/utils/balancer/bal4gas';
Expand All @@ -27,7 +26,8 @@ import { useI18n } from 'vue-i18n';
import { EXTERNAL_LINKS } from '@/constants/links';
import { getOriginalAddress } from '@/services/coingecko';
import useWeb3 from '@/services/web3/useWeb3';
import { TOKENS } from '@/constants/tokens';
import { NATIVE_ASSET_ADDRESS, TOKENS } from '@/constants/tokens';
import useTokens from '@/composables/useTokens';

export default defineComponent({
props: {
Expand All @@ -50,6 +50,7 @@ export default defineComponent({
const { appNetworkConfig } = useWeb3();
const isBalForGasBudget = ref<boolean>(false);
const { t } = useI18n();
const { priceFor } = useTokens();

const eligibleAssetMeta = eligibleAssetList[appNetworkConfig.network] ?? {};
const eligibleAssets = Object.fromEntries(
Expand All @@ -68,19 +69,17 @@ export default defineComponent({
};
}

const ethPrice =
store.state.market.prices[ETHER.address.toLowerCase()]?.price || 0;
const balPrice =
store.state.market.prices[
getOriginalAddress(appNetworkConfig.chainId, TOKENS.AddressMap.BAL)
]?.price || 0;
const ethPrice = priceFor(appNetworkConfig.nativeAsset.address);
const balPrice = priceFor(
getOriginalAddress(appNetworkConfig.chainId, TOKENS.AddressMap.BAL)
);
const gasPrice = store.state.market.gasPrice || 0;

const addressInIsEligible =
props.addressIn === ETHER.address ||
props.addressIn === NATIVE_ASSET_ADDRESS ||
props.addressIn.toLowerCase() in eligibleAssets;
const addressOutIsEligible =
props.addressOut === ETHER.address ||
props.addressOut === NATIVE_ASSET_ADDRESS ||
props.addressOut.toLowerCase() in eligibleAssets;
const reimburseAllSwaps = addressInIsEligible && addressOutIsEligible;

Expand Down
12 changes: 5 additions & 7 deletions src/components/cards/TradeCard/TradeCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ import useValidation, {
TradeValidation
} from '@/composables/trade/useValidation';
import useSor from '@/composables/trade/useSor';
import { ETHER } from '@/constants/tokenlists';

import SuccessOverlay from '@/components/cards/SuccessOverlay.vue';
import TradePair from '@/components/cards/TradeCard/TradePair.vue';
Expand Down Expand Up @@ -173,15 +172,15 @@ export default defineComponent({
const isWrap = computed(() => {
const config = userNetworkConfig.value;
return (
tokenInAddress.value === ETHER.address &&
tokenInAddress.value === nativeAsset.address &&
tokenOutAddress.value === config.addresses.weth
);
});

const isUnwrap = computed(() => {
const config = userNetworkConfig.value;
return (
tokenOutAddress.value === ETHER.address &&
tokenOutAddress.value === nativeAsset.address &&
tokenInAddress.value === config.addresses.weth
);
});
Expand Down Expand Up @@ -230,8 +229,7 @@ export default defineComponent({
tokenInAddress,
tokenInAmount,
tokenOutAddress,
tokenOutAmount,
tokens
tokenOutAmount
);

const title = computed(() => {
Expand Down Expand Up @@ -280,10 +278,10 @@ export default defineComponent({

async function populateInitialTokens(): Promise<void> {
let assetIn = router.currentRoute.value.params.assetIn as string;
if (assetIn === ETHER.deeplinkId) assetIn = ETHER.address;
if (assetIn === nativeAsset.deeplinkId) assetIn = nativeAsset.address;
else if (isAddress(assetIn)) assetIn = getAddress(assetIn);
let assetOut = router.currentRoute.value.params.assetOut as string;
if (assetOut === ETHER.deeplinkId) assetOut = ETHER.address;
if (assetOut === nativeAsset.deeplinkId) assetOut = nativeAsset.address;
else if (isAddress(assetOut)) assetOut = getAddress(assetOut);

tokenInAddress.value = assetIn || store.state.trade.inputAsset;
Expand Down
14 changes: 6 additions & 8 deletions src/components/cards/TradeCard/TradePair.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,13 @@

<script lang="ts">
import { defineComponent, toRefs, computed, ref } from 'vue';
import { useStore } from 'vuex';

import useNumbers from '@/composables/useNumbers';
import { ETHER } from '@/constants/tokenlists';

import TradePairToggle from '@/components/cards/TradeCard/TradePairToggle.vue';
import SelectTokenModal from '@/components/modals/SelectTokenModal/SelectTokenModal.vue';
import useTokens from '@/composables/useTokens';
import { NATIVE_ASSET_ADDRESS } from '@/constants/tokens';

const ETH_BUFFER = 0.1;

Expand Down Expand Up @@ -205,8 +204,7 @@ export default defineComponent({
'change'
],
setup(props, { emit }) {
const store = useStore();
const { tokens } = useTokens();
const { tokens, balances, injectTokens } = useTokens();
const { fNum, toFiat } = useNumbers();

const {
Expand Down Expand Up @@ -256,10 +254,10 @@ export default defineComponent({
const modalSelectTokenIsOpen = ref(false);

function handleMax(): void {
const balance = tokens.value[tokenInAddressInput.value]?.balance || '0';
const balance = balances.value[tokenInAddressInput.value] || '0';
const balanceNumber = parseFloat(balance);
const maxAmount =
tokenInAddressInput.value !== ETHER.address
tokenInAddressInput.value !== NATIVE_ASSET_ADDRESS
? balance
: balanceNumber > ETH_BUFFER
? (balanceNumber - ETH_BUFFER).toString()
Expand Down Expand Up @@ -299,7 +297,7 @@ export default defineComponent({
return;
} else emit('tokenOutAddressChange', address);
}
store.dispatch('registry/injectTokens', [address]);
injectTokens([address]);
}

const rateMessage = computed(() => {
Expand Down Expand Up @@ -338,7 +336,7 @@ export default defineComponent({
}

const balanceLabel = computed(
() => tokens.value[tokenInAddressInput.value]?.balance
() => balances.value[tokenInAddressInput.value]
);

return {
Expand Down
Loading