assembly/components/sidebar/context/strategy/SidebarStrategy.vue

134 lines
4.1 KiB
Vue
Raw Normal View History

2021-08-22 12:54:23 +00:00
<template>
<SidebarContextContainer class="h-full overflow-hidden">
2021-08-25 11:13:23 +00:00
<SidebarContextHeader>
<h1 class="font-bold text-primary-black text-lg">
{{ activeStrategy.schema.name }}
</h1>
<p
v-if="activeStrategy.schema.author"
class="font-medium text-[#1874FF] text-sm mt-2.5"
>
{{ activeStrategy.schema.author }}
</p>
</SidebarContextHeader>
2021-08-22 12:54:23 +00:00
2021-08-25 11:13:23 +00:00
<div class="h-full overflow-y-scroll scrollbar-hover flex flex-col">
2021-09-05 11:01:19 +00:00
<div class="mx-auto mb-6" style="width: 296px">
2021-08-25 11:13:23 +00:00
<div
class="flex-shrink-0 font-medium prose prose-sm text-primary-gray"
v-if="activeStrategy.schema.details"
v-html="activeStrategy.schema.details"
></div>
</div>
<div class="flex-1 bg-[#1874FF] bg-opacity-[0.04]">
<div class="mx-auto h-full" style="max-width: 296px">
<div class="space-y-4 py-9 h-full flex flex-col">
<div class="flex-1">
2021-09-05 11:46:39 +00:00
<div v-for="(component, index) in components" :key="index" class="mb-6">
2021-08-25 11:13:23 +00:00
<input-amount
2021-09-05 11:46:39 +00:00
v-if="component.type === 'input-with-token'"
2021-08-25 11:13:23 +00:00
:key="index"
2021-09-05 11:46:39 +00:00
:value="component.value"
:token-key="component.token ? component.token.key : 'eth'"
2021-08-25 11:13:23 +00:00
:token-keys="
2021-09-05 11:46:39 +00:00
component.tokenKeys
? component.tokenKeys
2021-08-25 11:13:23 +00:00
: activeStrategy.getContext()['tokenKeys']
"
2021-09-05 11:46:39 +00:00
:error="component.error"
:placeholder="component.placeholder()"
@input="$event => component.onInput($event)"
2021-08-25 11:13:23 +00:00
@tokenKeyChanged="
tokenKey => {
2021-09-05 11:46:39 +00:00
component.onCustomInput({
2021-08-25 11:13:23 +00:00
token: getTokenByKey(tokenKey)
});
}
"
/>
2021-09-05 11:01:19 +00:00
<SidebarContextHeading
2021-09-05 11:46:39 +00:00
v-else-if="component.type === 'heading'"
2021-09-05 11:01:19 +00:00
:key="index"
>
2021-09-05 11:46:39 +00:00
{{ component.name }}
2021-09-05 11:01:19 +00:00
</SidebarContextHeading>
2021-09-05 11:46:39 +00:00
<div v-else-if="component.type === 'value'" :key="index">
<value-display :label="component.name">
{{ component.value }}
2021-09-05 11:01:19 +00:00
</value-display>
</div>
2021-08-25 11:13:23 +00:00
</div>
</div>
2021-08-22 17:35:46 +00:00
2021-08-25 11:13:23 +00:00
<div class="mt-auto">
<ValidationErrors
:error-messages="error ? [error] : []"
class="mb-6"
/>
2021-08-22 17:35:46 +00:00
2021-08-25 11:13:23 +00:00
<ButtonCTA
class="w-full"
@click="submit"
:loading="pending"
:disabled="pending"
>
{{ activeStrategy.schema.submitText || "Submit" }}
</ButtonCTA>
</div>
</div>
2021-08-22 12:54:23 +00:00
</div>
</div>
</div>
</SidebarContextContainer>
</template>
2021-08-22 13:49:31 +00:00
<script lang="ts">
2021-08-22 17:35:46 +00:00
import { defineComponent } from "@nuxtjs/composition-api";
2021-08-22 13:49:31 +00:00
import { useSidebar } from "~/composables/useSidebar";
import { protocolStrategies, DefineStrategy } from "~/core/strategies";
2021-08-22 17:35:46 +00:00
import { useStrategy } from "~/composables/useStrategy";
2021-08-22 18:32:28 +00:00
import InputAmount from "~/components/common/input/InputAmount.vue";
2021-08-22 19:34:59 +00:00
import { useToken } from "~/composables/useToken";
2021-08-25 11:13:23 +00:00
import ButtonCTA from "~/components/common/input/ButtonCTA.vue";
2021-09-05 11:01:19 +00:00
import ValueDisplay from "../components/ValueDisplay.vue";
2021-08-22 12:54:23 +00:00
export default defineComponent({
2021-09-05 11:01:19 +00:00
components: { InputAmount, ButtonCTA, ValueDisplay },
2021-08-22 12:54:23 +00:00
props: {
protocol: {
type: String,
2021-08-22 13:49:31 +00:00
required: true
2021-08-22 12:54:23 +00:00
},
strategy: {
type: String,
2021-08-22 13:49:31 +00:00
required: true
2021-08-22 12:54:23 +00:00
}
},
setup(props) {
const { close } = useSidebar();
2021-08-22 19:34:59 +00:00
const { getTokenByKey } = useToken();
2021-08-22 12:54:23 +00:00
2021-08-22 13:49:31 +00:00
const strategies: DefineStrategy[] =
protocolStrategies[props.protocol] || [];
2021-08-22 12:54:23 +00:00
2021-08-25 11:13:23 +00:00
const {
2021-09-05 11:46:39 +00:00
components,
2021-08-25 11:13:23 +00:00
submit,
error,
strategy: activeStrategy,
pending
} = useStrategy(
2021-08-22 13:49:31 +00:00
strategies.find(strategy => strategy.id === props.strategy)
);
2021-08-22 12:54:23 +00:00
return {
2021-09-05 11:46:39 +00:00
components,
2021-08-22 17:35:46 +00:00
error,
2021-08-22 19:34:59 +00:00
submit,
activeStrategy,
getTokenByKey,
2021-08-25 11:13:23 +00:00
pending
2021-08-22 13:49:31 +00:00
};
}
});
2021-08-22 12:54:23 +00:00
</script>