-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
Check failure on line 1 in components/common/autoTeleport/AutoTeleportActionButton.vue GitHub Actions / runner / eslint
|
||
<template> | ||
<div class="is-flex is-flex-direction-column w-full"> | ||
Check failure on line 3 in components/common/autoTeleport/AutoTeleportActionButton.vue GitHub Actions / runner / eslint
|
||
|
||
Check failure on line 4 in components/common/autoTeleport/AutoTeleportActionButton.vue GitHub Actions / runner / eslint
|
||
<div class="is-flex is-justify-content-space-between w-full mb-4" v-if="showTeleport"> | ||
<p class="has-text-weight-bold">Auto Teleport</p> | ||
Check failure on line 6 in components/common/autoTeleport/AutoTeleportActionButton.vue GitHub Actions / runner / eslint
|
||
|
||
<NeoSwitch | ||
Check failure on line 8 in components/common/autoTeleport/AutoTeleportActionButton.vue GitHub Actions / runner / eslint
|
||
v-model="autoTeleport" | ||
data-testid="auto-teleport-switch" /> | ||
</div> | ||
Check failure on line 11 in components/common/autoTeleport/AutoTeleportActionButton.vue GitHub Actions / runner / eslint
|
||
|
||
<NeoButton | ||
Check failure on line 13 in components/common/autoTeleport/AutoTeleportActionButton.vue GitHub Actions / runner / eslint
|
||
:label="label" | ||
Check failure on line 14 in components/common/autoTeleport/AutoTeleportActionButton.vue GitHub Actions / runner / eslint
|
||
variant="k-accent" | ||
no-shadow | ||
:disabled="false" | ||
class="is-flex is-flex-grow-1 btn-height" | ||
/> | ||
|
||
<div class="is-flex is-justify-content-center mt-4" v-if="showTeleport"> | ||
<span class="has-text-grey">Or</span> | ||
|
||
<a class="ml-2" @click="rampActive = true" | ||
>+ {{ $t('addFunds') }} Via Onramp</a | ||
> | ||
</div> | ||
|
||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { NeoButton , NeoSwitch } from '@kodadot1/brick' | ||
const props = defineProps<{ | ||
amount: number, | ||
label: string | ||
}>() | ||
const autoTeleport = ref(false) | ||
const { hasEnough, hasEnoughInOtherChains} = useAutoTeleport(computed(() => props.amount)) | ||
const showTeleport = computed(() => !hasEnough.value) | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
|
||
import {allowedTransitions as teleportRoutes, prefixToChainMap, chainToPrefixMap } from "@/utils/teleport" | ||
|
||
export default function (neededAmount: ComputedRef<number>) { | ||
const { urlPrefix } = usePrefix() | ||
const { balance , getBalance } = useBalance() | ||
const {fetchMultipleBalance} = useMultiBalance() | ||
|
||
const hasEnough = computed(() => neededAmount.value < balance.value) | ||
const targetChains = computed(() => teleportRoutes[prefixToChainMap[urlPrefix.value]]) | ||
|
||
const targetChainsBalances = computed(() => targetChains.value.reduce((reducer, chainPrefix) => { | ||
const prefix = chainToPrefixMap[chainPrefix] | ||
return { | ||
...reducer, | ||
[prefix]: getBalance('KSM', prefix) | ||
} | ||
}, {})) | ||
|
||
const hasEnoughInOtherChains = computed(() => Object.values(targetChainsBalances.value).some(Boolean)) | ||
|
||
onMounted(async () => { | ||
await fetchMultipleBalance() | ||
}) | ||
|
||
return { | ||
hasEnough, | ||
hasEnoughInOtherChains, | ||
// teleport: | ||
} | ||
} |