Skip to content

Commit fd8ee93

Browse files
committed
chore(v1.2.2 dist): v1.2.2 dist
1 parent 0af2802 commit fd8ee93

File tree

9 files changed

+140
-124
lines changed

9 files changed

+140
-124
lines changed

dist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@idealight-labs/anyweb-js-sdk",
33
"description": "AnyWeb JavaScript Software Development Kit",
4-
"version": "1.2.1",
4+
"version": "1.2.2",
55
"license": "LGPL-3.0",
66
"author": "common@idealight.ltd",
77
"repository": {

dist/src/config.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
* @since 2022/2/12
44
*/
55
export declare const BASE_URL = "https://app.anyweb.cc/#/";
6-
export declare const API_BASE_URL = "https://api.anyweb.cc";

dist/src/config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.API_BASE_URL = exports.BASE_URL = void 0;
3+
exports.BASE_URL = void 0;
44
/**
55
* @author Littleor <me@littleor.cn>
66
* @since 2022/2/12
77
*/
88
exports.BASE_URL = 'https://app.anyweb.cc/#/';
9-
exports.API_BASE_URL = 'https://api.anyweb.cc';

dist/src/interface/provider.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export interface IIframeData {
6969
type: 'event' | 'callback' | 'router' | 'default';
7070
data: unknown;
7171
success?: boolean;
72+
message?: string;
73+
code: number;
7274
}
7375
export interface IIframeEventData {
7476
type: 'changeNetwork' | 'changeChain';

dist/src/provider.js

Lines changed: 113 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -152,60 +152,60 @@ class Provider {
152152
*/
153153
// eslint-disable-next-line @typescript-eslint/no-explicit-any
154154
rawRequest(method, params) {
155-
var _a, _b, _c, _d, _e, _f;
155+
var _a, _b, _c, _d, _e, _f, _g;
156156
return __awaiter(this, void 0, void 0, function* () {
157157
if (!Provider.ready) {
158158
throw new common_1.ProviderRpcError(common_1.ProviderErrorCode.SDKNotReady, "Provider is not ready, please use on('ready', callback) to listen to ready event");
159159
}
160-
switch (method) {
161-
case 'cfx_requestAccounts':
162-
return this.rawRequest('cfx_accounts');
163-
case 'cfx_accounts':
164-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug('[AnyWeb]', { params });
165-
const scopes = params[0].scopes;
166-
let result;
167-
try {
168-
result = (yield (0, common_1.callIframe)('pages/dapp/auth', {
169-
appId: this.appId,
170-
params: params ? JSON.stringify(params[0]) : '',
171-
chainId: this.chainId,
172-
authType: 'check_auth',
173-
scopes: scopes,
174-
silence: true,
175-
}, this));
176-
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.debug('[AnyWeb]', 'silent auth result', result);
177-
}
178-
catch (e) {
179-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.debug('[AnyWeb]', 'need to auth', e);
180-
result = (yield (0, common_1.callIframe)('pages/dapp/auth', {
181-
appId: this.appId,
182-
params: params ? JSON.stringify(params[0]) : '',
183-
chainId: this.chainId,
184-
authType: 'account',
185-
scopes: scopes,
186-
}, this));
187-
}
188-
result.scopes = scopes;
189-
this.events.onAccountsChanged &&
190-
this.events.onAccountsChanged(result.address);
191-
this.events.onChainChanged &&
192-
this.events.onChainChanged(String(result.chainId));
193-
this.events.onNetworkChanged &&
194-
this.events.onNetworkChanged(String(result.networkId));
195-
if (scopes.length > 0) {
196-
return {
197-
address: result.address,
198-
code: result.code,
199-
scopes: scopes,
200-
chainId: result.chainId,
201-
networkId: result.networkId,
202-
};
203-
}
204-
else {
205-
return false;
206-
}
207-
case 'cfx_sendTransaction':
208-
try {
160+
try {
161+
switch (method) {
162+
case 'cfx_requestAccounts':
163+
return this.rawRequest('cfx_accounts');
164+
case 'cfx_accounts':
165+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug('[AnyWeb]', { params });
166+
const scopes = params[0].scopes;
167+
let result;
168+
try {
169+
result = (yield (0, common_1.callIframe)('pages/dapp/auth', {
170+
appId: this.appId,
171+
params: params ? JSON.stringify(params[0]) : '',
172+
chainId: this.chainId,
173+
authType: 'check_auth',
174+
scopes: scopes,
175+
silence: true,
176+
}, this));
177+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.debug('[AnyWeb]', 'silent auth result', result);
178+
}
179+
catch (e) {
180+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.debug('[AnyWeb]', 'need to auth', e);
181+
result = (yield (0, common_1.callIframe)('pages/dapp/auth', {
182+
appId: this.appId,
183+
params: params ? JSON.stringify(params[0]) : '',
184+
chainId: this.chainId,
185+
authType: 'account',
186+
scopes: scopes,
187+
}, this));
188+
}
189+
result.scopes = scopes;
190+
this.events.onAccountsChanged &&
191+
this.events.onAccountsChanged(result.address);
192+
this.events.onChainChanged &&
193+
this.events.onChainChanged(String(result.chainId));
194+
this.events.onNetworkChanged &&
195+
this.events.onNetworkChanged(String(result.networkId));
196+
if (scopes.length > 0) {
197+
return {
198+
address: result.address,
199+
code: result.code,
200+
scopes: scopes,
201+
chainId: result.chainId,
202+
networkId: result.networkId,
203+
};
204+
}
205+
else {
206+
return false;
207+
}
208+
case 'cfx_sendTransaction':
209209
let authType;
210210
const payload = params[0];
211211
const to = payload.to;
@@ -218,7 +218,6 @@ class Provider {
218218
else {
219219
authType = 'createContract';
220220
}
221-
// createContract
222221
return yield (0, common_1.callIframe)('pages/dapp/auth', {
223222
appId: this.appId,
224223
chainId: this.chainId,
@@ -230,86 +229,88 @@ class Provider {
230229
: '',
231230
authType: authType,
232231
}, this);
233-
}
234-
catch (e) {
235-
throw new common_1.ProviderRpcError(common_1.ProviderErrorCode.SendTransactionError, 'Error to sendTransaction: ' + e);
236-
}
237-
case 'anyweb_importAccount':
238-
try {
232+
case 'anyweb_importAccount':
239233
return yield (0, common_1.callIframe)('pages/dapp/auth', {
240234
appId: this.appId,
241235
chainId: this.chainId,
242236
params: params ? JSON.stringify(params[0]) : JSON.stringify({}),
243237
authType: 'importAccount',
244238
}, this);
245-
}
246-
catch (e) {
247-
throw new common_1.ProviderRpcError(common_1.ProviderErrorCode.ImportAddressError, 'Error to import Address: ' + e);
248-
}
249-
case 'anyweb_version':
250-
return package_json_1.default.version;
251-
case 'anyweb_home':
252-
return yield (0, common_1.callIframe)('pages/index/home', {
253-
appId: this.appId,
254-
chainId: this.chainId,
255-
params: params ? JSON.stringify(params) : '',
256-
waitResult: false,
257-
}, this);
258-
case 'exit_accounts':
259-
return yield (0, common_1.callIframe)('pages/dapp/auth', {
260-
appId: this.appId,
261-
chainId: this.chainId,
262-
params: params ? JSON.stringify(params) : '',
263-
authType: 'exit_accounts',
264-
silence: true,
265-
}, this);
266-
case 'anyweb_identify':
267-
let identifyResult;
268-
try {
269-
identifyResult = yield (0, common_1.callIframe)('pages/user/identify', {
239+
case 'anyweb_version':
240+
return package_json_1.default.version;
241+
case 'anyweb_home':
242+
return yield (0, common_1.callIframe)('pages/index/home', {
270243
appId: this.appId,
271244
chainId: this.chainId,
272245
params: params ? JSON.stringify(params) : '',
273-
authType: 'check_identify',
274-
silence: true,
246+
waitResult: false,
275247
}, this);
276-
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.debug('[AnyWeb]', 'Check identify result', identifyResult);
277-
}
278-
catch (e) {
279-
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.debug('[AnyWeb]', 'need to identify', e);
280-
identifyResult = yield (0, common_1.callIframe)('pages/user/identify', {
248+
case 'exit_accounts':
249+
return this.rawRequest('anyweb_revoke', params);
250+
case 'anyweb_revoke':
251+
return yield (0, common_1.callIframe)('pages/dapp/auth', {
281252
appId: this.appId,
282253
chainId: this.chainId,
283254
params: params ? JSON.stringify(params) : '',
284-
authType: 'identify',
255+
authType: 'exit_accounts',
256+
silence: true,
285257
}, this);
286-
}
287-
return identifyResult;
288-
case 'anyweb_logout':
289-
// Logout the account of AnyWeb
290-
return yield (0, common_1.callIframe)('pages/dapp/auth', {
291-
appId: this.appId,
292-
chainId: this.chainId,
293-
params: params ? JSON.stringify(params) : '',
294-
authType: 'logout',
295-
silence: true,
296-
}, this);
297-
case 'anyweb_loginstate':
298-
try {
258+
case 'anyweb_identify':
259+
let identifyResult;
260+
try {
261+
identifyResult = yield (0, common_1.callIframe)('pages/user/identify', {
262+
appId: this.appId,
263+
chainId: this.chainId,
264+
params: params ? JSON.stringify(params) : '',
265+
authType: 'check_identify',
266+
silence: true,
267+
}, this);
268+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.debug('[AnyWeb]', 'Check identify result', identifyResult);
269+
}
270+
catch (e) {
271+
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.debug('[AnyWeb]', 'need to identify', e);
272+
identifyResult = yield (0, common_1.callIframe)('pages/user/identify', {
273+
appId: this.appId,
274+
chainId: this.chainId,
275+
params: params ? JSON.stringify(params) : '',
276+
authType: 'identify',
277+
}, this);
278+
}
279+
return identifyResult;
280+
case 'anyweb_logout':
281+
// Logout the account of AnyWeb
299282
return yield (0, common_1.callIframe)('pages/dapp/auth', {
300283
appId: this.appId,
301-
params: '',
302284
chainId: this.chainId,
303-
authType: 'check_login',
285+
params: params ? JSON.stringify(params) : '',
286+
authType: 'logout',
304287
silence: true,
305288
}, this);
306-
}
307-
catch (e) {
308-
(_f = this.logger) === null || _f === void 0 ? void 0 : _f.debug('[AnyWeb]', 'need to login', e);
309-
return false;
310-
}
311-
default:
312-
throw new common_1.ProviderRpcError(common_1.ProviderErrorCode.UnsupportedMethod, 'Unsupported Method: ' + method);
289+
case 'anyweb_loginstate':
290+
try {
291+
return yield (0, common_1.callIframe)('pages/dapp/auth', {
292+
appId: this.appId,
293+
params: '',
294+
chainId: this.chainId,
295+
authType: 'check_login',
296+
silence: true,
297+
}, this);
298+
}
299+
catch (e) {
300+
(_f = this.logger) === null || _f === void 0 ? void 0 : _f.debug('[AnyWeb]', 'need to login', e);
301+
return false;
302+
}
303+
default:
304+
throw new common_1.ProviderRpcError(common_1.ProviderErrorCode.UnsupportedMethod, 'Unsupported Method: ' + method);
305+
}
306+
}
307+
catch (e) {
308+
// const codeList = {
309+
// cfx_sendTransaction: ProviderErrorCode.SendTransactionError,
310+
// anyweb_importAccount: ProviderErrorCode.ImportAddressError,
311+
// }
312+
(_g = this.logger) === null || _g === void 0 ? void 0 : _g.info(`Error when handler request '${method}'!`);
313+
throw new common_1.ProviderRpcError(common_1.ProviderErrorCode.RequestError, (0, common_1.isObject)(e) && 'message' in e ? e.message : e, (0, common_1.isObject)(e) && 'data' in e ? e.data : {});
313314
}
314315
});
315316
}

dist/src/utils/address.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export declare enum AddressType {
88
/**
99
* Get the type of an address.
1010
* @param address
11+
* @param logger
1112
*/
1213
export declare const getAddressType: (address: string, logger?: ConsoleLike) => AddressType;

dist/src/utils/address.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var AddressType;
1212
/**
1313
* Get the type of an address.
1414
* @param address
15+
* @param logger
1516
*/
1617
const getAddressType = (address, logger = console) => {
1718
const decodeResult = (0, conflux_address_js_1.decode)(address);

dist/src/utils/common.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export declare const isFullScreen: () => boolean;
1313
*/
1414
export declare function sha512(str: string): string;
1515
export declare const isObject: (obj: unknown) => boolean;
16-
export declare const sendMessageToApp: ({ data, type, success, }: IIframeData) => void;
16+
export declare const sendMessageToApp: ({ data, type, success, code, }: IIframeData) => void;
1717
export declare const createIframe: (url: string, logger?: ConsoleLike | undefined) => Promise<void>;
1818
export declare const getIframe: (url: string, onClose: () => void, silence?: boolean, logger?: ConsoleLike | undefined) => Promise<() => void>;
1919
export declare const callIframe: (path: string, { appId, params, chainId, scopes, authType, waitResult, silence, }: IIframeOptions, provider: Provider) => Promise<unknown>;
@@ -27,6 +27,7 @@ export declare enum ProviderErrorCode {
2727
Disconnected = 4900,
2828
ChainDisconnected = 4901,
2929
SDKNotReady = 5000,
30+
SDKTimeOut = 5001,
3031
ParamsError = 6000,
3132
RequestError = 7000,
3233
SendTransactionError = 7001,
@@ -35,5 +36,5 @@ export declare enum ProviderErrorCode {
3536
export declare class ProviderRpcError extends Error implements IProviderRpcError {
3637
code: number;
3738
data?: unknown;
38-
constructor(code: ProviderErrorCode, message: string, logger?: ConsoleLike);
39+
constructor(code: ProviderErrorCode, message: string, data?: {}, logger?: ConsoleLike);
3940
}

0 commit comments

Comments
 (0)