@reyaxyz/community-sdk 0.1.0
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.
- package/LICENSE.md +1 -0
- package/README.md +10 -0
- package/dist/client/constants.js +9 -0
- package/dist/client/constants.js.map +1 -0
- package/dist/client/index.js +63 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/index.js +18 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/vote/index.js +68 -0
- package/dist/modules/vote/index.js.map +1 -0
- package/dist/modules/vote/services/get-vote-details/index.js +73 -0
- package/dist/modules/vote/services/get-vote-details/index.js.map +1 -0
- package/dist/modules/vote/services/get-vote-status/index.js +67 -0
- package/dist/modules/vote/services/get-vote-status/index.js.map +1 -0
- package/dist/modules/vote/services/index.js +20 -0
- package/dist/modules/vote/services/index.js.map +1 -0
- package/dist/modules/vote/services/vote/index.js +63 -0
- package/dist/modules/vote/services/vote/index.js.map +1 -0
- package/dist/types/client/constants.d.ts +8 -0
- package/dist/types/client/constants.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +24 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/index.d.ts +2 -0
- package/dist/types/modules/index.d.ts.map +1 -0
- package/dist/types/modules/vote/index.d.ts +10 -0
- package/dist/types/modules/vote/index.d.ts.map +1 -0
- package/dist/types/modules/vote/services/get-vote-details/index.d.ts +7 -0
- package/dist/types/modules/vote/services/get-vote-details/index.d.ts.map +1 -0
- package/dist/types/modules/vote/services/get-vote-status/index.d.ts +8 -0
- package/dist/types/modules/vote/services/get-vote-status/index.d.ts.map +1 -0
- package/dist/types/modules/vote/services/index.d.ts +4 -0
- package/dist/types/modules/vote/services/index.d.ts.map +1 -0
- package/dist/types/modules/vote/services/vote/index.d.ts +12 -0
- package/dist/types/modules/vote/services/vote/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +13 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
- package/src/client/constants.ts +13 -0
- package/src/client/index.ts +46 -0
- package/src/index.ts +2 -0
- package/src/modules/index.ts +1 -0
- package/src/modules/vote/index.ts +29 -0
- package/src/modules/vote/services/get-vote-details/index.ts +36 -0
- package/src/modules/vote/services/get-vote-status/index.ts +33 -0
- package/src/modules/vote/services/index.ts +3 -0
- package/src/modules/vote/services/vote/index.ts +29 -0
- package/src/types.ts +13 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MIT License
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @reyaxyz/community-sdk
|
|
2
|
+
|
|
3
|
+
<p align="center"> Community sdk for the Reya Network </p>
|
|
4
|
+
|
|
5
|
+
<br />
|
|
6
|
+
|
|
7
|
+
| Statements | Branches | Functions | Lines |
|
|
8
|
+
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
+
|  |  |  |  |
|
|
10
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SERVICE_CONFIG = void 0;
|
|
4
|
+
var common_1 = require("@reyaxyz/common");
|
|
5
|
+
exports.SERVICE_CONFIG = {
|
|
6
|
+
production: { environment: 'production', chainId: common_1.ReyaChainId.reyaNetwork },
|
|
7
|
+
test: { environment: 'test', chainId: common_1.ReyaChainId.reyaCronos },
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"/","sources":["client/constants.ts"],"names":[],"mappings":";;;AAAA,0CAA8C;AASjC,QAAA,cAAc,GAA8C;IACvE,UAAU,EAAE,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,oBAAW,CAAC,WAAW,EAAE;IAC3E,IAAI,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAW,CAAC,UAAU,EAAE;CAC/D,CAAC","sourcesContent":["import { ReyaChainId } from '@reyaxyz/common';\n\nexport type ServiceEnvironment = 'production' | 'test';\n\nexport type ServiceConfig = {\n chainId: ReyaChainId;\n environment: ServiceEnvironment;\n};\n\nexport const SERVICE_CONFIG: Record<ServiceEnvironment, ServiceConfig> = {\n production: { environment: 'production', chainId: ReyaChainId.reyaNetwork },\n test: { environment: 'test', chainId: ReyaChainId.reyaCronos },\n};\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.CommunityClient = void 0;
|
|
18
|
+
var constants_1 = require("./constants");
|
|
19
|
+
var vote_1 = __importDefault(require("../modules/vote"));
|
|
20
|
+
/**
|
|
21
|
+
* @description Client for Community SDK
|
|
22
|
+
*/
|
|
23
|
+
var CommunityClient = /** @class */ (function () {
|
|
24
|
+
function CommunityClient(config) {
|
|
25
|
+
CommunityClient.config = __assign(__assign({}, CommunityClient.config), config);
|
|
26
|
+
this._vote = new vote_1.default(CommunityClient.config.chainId);
|
|
27
|
+
}
|
|
28
|
+
CommunityClient.configure = function (config) {
|
|
29
|
+
CommunityClient.config = config;
|
|
30
|
+
CommunityClient.instance = new CommunityClient(config);
|
|
31
|
+
};
|
|
32
|
+
CommunityClient.getInstance = function () {
|
|
33
|
+
if (!CommunityClient.instance) {
|
|
34
|
+
throw new Error('ApiClient is not configured. Please configure it before using.');
|
|
35
|
+
}
|
|
36
|
+
return CommunityClient.instance;
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(CommunityClient, "vote", {
|
|
39
|
+
/**
|
|
40
|
+
* Provides access to the VoteModule instance.
|
|
41
|
+
* This getter allows for interacting with vote-related functionalities.
|
|
42
|
+
*
|
|
43
|
+
* @returns {VoteModule} An instance of VoteModule for vote operations.
|
|
44
|
+
* @memberof CommunityClient
|
|
45
|
+
*/
|
|
46
|
+
get: function () {
|
|
47
|
+
return CommunityClient.getInstance()._vote;
|
|
48
|
+
},
|
|
49
|
+
enumerable: false,
|
|
50
|
+
configurable: true
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(CommunityClient, "supportedChains", {
|
|
53
|
+
get: function () {
|
|
54
|
+
return [CommunityClient.config.chainId];
|
|
55
|
+
},
|
|
56
|
+
enumerable: false,
|
|
57
|
+
configurable: true
|
|
58
|
+
});
|
|
59
|
+
CommunityClient.config = constants_1.SERVICE_CONFIG['test'];
|
|
60
|
+
return CommunityClient;
|
|
61
|
+
}());
|
|
62
|
+
exports.CommunityClient = CommunityClient;
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAA4D;AAC5D,yDAAyC;AAGzC;;GAEG;AACH;IAKE,yBAAoB,MAAqB;QACvC,eAAe,CAAC,MAAM,yBAAQ,eAAe,CAAC,MAAM,GAAK,MAAM,CAAE,CAAC;QAClE,IAAI,CAAC,KAAK,GAAG,IAAI,cAAU,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9D,CAAC;IAEa,yBAAS,GAAvB,UAAwB,MAAqB;QAC3C,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC;QAChC,eAAe,CAAC,QAAQ,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;IACzD,CAAC;IAEc,2BAAW,GAA1B;QACE,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;QACJ,CAAC;QACD,OAAO,eAAe,CAAC,QAAQ,CAAC;IAClC,CAAC;IASD,sBAAkB,uBAAI;QAPtB;;;;;;WAMG;aACH;YACE,OAAO,eAAe,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC;QAC7C,CAAC;;;OAAA;IAED,sBAAkB,kCAAe;aAAjC;YACE,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;;;OAAA;IAnCc,sBAAM,GAAkB,0BAAc,CAAC,MAAM,CAAC,CAAC;IAoChE,sBAAC;CAAA,AAtCD,IAsCC;AAtCY,0CAAe","sourcesContent":["import { SERVICE_CONFIG, ServiceConfig } from './constants';\nimport VoteModule from '../modules/vote';\nimport { ReyaChainId } from '@reyaxyz/common';\n\n/**\n * @description Client for Community SDK\n */\nexport class CommunityClient {\n private static instance: CommunityClient;\n private static config: ServiceConfig = SERVICE_CONFIG['test'];\n private readonly _vote: VoteModule;\n\n private constructor(config: ServiceConfig) {\n CommunityClient.config = { ...CommunityClient.config, ...config };\n this._vote = new VoteModule(CommunityClient.config.chainId);\n }\n\n public static configure(config: ServiceConfig): void {\n CommunityClient.config = config;\n CommunityClient.instance = new CommunityClient(config);\n }\n\n private static getInstance(): CommunityClient {\n if (!CommunityClient.instance) {\n throw new Error(\n 'ApiClient is not configured. Please configure it before using.',\n );\n }\n return CommunityClient.instance;\n }\n\n /**\n * Provides access to the VoteModule instance.\n * This getter allows for interacting with vote-related functionalities.\n *\n * @returns {VoteModule} An instance of VoteModule for vote operations.\n * @memberof CommunityClient\n */\n public static get vote(): VoteModule {\n return CommunityClient.getInstance()._vote;\n }\n\n public static get supportedChains(): ReyaChainId[] {\n return [CommunityClient.config.chainId];\n }\n}\n"]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./client"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB","sourcesContent":["export * from './types';\nexport * from './client';\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./vote"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB","sourcesContent":["export * from './vote';\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var services_1 = require("./services");
|
|
40
|
+
var VoteModule = /** @class */ (function () {
|
|
41
|
+
function VoteModule(chainId) {
|
|
42
|
+
this.chainId = chainId;
|
|
43
|
+
}
|
|
44
|
+
VoteModule.prototype.getVoteDetails = function (params) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
return [2 /*return*/, (0, services_1.getVoteDetails)(params)];
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
VoteModule.prototype.getVoteStatus = function (params) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
return [2 /*return*/, (0, services_1.getVoteStatus)(params)];
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
VoteModule.prototype.vote = function (params) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
return [2 /*return*/, (0, services_1.vote)(params)];
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return VoteModule;
|
|
66
|
+
}());
|
|
67
|
+
exports.default = VoteModule;
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uCAOoB;AAEpB;IAGE,oBAAY,OAAoB;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEK,mCAAc,GAApB,UAAqB,MAA4B;;;gBAC/C,sBAAO,IAAA,yBAAc,EAAC,MAAM,CAAC,EAAC;;;KAC/B;IAEK,kCAAa,GAAnB,UAAoB,MAA2B;;;gBAC7C,sBAAO,IAAA,wBAAa,EAAC,MAAM,CAAC,EAAC;;;KAC9B;IAEK,yBAAI,GAAV,UAAW,MAAkB;;;gBAC3B,sBAAO,IAAA,eAAI,EAAC,MAAM,CAAC,EAAC;;;KACrB;IACH,iBAAC;AAAD,CAAC,AAlBD,IAkBC","sourcesContent":["import { ReyaChainId } from '@reyaxyz/common';\nimport {\n getVoteDetails,\n GetVoteDetailsParams,\n getVoteStatus,\n GetVoteStatusParams,\n vote,\n VoteParams,\n} from './services';\n\nexport default class VoteModule {\n private chainId: ReyaChainId;\n\n constructor(chainId: ReyaChainId) {\n this.chainId = chainId;\n }\n\n async getVoteDetails(params: GetVoteDetailsParams) {\n return getVoteDetails(params);\n }\n\n async getVoteStatus(params: GetVoteStatusParams) {\n return getVoteStatus(params);\n }\n\n async vote(params: VoteParams) {\n return vote(params);\n }\n}\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getVoteDetails = void 0;
|
|
40
|
+
function mockVoteEntity(id) {
|
|
41
|
+
var daysToAdd = Math.floor(Math.random() * (30 - 14 + 1)) + 14; // Random days between 14 and 30
|
|
42
|
+
return {
|
|
43
|
+
id: id,
|
|
44
|
+
startDate: Date.now(),
|
|
45
|
+
endDate: Date.now() + 1000 * 60 * 60 * 24 * daysToAdd, // 14 to 30 days from now
|
|
46
|
+
percentageToPass: 4,
|
|
47
|
+
yesCount: Math.floor(Math.random() * 100),
|
|
48
|
+
noCount: Math.floor(Math.random() * 100),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// TODO: Write proper implementation
|
|
52
|
+
// TODO: Note if vote details cannot be found throw new Error('Vote not found') UI will have logic based on this
|
|
53
|
+
var getVoteDetails = function (_a) {
|
|
54
|
+
var id = _a.id;
|
|
55
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
return __generator(this, function (_b) {
|
|
57
|
+
switch (_b.label) {
|
|
58
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
59
|
+
setTimeout(function () {
|
|
60
|
+
var error = Math.random() * 100 > 50;
|
|
61
|
+
if (error) {
|
|
62
|
+
reject(new Error('Vote not found'));
|
|
63
|
+
}
|
|
64
|
+
resolve(mockVoteEntity(id));
|
|
65
|
+
}, Math.random() * 100 + 1000);
|
|
66
|
+
})];
|
|
67
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
exports.getVoteDetails = getVoteDetails;
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/services/get-vote-details/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,cAAc,CAAC,EAAU;IAChC,IAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,gCAAgC;IAClG,OAAO;QACL,EAAE,IAAA;QACF,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,yBAAyB;QAChF,gBAAgB,EAAE,CAAC;QACnB,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;QACzC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;KACzC,CAAC;AACJ,CAAC;AAMD,oCAAoC;AACpC,gHAAgH;AACzG,IAAM,cAAc,GAAG,UAAO,EAEd;QADrB,EAAE,QAAA;;;;wBAEK,qBAAM,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;wBACvC,UAAU,CACR;4BACE,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;4BACvC,IAAI,KAAK,EAAE,CAAC;gCACV,MAAM,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;4BACtC,CAAC;4BACD,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;wBAC9B,CAAC,EACD,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI,CAC3B,CAAC;oBACJ,CAAC,CAAC,EAAA;wBAXF,sBAAO,SAWL,EAAC;;;;CACJ,CAAC;AAfW,QAAA,cAAc,kBAezB","sourcesContent":["import { VoteDetailsEntity } from '../../../../types';\n\nfunction mockVoteEntity(id: number): VoteDetailsEntity {\n const daysToAdd = Math.floor(Math.random() * (30 - 14 + 1)) + 14; // Random days between 14 and 30\n return {\n id,\n startDate: Date.now(),\n endDate: Date.now() + 1000 * 60 * 60 * 24 * daysToAdd, // 14 to 30 days from now\n percentageToPass: 4,\n yesCount: Math.floor(Math.random() * 100),\n noCount: Math.floor(Math.random() * 100),\n };\n}\n\nexport type GetVoteDetailsParams = {\n id: VoteDetailsEntity['id'];\n};\nexport type GetVoteDetailsResult = VoteDetailsEntity;\n// TODO: Write proper implementation\n// TODO: Note if vote details cannot be found throw new Error('Vote not found') UI will have logic based on this\nexport const getVoteDetails = async ({\n id,\n}: GetVoteDetailsParams): Promise<GetVoteDetailsResult> => {\n return await new Promise((resolve, reject) => {\n setTimeout(\n () => {\n const error = Math.random() * 100 > 50;\n if (error) {\n reject(new Error('Vote not found'));\n }\n resolve(mockVoteEntity(id));\n },\n Math.random() * 100 + 1000,\n );\n });\n};\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getVoteStatus = void 0;
|
|
40
|
+
function mockVoteStatusEntity() {
|
|
41
|
+
return {
|
|
42
|
+
votingPower: Math.floor(Math.random() * 1000), // Random voting power between 0 and 999
|
|
43
|
+
hasVoted: Math.random() < 0.5, // Randomly true or false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// TODO: Write proper implementation
|
|
47
|
+
var getVoteStatus = function (_a) {
|
|
48
|
+
var id = _a.id, address = _a.address;
|
|
49
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
50
|
+
return __generator(this, function (_b) {
|
|
51
|
+
switch (_b.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
53
|
+
setTimeout(function () {
|
|
54
|
+
var error = Math.random() * 100 > 50;
|
|
55
|
+
if (error) {
|
|
56
|
+
reject(new Error("Vote ".concat(id, ", ").concat(address, " error")));
|
|
57
|
+
}
|
|
58
|
+
resolve(mockVoteStatusEntity());
|
|
59
|
+
}, Math.random() * 100 + 1000);
|
|
60
|
+
})];
|
|
61
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
exports.getVoteStatus = getVoteStatus;
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/services/get-vote-status/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,oBAAoB;IAC3B,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,wCAAwC;QACvF,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE,yBAAyB;KACzD,CAAC;AACJ,CAAC;AAQD,oCAAoC;AAC7B,IAAM,aAAa,GAAG,UAAO,EAGd;QAFpB,EAAE,QAAA,EACF,OAAO,aAAA;;;;wBAEA,qBAAM,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;wBACvC,UAAU,CACR;4BACE,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;4BACvC,IAAI,KAAK,EAAE,CAAC;gCACV,MAAM,CAAC,IAAI,KAAK,CAAC,eAAQ,EAAE,eAAK,OAAO,WAAQ,CAAC,CAAC,CAAC;4BACpD,CAAC;4BACD,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;wBAClC,CAAC,EACD,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI,CAC3B,CAAC;oBACJ,CAAC,CAAC,EAAA;wBAXF,sBAAO,SAWL,EAAC;;;;CACJ,CAAC;AAhBW,QAAA,aAAa,iBAgBxB","sourcesContent":["import { VoteDetailsEntity, VoteStatusEntity } from '../../../../types';\n\nfunction mockVoteStatusEntity(): VoteStatusEntity {\n return {\n votingPower: Math.floor(Math.random() * 1000), // Random voting power between 0 and 999\n hasVoted: Math.random() < 0.5, // Randomly true or false\n };\n}\n\nexport type GetVoteStatusParams = {\n address: string;\n id: VoteDetailsEntity['id'];\n};\nexport type GetVoteStatusResult = VoteStatusEntity;\n\n// TODO: Write proper implementation\nexport const getVoteStatus = async ({\n id,\n address,\n}: GetVoteStatusParams): Promise<GetVoteStatusResult> => {\n return await new Promise((resolve, reject) => {\n setTimeout(\n () => {\n const error = Math.random() * 100 > 50;\n if (error) {\n reject(new Error(`Vote ${id}, ${address} error`));\n }\n resolve(mockVoteStatusEntity());\n },\n Math.random() * 100 + 1000,\n );\n });\n};\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./get-vote-details"), exports);
|
|
18
|
+
__exportStar(require("./get-vote-status"), exports);
|
|
19
|
+
__exportStar(require("./vote"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,oDAAkC;AAClC,yCAAuB","sourcesContent":["export * from './get-vote-details';\nexport * from './get-vote-status';\nexport * from './vote';\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.vote = void 0;
|
|
40
|
+
// TODO: Write proper implementation
|
|
41
|
+
var vote = function (_a) {
|
|
42
|
+
var id = _a.id;
|
|
43
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
+
return __generator(this, function (_b) {
|
|
45
|
+
switch (_b.label) {
|
|
46
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
47
|
+
setTimeout(function () {
|
|
48
|
+
var error = Math.random() * 100 > 50;
|
|
49
|
+
if (error) {
|
|
50
|
+
reject(new Error("Vote ".concat(id, " error")));
|
|
51
|
+
}
|
|
52
|
+
resolve({
|
|
53
|
+
transactionHash: '0x123fake',
|
|
54
|
+
});
|
|
55
|
+
}, Math.random() * 100 + 1000);
|
|
56
|
+
})];
|
|
57
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
exports.vote = vote;
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/services/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,oCAAoC;AAC7B,IAAM,IAAI,GAAG,UAAO,EAAkB;QAAhB,EAAE,QAAA;;;;wBACtB,qBAAM,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;wBACvC,UAAU,CACR;4BACE,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;4BACvC,IAAI,KAAK,EAAE,CAAC;gCACV,MAAM,CAAC,IAAI,KAAK,CAAC,eAAQ,EAAE,WAAQ,CAAC,CAAC,CAAC;4BACxC,CAAC;4BACD,OAAO,CAAC;gCACN,eAAe,EAAE,WAAW;6BAC7B,CAAC,CAAC;wBACL,CAAC,EACD,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI,CAC3B,CAAC;oBACJ,CAAC,CAAC,EAAA;wBAbF,sBAAO,SAaL,EAAC;;;;CACJ,CAAC;AAfW,QAAA,IAAI,QAef","sourcesContent":["import { VoteDetailsEntity } from '../../../../types';\nimport { Signer, JsonRpcSigner } from 'ethers';\n\nexport type VoteParams = {\n id: VoteDetailsEntity['id'];\n voted: 'yes' | 'no';\n signer: Signer | JsonRpcSigner;\n};\nexport type VoteResult = {\n transactionHash: string;\n};\n\n// TODO: Write proper implementation\nexport const vote = async ({ id }: VoteParams): Promise<VoteResult> => {\n return await new Promise((resolve, reject) => {\n setTimeout(\n () => {\n const error = Math.random() * 100 > 50;\n if (error) {\n reject(new Error(`Vote ${id} error`));\n }\n resolve({\n transactionHash: '0x123fake',\n });\n },\n Math.random() * 100 + 1000,\n );\n });\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReyaChainId } from '@reyaxyz/common';
|
|
2
|
+
export type ServiceEnvironment = 'production' | 'test';
|
|
3
|
+
export type ServiceConfig = {
|
|
4
|
+
chainId: ReyaChainId;
|
|
5
|
+
environment: ServiceEnvironment;
|
|
6
|
+
};
|
|
7
|
+
export declare const SERVICE_CONFIG: Record<ServiceEnvironment, ServiceConfig>;
|
|
8
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"/","sources":["client/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,MAAM,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,kBAAkB,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAGpE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ServiceConfig } from './constants';
|
|
2
|
+
import VoteModule from '../modules/vote';
|
|
3
|
+
import { ReyaChainId } from '@reyaxyz/common';
|
|
4
|
+
/**
|
|
5
|
+
* @description Client for Community SDK
|
|
6
|
+
*/
|
|
7
|
+
export declare class CommunityClient {
|
|
8
|
+
private static instance;
|
|
9
|
+
private static config;
|
|
10
|
+
private readonly _vote;
|
|
11
|
+
private constructor();
|
|
12
|
+
static configure(config: ServiceConfig): void;
|
|
13
|
+
private static getInstance;
|
|
14
|
+
/**
|
|
15
|
+
* Provides access to the VoteModule instance.
|
|
16
|
+
* This getter allows for interacting with vote-related functionalities.
|
|
17
|
+
*
|
|
18
|
+
* @returns {VoteModule} An instance of VoteModule for vote operations.
|
|
19
|
+
* @memberof CommunityClient
|
|
20
|
+
*/
|
|
21
|
+
static get vote(): VoteModule;
|
|
22
|
+
static get supportedChains(): ReyaChainId[];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkB;IACzC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAyC;IAC9D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IAEnC,OAAO;WAKO,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAKpD,OAAO,CAAC,MAAM,CAAC,WAAW;IAS1B;;;;;;OAMG;IACH,WAAkB,IAAI,IAAI,UAAU,CAEnC;IAED,WAAkB,eAAe,IAAI,WAAW,EAAE,CAEjD;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReyaChainId } from '@reyaxyz/common';
|
|
2
|
+
import { GetVoteDetailsParams, GetVoteStatusParams, VoteParams } from './services';
|
|
3
|
+
export default class VoteModule {
|
|
4
|
+
private chainId;
|
|
5
|
+
constructor(chainId: ReyaChainId);
|
|
6
|
+
getVoteDetails(params: GetVoteDetailsParams): Promise<import("../..").VoteDetailsEntity>;
|
|
7
|
+
getVoteStatus(params: GetVoteStatusParams): Promise<import("../..").VoteStatusEntity>;
|
|
8
|
+
vote(params: VoteParams): Promise<import("./services").VoteResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAEL,oBAAoB,EAEpB,mBAAmB,EAEnB,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,OAAO,CAAc;gBAEjB,OAAO,EAAE,WAAW;IAI1B,cAAc,CAAC,MAAM,EAAE,oBAAoB;IAI3C,aAAa,CAAC,MAAM,EAAE,mBAAmB;IAIzC,IAAI,CAAC,MAAM,EAAE,UAAU;CAG9B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { VoteDetailsEntity } from '../../../../types';
|
|
2
|
+
export type GetVoteDetailsParams = {
|
|
3
|
+
id: VoteDetailsEntity['id'];
|
|
4
|
+
};
|
|
5
|
+
export type GetVoteDetailsResult = VoteDetailsEntity;
|
|
6
|
+
export declare const getVoteDetails: ({ id, }: GetVoteDetailsParams) => Promise<GetVoteDetailsResult>;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/services/get-vote-details/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AActD,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAGrD,eAAO,MAAM,cAAc,YAExB,oBAAoB,KAAG,QAAQ,oBAAoB,CAarD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VoteDetailsEntity, VoteStatusEntity } from '../../../../types';
|
|
2
|
+
export type GetVoteStatusParams = {
|
|
3
|
+
address: string;
|
|
4
|
+
id: VoteDetailsEntity['id'];
|
|
5
|
+
};
|
|
6
|
+
export type GetVoteStatusResult = VoteStatusEntity;
|
|
7
|
+
export declare const getVoteStatus: ({ id, address, }: GetVoteStatusParams) => Promise<GetVoteStatusResult>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/services/get-vote-status/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AASxE,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AAGnD,eAAO,MAAM,aAAa,qBAGvB,mBAAmB,KAAG,QAAQ,mBAAmB,CAanD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VoteDetailsEntity } from '../../../../types';
|
|
2
|
+
import { Signer, JsonRpcSigner } from 'ethers';
|
|
3
|
+
export type VoteParams = {
|
|
4
|
+
id: VoteDetailsEntity['id'];
|
|
5
|
+
voted: 'yes' | 'no';
|
|
6
|
+
signer: Signer | JsonRpcSigner;
|
|
7
|
+
};
|
|
8
|
+
export type VoteResult = {
|
|
9
|
+
transactionHash: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const vote: ({ id }: VoteParams) => Promise<VoteResult>;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/services/vote/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;CAChC,CAAC;AACF,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAGF,eAAO,MAAM,IAAI,WAAkB,UAAU,KAAG,QAAQ,UAAU,CAejE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type VoteDetailsEntity = {
|
|
2
|
+
id: number;
|
|
3
|
+
startDate: number;
|
|
4
|
+
endDate: number;
|
|
5
|
+
percentageToPass: number;
|
|
6
|
+
yesCount: number;
|
|
7
|
+
noCount: number;
|
|
8
|
+
};
|
|
9
|
+
export type VoteStatusEntity = {
|
|
10
|
+
votingPower: number;
|
|
11
|
+
hasVoted: boolean;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["export type VoteDetailsEntity = {\n id: number;\n startDate: number; // timestamp in UTC milliseconds\n endDate: number; // timestamp in UTC milliseconds\n percentageToPass: number; // Example: 4%\n yesCount: number;\n noCount: number;\n};\n\nexport type VoteStatusEntity = {\n votingPower: number;\n hasVoted: boolean;\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reyaxyz/community-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/Reya-Labs/reya-off-chain-monorepo.git"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@reyaxyz/common": "0.3.0",
|
|
14
|
+
"ethers": "6.9.0"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/types",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"files": [
|
|
20
|
+
"src/**/*.*",
|
|
21
|
+
"dist/**/*.*",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"prebuild": "rm -rf node_modules && rm -rf dist",
|
|
26
|
+
"build": "tsc -p tsconfig.build.json",
|
|
27
|
+
"ts:check-types": "npx tsc --noEmit",
|
|
28
|
+
"ts:circular-check": "dpdm --no-output --no-tree --no-warning --exit-code circular:1 -T src/index.ts",
|
|
29
|
+
"ts:check": "pnpm ts:check-types && pnpm ts:circular-check",
|
|
30
|
+
"lint:check": "eslint '{src, tests}/**/*.{ts,tsx}'",
|
|
31
|
+
"prettier:check": "npx prettier --log-level silent --check './{src, tests}/**/*.{ts,tsx}'",
|
|
32
|
+
"code-quality:check": "npx concurrently 'pnpm ts:check' 'pnpm prettier:check' 'pnpm lint:check --quiet'",
|
|
33
|
+
"lint:fix": "npx eslint --fix '{src, tests}/**/*.{ts,tsx}'",
|
|
34
|
+
"prettier:fix": "npx prettier --log-level silent --write './{src, tests}/**/*.{ts,tsx}'",
|
|
35
|
+
"test": "npx jest --silent",
|
|
36
|
+
"test:coverage": "npx jest test --coverage",
|
|
37
|
+
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
38
|
+
},
|
|
39
|
+
"packageManager": "pnpm@8.10.4",
|
|
40
|
+
"gitHead": "037cbc040faa91d6148afb21e36a739a017cef89"
|
|
41
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReyaChainId } from '@reyaxyz/common';
|
|
2
|
+
|
|
3
|
+
export type ServiceEnvironment = 'production' | 'test';
|
|
4
|
+
|
|
5
|
+
export type ServiceConfig = {
|
|
6
|
+
chainId: ReyaChainId;
|
|
7
|
+
environment: ServiceEnvironment;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const SERVICE_CONFIG: Record<ServiceEnvironment, ServiceConfig> = {
|
|
11
|
+
production: { environment: 'production', chainId: ReyaChainId.reyaNetwork },
|
|
12
|
+
test: { environment: 'test', chainId: ReyaChainId.reyaCronos },
|
|
13
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SERVICE_CONFIG, ServiceConfig } from './constants';
|
|
2
|
+
import VoteModule from '../modules/vote';
|
|
3
|
+
import { ReyaChainId } from '@reyaxyz/common';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description Client for Community SDK
|
|
7
|
+
*/
|
|
8
|
+
export class CommunityClient {
|
|
9
|
+
private static instance: CommunityClient;
|
|
10
|
+
private static config: ServiceConfig = SERVICE_CONFIG['test'];
|
|
11
|
+
private readonly _vote: VoteModule;
|
|
12
|
+
|
|
13
|
+
private constructor(config: ServiceConfig) {
|
|
14
|
+
CommunityClient.config = { ...CommunityClient.config, ...config };
|
|
15
|
+
this._vote = new VoteModule(CommunityClient.config.chainId);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public static configure(config: ServiceConfig): void {
|
|
19
|
+
CommunityClient.config = config;
|
|
20
|
+
CommunityClient.instance = new CommunityClient(config);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private static getInstance(): CommunityClient {
|
|
24
|
+
if (!CommunityClient.instance) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
'ApiClient is not configured. Please configure it before using.',
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return CommunityClient.instance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Provides access to the VoteModule instance.
|
|
34
|
+
* This getter allows for interacting with vote-related functionalities.
|
|
35
|
+
*
|
|
36
|
+
* @returns {VoteModule} An instance of VoteModule for vote operations.
|
|
37
|
+
* @memberof CommunityClient
|
|
38
|
+
*/
|
|
39
|
+
public static get vote(): VoteModule {
|
|
40
|
+
return CommunityClient.getInstance()._vote;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public static get supportedChains(): ReyaChainId[] {
|
|
44
|
+
return [CommunityClient.config.chainId];
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './vote';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReyaChainId } from '@reyaxyz/common';
|
|
2
|
+
import {
|
|
3
|
+
getVoteDetails,
|
|
4
|
+
GetVoteDetailsParams,
|
|
5
|
+
getVoteStatus,
|
|
6
|
+
GetVoteStatusParams,
|
|
7
|
+
vote,
|
|
8
|
+
VoteParams,
|
|
9
|
+
} from './services';
|
|
10
|
+
|
|
11
|
+
export default class VoteModule {
|
|
12
|
+
private chainId: ReyaChainId;
|
|
13
|
+
|
|
14
|
+
constructor(chainId: ReyaChainId) {
|
|
15
|
+
this.chainId = chainId;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getVoteDetails(params: GetVoteDetailsParams) {
|
|
19
|
+
return getVoteDetails(params);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getVoteStatus(params: GetVoteStatusParams) {
|
|
23
|
+
return getVoteStatus(params);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async vote(params: VoteParams) {
|
|
27
|
+
return vote(params);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { VoteDetailsEntity } from '../../../../types';
|
|
2
|
+
|
|
3
|
+
function mockVoteEntity(id: number): VoteDetailsEntity {
|
|
4
|
+
const daysToAdd = Math.floor(Math.random() * (30 - 14 + 1)) + 14; // Random days between 14 and 30
|
|
5
|
+
return {
|
|
6
|
+
id,
|
|
7
|
+
startDate: Date.now(),
|
|
8
|
+
endDate: Date.now() + 1000 * 60 * 60 * 24 * daysToAdd, // 14 to 30 days from now
|
|
9
|
+
percentageToPass: 4,
|
|
10
|
+
yesCount: Math.floor(Math.random() * 100),
|
|
11
|
+
noCount: Math.floor(Math.random() * 100),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type GetVoteDetailsParams = {
|
|
16
|
+
id: VoteDetailsEntity['id'];
|
|
17
|
+
};
|
|
18
|
+
export type GetVoteDetailsResult = VoteDetailsEntity;
|
|
19
|
+
// TODO: Write proper implementation
|
|
20
|
+
// TODO: Note if vote details cannot be found throw new Error('Vote not found') UI will have logic based on this
|
|
21
|
+
export const getVoteDetails = async ({
|
|
22
|
+
id,
|
|
23
|
+
}: GetVoteDetailsParams): Promise<GetVoteDetailsResult> => {
|
|
24
|
+
return await new Promise((resolve, reject) => {
|
|
25
|
+
setTimeout(
|
|
26
|
+
() => {
|
|
27
|
+
const error = Math.random() * 100 > 50;
|
|
28
|
+
if (error) {
|
|
29
|
+
reject(new Error('Vote not found'));
|
|
30
|
+
}
|
|
31
|
+
resolve(mockVoteEntity(id));
|
|
32
|
+
},
|
|
33
|
+
Math.random() * 100 + 1000,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { VoteDetailsEntity, VoteStatusEntity } from '../../../../types';
|
|
2
|
+
|
|
3
|
+
function mockVoteStatusEntity(): VoteStatusEntity {
|
|
4
|
+
return {
|
|
5
|
+
votingPower: Math.floor(Math.random() * 1000), // Random voting power between 0 and 999
|
|
6
|
+
hasVoted: Math.random() < 0.5, // Randomly true or false
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type GetVoteStatusParams = {
|
|
11
|
+
address: string;
|
|
12
|
+
id: VoteDetailsEntity['id'];
|
|
13
|
+
};
|
|
14
|
+
export type GetVoteStatusResult = VoteStatusEntity;
|
|
15
|
+
|
|
16
|
+
// TODO: Write proper implementation
|
|
17
|
+
export const getVoteStatus = async ({
|
|
18
|
+
id,
|
|
19
|
+
address,
|
|
20
|
+
}: GetVoteStatusParams): Promise<GetVoteStatusResult> => {
|
|
21
|
+
return await new Promise((resolve, reject) => {
|
|
22
|
+
setTimeout(
|
|
23
|
+
() => {
|
|
24
|
+
const error = Math.random() * 100 > 50;
|
|
25
|
+
if (error) {
|
|
26
|
+
reject(new Error(`Vote ${id}, ${address} error`));
|
|
27
|
+
}
|
|
28
|
+
resolve(mockVoteStatusEntity());
|
|
29
|
+
},
|
|
30
|
+
Math.random() * 100 + 1000,
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { VoteDetailsEntity } from '../../../../types';
|
|
2
|
+
import { Signer, JsonRpcSigner } from 'ethers';
|
|
3
|
+
|
|
4
|
+
export type VoteParams = {
|
|
5
|
+
id: VoteDetailsEntity['id'];
|
|
6
|
+
voted: 'yes' | 'no';
|
|
7
|
+
signer: Signer | JsonRpcSigner;
|
|
8
|
+
};
|
|
9
|
+
export type VoteResult = {
|
|
10
|
+
transactionHash: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// TODO: Write proper implementation
|
|
14
|
+
export const vote = async ({ id }: VoteParams): Promise<VoteResult> => {
|
|
15
|
+
return await new Promise((resolve, reject) => {
|
|
16
|
+
setTimeout(
|
|
17
|
+
() => {
|
|
18
|
+
const error = Math.random() * 100 > 50;
|
|
19
|
+
if (error) {
|
|
20
|
+
reject(new Error(`Vote ${id} error`));
|
|
21
|
+
}
|
|
22
|
+
resolve({
|
|
23
|
+
transactionHash: '0x123fake',
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
Math.random() * 100 + 1000,
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type VoteDetailsEntity = {
|
|
2
|
+
id: number;
|
|
3
|
+
startDate: number; // timestamp in UTC milliseconds
|
|
4
|
+
endDate: number; // timestamp in UTC milliseconds
|
|
5
|
+
percentageToPass: number; // Example: 4%
|
|
6
|
+
yesCount: number;
|
|
7
|
+
noCount: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type VoteStatusEntity = {
|
|
11
|
+
votingPower: number;
|
|
12
|
+
hasVoted: boolean;
|
|
13
|
+
};
|