From 79aa847eff65c67c4a1b5a07dcf2157b9ff3dfdf Mon Sep 17 00:00:00 2001
From: Jamie Hewitt <jamie.hewitt15@gmail.com>
Date: Wed, 29 Jun 2022 19:41:26 +0300
Subject: [PATCH] Saving providerFee as an array of all previous provider fees

---
 .vscode/extensions.json        |  7 +++++++
 .vscode/settings.json          | 17 +++++++++++++++++
 schema.graphql                 |  2 +-
 src/mappings/erc20Templates.ts | 10 ++++++++--
 4 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 .vscode/extensions.json
 create mode 100644 .vscode/settings.json

diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 0000000..5901167
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,7 @@
+{
+  "recommendations": [
+    "dbaeumer.vscode-eslint",
+    "esbenp.prettier-vscode",
+    "wix.vscode-import-cost"
+  ]
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..171c9cd
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,17 @@
+{
+  "editor.codeActionsOnSave": {
+    "source.fixAll.eslint": true
+  },
+  "editor.defaultFormatter": "esbenp.prettier-vscode",
+  "editor.formatOnSave": true,
+  "eslint.validate": [
+    "javascript",
+    "javascriptreact",
+    "typescript",
+    "typescriptreact"
+  ],
+  "search.exclude": {
+    "**/.next": true,
+    "**/out": true
+  }
+}
diff --git a/schema.graphql b/schema.graphql
index 36fe1f2..feb4ea7 100644
--- a/schema.graphql
+++ b/schema.graphql
@@ -265,7 +265,7 @@ type Order @entity {
   publishingMarket: User
   publishingMarketToken: Token                                #
   publishingMarketAmmount: BigDecimal                         #call contract to get fee amount
-  providerFee: String
+  providerFee: [String!]
 
   consumerMarket: User
   consumerMarketToken: Token                                  #
diff --git a/src/mappings/erc20Templates.ts b/src/mappings/erc20Templates.ts
index 56c8ef0..3d88858 100644
--- a/src/mappings/erc20Templates.ts
+++ b/src/mappings/erc20Templates.ts
@@ -204,7 +204,8 @@ export function handleProviderFee(event: ProviderFee): void {
     event.address.toHex(),
     event.transaction.from.toHex()
   )
-  const providerFee = `{providerFeeAddress: ${event.params.providerFeeAddress.toHex()}, providerFeeToken: ${event.params.providerFeeToken.toHex()}, providerFeeAmount: ${
+
+  const providerFee: string = `{providerFeeAddress: ${event.params.providerFeeAddress.toHex()}, providerFeeToken: ${event.params.providerFeeToken.toHex()}, providerFeeAmount: ${
     event.params.providerFeeAmount
   }, providerData: ${event.params.providerData.toHexString()}, v: ${
     event.params.v
@@ -213,7 +214,12 @@ export function handleProviderFee(event: ProviderFee): void {
   }
   }`
 
-  order.providerFee = providerFee
+  let existingProviderFees: string[]
+  if (!order.providerFee) existingProviderFees = []
+  else existingProviderFees = order.providerFee as string[]
+  existingProviderFees.push(providerFee)
+
+  order.providerFee = existingProviderFees
   order.save()
 }