From 48602b9d6cd593fedced63188ce0ab8cadc4bde2 Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Sun, 22 Aug 2021 15:54:23 +0300 Subject: [PATCH] update --- .../context/strategy/SidebarStrategy.vue | 51 +++++++++++++++++ .../strategy/SidebarStrategySelection.vue | 56 +++++++++++++++++++ composables/useSidebar.ts | 5 ++ core/strategies/helpers/strategy.ts | 19 ++++++- core/strategies/index.ts | 2 +- .../protocols/aave-v2/deposit-and-borrow.ts | 4 +- package.json | 1 + yarn.lock | 5 ++ 8 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 components/sidebar/context/strategy/SidebarStrategy.vue create mode 100644 components/sidebar/context/strategy/SidebarStrategySelection.vue diff --git a/components/sidebar/context/strategy/SidebarStrategy.vue b/components/sidebar/context/strategy/SidebarStrategy.vue new file mode 100644 index 0000000..cc9ac52 --- /dev/null +++ b/components/sidebar/context/strategy/SidebarStrategy.vue @@ -0,0 +1,51 @@ + + + \ No newline at end of file diff --git a/components/sidebar/context/strategy/SidebarStrategySelection.vue b/components/sidebar/context/strategy/SidebarStrategySelection.vue new file mode 100644 index 0000000..e1218e7 --- /dev/null +++ b/components/sidebar/context/strategy/SidebarStrategySelection.vue @@ -0,0 +1,56 @@ + + + \ No newline at end of file diff --git a/composables/useSidebar.ts b/composables/useSidebar.ts index 98fd763..517e473 100644 --- a/composables/useSidebar.ts +++ b/composables/useSidebar.ts @@ -35,11 +35,16 @@ import SidebarLiquityTroveWithdraw from '~/components/sidebar/context/liquity/Si import SidebarLiquityTroveBorrow from '~/components/sidebar/context/liquity/SidebarLiquityTroveBorrow.vue' import SidebarLiquityTrovePayback from '~/components/sidebar/context/liquity/SidebarLiquityTrovePayback.vue' +import SidebarStrategySelection from '~/components/sidebar/context/strategy/SidebarStrategySelection.vue' +import SidebarStrategy from '~/components/sidebar/context/strategy/SidebarStrategy.vue' const sidebars = { "#overview" : {component: SidebarOverview, back : false, close : true }, "#deposit-overview": {component: SidebarDepositOverview, back: { hash: 'overview' } }, '#withdraw-token': { component: SidebarWithdraw, back: { hash: 'overview' } }, + '#strategies': { component: SidebarStrategySelection }, + '#strategy': { component: SidebarStrategy }, + "/aave-v2": { component: null }, "/aave-v2#supply": { component: SidebarAaveV2Supply }, "/aave-v2#borrow": { component: SidebarAaveV2Borrow }, diff --git a/core/strategies/helpers/strategy.ts b/core/strategies/helpers/strategy.ts index 79cf986..b1f94e1 100644 --- a/core/strategies/helpers/strategy.ts +++ b/core/strategies/helpers/strategy.ts @@ -1,6 +1,6 @@ import DSA from "dsa-connect"; import Web3 from "web3"; - +import slugify from "slugify" export interface IStrategyContext { dsa: typeof DSA; web3: Web3; @@ -22,6 +22,13 @@ export enum StrategyInputType { INPUT_WITH_TOKEN = "input-with-token" } +// type InputTypes = { +// [StrategyInputType.INPUT] : { +// token?: IStrategyToken; +// value?: any; +// }; +// } + export interface IStrategyInput { type: StrategyInputType; name: string; @@ -32,9 +39,12 @@ export interface IStrategyInput { // If type is "input-with-token", this is the token token?: IStrategyToken; value?: any; + + [key: string]: any; } export interface IStrategy { + id?: string; name: string; description: string; author?: string; @@ -42,8 +52,15 @@ export interface IStrategy { inputs: IStrategyInput[]; spells: (context: IStrategyContext) => any; + + submitText?: string; } export function defineStrategy(strategy: IStrategy): IStrategy { + + if(! strategy.id){ + strategy.id = slugify(strategy.name).toLowerCase(); + } + return strategy; } diff --git a/core/strategies/index.ts b/core/strategies/index.ts index 47e70d5..03f0341 100644 --- a/core/strategies/index.ts +++ b/core/strategies/index.ts @@ -1,5 +1,5 @@ import AaveV2 from "./protocols/aave-v2" -export const strategies = { +export const protocolStrategies = { aaveV2 : AaveV2, } \ No newline at end of file diff --git a/core/strategies/protocols/aave-v2/deposit-and-borrow.ts b/core/strategies/protocols/aave-v2/deposit-and-borrow.ts index 76582c6..919a6ef 100644 --- a/core/strategies/protocols/aave-v2/deposit-and-borrow.ts +++ b/core/strategies/protocols/aave-v2/deposit-and-borrow.ts @@ -16,8 +16,8 @@ export default defineStrategy({ } if (input.token.balance < input.value) { - return "Your amount exceeds your maximum limit."; - } + return "Your amount exceeds your maximum limit."; + } return true; } diff --git a/package.json b/package.json index ebbc75f..e65ae6f 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "dsa-connect": "^0.4.3", "nuxt": "^2.15.7", "qrcode": "^1.4.4", + "slugify": "^1.6.0", "v-click-outside": "^3.1.2", "v-tooltip": "^2.1.3", "vue-clipboard2": "^0.3.1", diff --git a/yarn.lock b/yarn.lock index 35f518d..01c4cd5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10410,6 +10410,11 @@ slash@^3.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== +slugify@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.0.tgz#6bdf8ed01dabfdc46425b67e3320b698832ff893" + integrity sha512-FkMq+MQc5hzYgM86nLuHI98Acwi3p4wX+a5BO9Hhw4JdK4L7WueIiZ4tXEobImPqBz2sVcV0+Mu3GRB30IGang== + snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"