denotify-client 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { createClient } from "@supabase/supabase-js";
2
- import axios from "axios";
3
2
  import { Notification } from "./notifications/notification.js";
4
3
  import { Trigger } from "./triggers/trigger.js";
4
+ import fetch from 'node-fetch';
5
5
  const toFunctionsUrl = (id) => {
6
6
  return `https://${id}.functions.supabase.co/`;
7
7
  };
@@ -86,16 +86,16 @@ export class DeNotifyClient {
86
86
  url.searchParams.append(param, options.params[param]);
87
87
  }
88
88
  }
89
- console.log(url.toString());
90
89
  const payload = {
91
90
  method,
92
- url: url.toString(),
93
91
  headers: this.headers
94
92
  };
95
93
  if (options.body)
96
- payload.data = options.body;
97
- const res = await axios(payload);
98
- return res.data;
94
+ payload.body = JSON.stringify(options.body);
95
+ const res = await fetch(url.toString(), payload);
96
+ if (!res.ok)
97
+ throw new Error(`unexpected response ${res.statusText}`);
98
+ return await res.json();
99
99
  }
100
100
  async getAbi(network, address) {
101
101
  const ret = await this.request('get', `abi/${network}/${address}`);
@@ -2,17 +2,24 @@ import { AlertBuilder } from "../alertbuilder.js";
2
2
  import { DeNotifyClient } from "../denotifyclient.js";
3
3
  import { FunctionBuilder } from "../functionbuilder.js";
4
4
  import { FilterBuilder } from "../util/filter.js";
5
+ import * as dotenv from 'dotenv';
6
+ // Load config from .env file in root directory
7
+ // See dotenv package for info
8
+ dotenv.config();
5
9
  // Simple App to demonstrate usage. Created a balance monitoring alert, updates it and deletes it
6
10
  async function main() {
7
11
  const api = await DeNotifyClient.create({
8
12
  email: process.env.EMAIL,
9
13
  password: process.env.PASSWORD,
14
+ anonKey: process.env.ANON_KEY,
15
+ projectId: process.env.PROJECT_ID
10
16
  });
11
17
  const network = 'avalanche';
12
18
  const address = '0x26985888d5b7019ff2A7444fB567D8F386c3b538';
13
19
  const myAddress = '0x7601630eC802952ba1ED2B6e4db16F699A0a5A87';
14
20
  const { abi } = await api.getAbi(network, address);
15
21
  const webhook = process.env.DISCORD_WEBHOOK;
22
+ console.log(abi);
16
23
  const builder = FunctionBuilder.create(api);
17
24
  await builder.addFunction(address, 'getBalance', [myAddress], abi);
18
25
  // Create the Balance Monitor alert
@@ -17,10 +17,12 @@ export class FunctionBuilder {
17
17
  async addFunction(address, func, args, abi) {
18
18
  const contract = new ethers.Contract(address, abi);
19
19
  contract.interface.encodeFunctionData(func, args);
20
+ const abiHash = await this.getAbiHash(abi);
21
+ console.log(abiHash);
20
22
  this.data.push({
21
23
  address,
22
24
  bytecode: contract.interface.encodeFunctionData(func, args),
23
- abiHash: await this.getAbiHash(abi),
25
+ abiHash,
24
26
  function: func,
25
27
  });
26
28
  return this;