Skip to content

Commit 7d7a30f

Browse files
committed
feat: use the pocket-universe sdk
1 parent 091c724 commit 7d7a30f

File tree

7 files changed

+61
-131
lines changed

7 files changed

+61
-131
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ state to be displayed.
3434
It will write to storage the action the user decides to take.
3535

3636
## Contact Us
37-
* [Twitter](https://twitter.com/PocketUniverseZ)
38-
* [Discord](https://discord.gg/UrgqjUQFH2)
37+
38+
- [Twitter](https://twitter.com/PocketUniverseZ)
39+
- [Discord](https://discord.gg/UrgqjUQFH2)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"ethers": "^5.6.9",
1818
"mixpanel-browser": "^2.45.0",
1919
"pino": "8.1.0",
20+
"pocket-universe-js": "^0.0.1",
2021
"react": "^17.0.2",
2122
"react-dom": "^17.0.2",
2223
"react-hot-loader": "^4.13.0",

src/containers/Transaction/Transaction.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { BeatLoader } from 'react-spinners';
77
import { useChromeStorageSync } from 'use-chrome-storage';
88

99
import logger from '../../lib/logger';
10-
import type { Event } from '../../lib/simulation';
11-
import { Simulation, EventType, TokenType } from '../../lib/simulation';
10+
import type { Event } from 'pocket-universe-js';
11+
import { Simulation, EventType, TokenType } from 'pocket-universe-js';
1212
import type { StoredSimulation } from '../../lib/storage';
1313
import {
1414
STORAGE_KEY,
@@ -159,7 +159,7 @@ const EventComponent = ({ event }: { event: Event }) => {
159159
);
160160
};
161161

162-
const TransferAllWarning = ({ events }: { events: Event[] }) => {
162+
const TransferAllWarning = ({ events }: { events: readonly Event[] }) => {
163163
const NoApprovalForAll = (
164164
<div className="text-base text-gray-400 pb-4">
165165
Changes being made in this transaction

src/lib/server.ts

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,24 @@ import config from '../config';
22

33
import logger from './logger';
44
import type { Transaction } from './simulate_request_reply';
5-
import { Simulation } from './simulation';
5+
import { PocketSimulator, Response } from 'pocket-universe-js';
66

77
const log = logger.child({ component: 'Server' });
88

99
// Will change depending on if dev or not.
1010
const SERVER_URL = config.server;
1111

12-
log.info(SERVER_URL, 'SERVER_URL');
13-
14-
export enum ResponseType {
15-
Success = 'success',
16-
Revert = 'revert',
17-
Error = 'error',
18-
}
19-
20-
export interface Response {
21-
type: ResponseType;
22-
23-
// Only set on success.
24-
simulation?: Simulation;
12+
const pocket = new PocketSimulator(SERVER_URL);
2513

26-
// Might be set on error.
27-
error?: string;
28-
}
14+
log.info(SERVER_URL, 'SERVER_URL');
2915

3016
export const fetchSimulate = async (args: {
3117
chainId: string;
3218
transaction: Transaction;
3319
}): Promise<Response> => {
3420
log.info(args, 'Fetch simulate');
35-
try {
36-
const result = await fetch(`${SERVER_URL}/simulate`, {
37-
method: 'POST',
38-
headers: {
39-
Accept: 'application/json',
40-
'Content-Type': 'application/json',
41-
},
42-
body: JSON.stringify({
43-
chainId: args.chainId,
44-
transaction: args.transaction,
45-
}),
46-
});
47-
48-
if (result.status === 200) {
49-
log.info('Fetch success');
50-
const data = await result.json();
51-
52-
if (data.success) {
53-
return {
54-
type: ResponseType.Success,
55-
simulation: Simulation.fromJSON(data.simulation),
56-
};
57-
}
58-
return {
59-
type: ResponseType.Revert,
60-
error: data.error,
61-
};
62-
}
63-
const { error } = await result.json();
64-
log.info({ error, msg: 'Error with the request' });
65-
return { type: ResponseType.Error, error };
66-
} catch (e: any) {
67-
log.warn(e, 'Error simulation');
68-
return { error: e.message, type: ResponseType.Error };
69-
}
21+
return pocket.simulate({
22+
chainId: args.chainId,
23+
...args.transaction,
24+
});
7025
};

src/lib/simulation.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/lib/storage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/// Storage wrapper for updating the storage.
22
import logger from './logger';
3-
import { fetchSimulate, ResponseType } from './server';
3+
import { fetchSimulate } from './server';
44
import type { SimulateRequestArgs } from './simulate_request_reply';
5-
import type { Simulation } from './simulation';
5+
import type { Simulation } from 'pocket-universe-js';
6+
import { ResponseType } from 'pocket-universe-js';
67

78
const log = logger.child({ component: 'Storage' });
89
export enum StoredSimulationState {

yarn.lock

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,14 @@
17161716
resolved "https://registry.yarnpkg.com/@types/mixpanel-browser/-/mixpanel-browser-2.38.0.tgz#b3e28e1ba06c10a9f88510b88f1ac9d1b2adfc42"
17171717
integrity sha512-TR8rvsILnqXA7oiiGOxuMGXwvDeCoQDonXJB5UR+TYvEAFpiK8ReFj5LhZT+Xhm3NpI9aPoju30jB2ssorSUww==
17181718

1719+
"@types/node-fetch@^2.6.2":
1720+
version "2.6.2"
1721+
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.2.tgz#d1a9c5fd049d9415dce61571557104dec3ec81da"
1722+
integrity sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==
1723+
dependencies:
1724+
"@types/node" "*"
1725+
form-data "^3.0.0"
1726+
17191727
"@types/node@*":
17201728
version "18.6.1"
17211729
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.6.1.tgz#828e4785ccca13f44e2fb6852ae0ef11e3e20ba5"
@@ -2356,6 +2364,14 @@ axe-core@^4.4.3:
23562364
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.3.tgz#11c74d23d5013c0fa5d183796729bc3482bd2f6f"
23572365
integrity sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w==
23582366

2367+
axios@^0.27.2:
2368+
version "0.27.2"
2369+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
2370+
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
2371+
dependencies:
2372+
follow-redirects "^1.14.9"
2373+
form-data "^4.0.0"
2374+
23592375
axobject-query@^2.2.0:
23602376
version "2.2.0"
23612377
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
@@ -2739,7 +2755,7 @@ colorette@^2.0.10, colorette@^2.0.14:
27392755
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798"
27402756
integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==
27412757

2742-
combined-stream@^1.0.6, combined-stream@~1.0.6:
2758+
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
27432759
version "1.0.8"
27442760
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
27452761
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
@@ -3799,7 +3815,7 @@ flatted@^3.1.0:
37993815
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.6.tgz#022e9218c637f9f3fc9c35ab9c9193f05add60b2"
38003816
integrity sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==
38013817

3802-
follow-redirects@^1.0.0:
3818+
follow-redirects@^1.0.0, follow-redirects@^1.14.9:
38033819
version "1.15.1"
38043820
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5"
38053821
integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==
@@ -3809,6 +3825,24 @@ forever-agent@~0.6.1:
38093825
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
38103826
integrity sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==
38113827

3828+
form-data@^3.0.0:
3829+
version "3.0.1"
3830+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
3831+
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
3832+
dependencies:
3833+
asynckit "^0.4.0"
3834+
combined-stream "^1.0.8"
3835+
mime-types "^2.1.12"
3836+
3837+
form-data@^4.0.0:
3838+
version "4.0.0"
3839+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
3840+
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
3841+
dependencies:
3842+
asynckit "^0.4.0"
3843+
combined-stream "^1.0.8"
3844+
mime-types "^2.1.12"
3845+
38123846
form-data@~2.3.2:
38133847
version "2.3.3"
38143848
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
@@ -5545,6 +5579,14 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0:
55455579
dependencies:
55465580
find-up "^4.0.0"
55475581

5582+
pocket-universe-js@^0.0.1:
5583+
version "0.0.1"
5584+
resolved "https://registry.yarnpkg.com/pocket-universe-js/-/pocket-universe-js-0.0.1.tgz#0a7fed5d1a8c48c450815f3432e20384ed4b7430"
5585+
integrity sha512-8wc2wk4mPBYE3xfQST0n35hQrbB448TDR52m06O6w/vew7BexKuTvOZafeQG5WAHHCnxQs2vhUpuh5SPMazu1g==
5586+
dependencies:
5587+
"@types/node-fetch" "^2.6.2"
5588+
axios "^0.27.2"
5589+
55485590
postcss-import@^14.1.0:
55495591
version "14.1.0"
55505592
resolved "https://registry.yarnpkg.com/postcss-import/-/postcss-import-14.1.0.tgz#a7333ffe32f0b8795303ee9e40215dac922781f0"

0 commit comments

Comments
 (0)