Skip to content

Commit

Permalink
fix: 🐛 swap when network is temp unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed Mar 6, 2024
1 parent 98cdf4d commit 5543f45
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,44 @@
class="swap-looking__animation"
/>
<Vue3Lottie
v-else-if="error === SwapError.NETWORK_NOT_SUPPORTED"
v-else-if="
error === SwapError.NETWORK_NOT_SUPPORTED ||
error === SwapError.TEMP_NOT_SUPPORTED
"
:loop="true"
:animation-data="LottieWarning"
class="swap-looking__animation"
/>

<h3 v-if="error !== SwapError.NETWORK_NOT_SUPPORTED">
<h3
v-if="
error !== SwapError.NETWORK_NOT_SUPPORTED &&
error !== SwapError.TEMP_NOT_SUPPORTED
"
>
{{ Errors[error!].title }}
</h3>
<p v-if="error !== SwapError.NETWORK_NOT_SUPPORTED">
<p
v-if="
error !== SwapError.NETWORK_NOT_SUPPORTED &&
error !== SwapError.TEMP_NOT_SUPPORTED
"
>
{{ Errors[error!].description }}
</p>

<h3 v-if="error === SwapError.NETWORK_NOT_SUPPORTED">
Coming soon to<br />{{ networkName }}
</h3>
<p v-if="error === SwapError.NETWORK_NOT_SUPPORTED">
<h3 v-if="error === SwapError.TEMP_NOT_SUPPORTED">
{{ networkName }}<br />is temporarily not supported
</h3>
<p
v-if="
error === SwapError.NETWORK_NOT_SUPPORTED ||
error === SwapError.TEMP_NOT_SUPPORTED
"
>
Can't wait to swap? Try swapping on {{ supportedNets }}.
</p>
</div>
Expand All @@ -57,10 +78,11 @@ interface IProps {
networkName: string;
close: () => void;
}
const prop = defineProps<IProps>();
const supportedNets = getSupportedNetworks()
.map((net) => net.name)
.filter((name) => name !== prop.networkName)
.join(", ");
defineProps<IProps>();
</script>

<style lang="less" scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum SwapError {
SOME_TOKENS,
NO_TRADES,
NETWORK_NOT_SUPPORTED,
TEMP_NOT_SUPPORTED,
}

export const Errors: Record<number, ErrorInfo> = {
Expand Down
8 changes: 7 additions & 1 deletion packages/extension/src/ui/action/views/swap/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ onMounted(async () => {
toNetworks.value.push(netInfo);
});
toNetworks.value.sort(sortByRank);
if (!thisNetwork!) {
swapError.value = SwapError.TEMP_NOT_SUPPORTED;
toggleSwapError();
return;
}
await initToNetworkInfo(thisNetwork!);
setToTokens();
isLooking.value = false;
Expand Down Expand Up @@ -597,7 +602,8 @@ const toggleLooking = () => {
const toggleSwapError = () => {
showSwapError.value = !showSwapError.value;
if (
swapError.value === SwapError.NETWORK_NOT_SUPPORTED &&
(swapError.value === SwapError.NETWORK_NOT_SUPPORTED ||
swapError.value === SwapError.TEMP_NOT_SUPPORTED) &&
!showSwapError.value
) {
router.go(-1);
Expand Down
4 changes: 2 additions & 2 deletions packages/swap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Swap extends EventEmitter {
};
const native = this.fromTokens.all.shift();
this.fromTokens.all.sort(sortByRank);
this.fromTokens.all.unshift(native);
if (native) this.fromTokens.all.unshift(native);
const allToTokens: ProviderToTokenResponse = {};
[...this.providers].reverse().forEach((p) => {
merge(allToTokens, p.getToTokens());
Expand All @@ -142,7 +142,7 @@ class Swap extends EventEmitter {
values.sort(sortNativeToFront);
const nativeTo = values.shift();
values.sort(sortByRank);
values.unshift(nativeTo);
if (nativeTo) values.unshift(nativeTo);
values.forEach((val: TokenTypeTo) => {
if (val.cgId && this.topTokenInfo.topTokens[val.cgId]) {
if (!this.toTokens.top[nName]) this.toTokens.top[nName] = [];
Expand Down

1 comment on commit 5543f45

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.