Skip to content

Commit

Permalink
Merge pull request #17 from sonicdex/development
Browse files Browse the repository at this point in the history
Ver 1.2.4
  • Loading branch information
memecakedev authored Oct 24, 2024
2 parents 22f7583 + b99276e commit 616a060
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 70 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Sonic

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion dist/bundle.js

Large diffs are not rendered by default.

96 changes: 48 additions & 48 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
interface TransactionItem {
canisterId: string;
methodName: string;
args: any;
idl: any;
onSuccess: any;
onFail: any;
updateNextStep: any;
skipCondition:string
canisterId: string;
methodName: string;
args: any;
idl: any;
onSuccess: any;
onFail: any;
updateNextStep: any;
skipCondition: string | string[];
}
type BatchTransactType = {
[key: string]: TransactionItem[];
[key: string]: TransactionItem[];
};

type ConnectObjType = { host: string; whitelist: string[] }
type ConnectObjType = {host: string; whitelist: string[]};

const Artemis = class Artemis {
constructor(connectObj?: ConnectObjType);
accountId: string;
principalId: string;
walletActive: string;
provider: any;
balance: number;
wallets: [];
canisterActors: {};
connectedWalletInfo: { id: string, icon: string, name: string };
connect(wallet: string, connectObj?: ConnectObjType):Promise<string> ;
autoConnect(connectObj?: ConnectObjType): Promise<string>;
disconnect(): Promise<any>;
isLoaded(): Promise<any>;
getWalletBalance(returnType: string): Promise<number>;
requestICPTransfer(transferRequest: any): Promise<any>;
getCanisterActor(canisterId: string, idl: any, isAnon: boolean , isForced?:boolean): Promise<any>;
batchTransact(transactions: BatchTransactType): Promise<any>;
trxArray:[TransactionItem[]]
}
constructor(connectObj?: ConnectObjType);
accountId: string;
principalId: string;
walletActive: string;
provider: any;
balance: number;
wallets: [];
canisterActors: {};
connectedWalletInfo: {id: string; icon: string; name: string};
connect(wallet: string, connectObj?: ConnectObjType): Promise<string>;
autoConnect(connectObj?: ConnectObjType): Promise<string>;
disconnect(): Promise<any>;
isLoaded(): Promise<any>;
getWalletBalance(returnType: string): Promise<number>;
requestICPTransfer(transferRequest: any): Promise<any>;
getCanisterActor(canisterId: string, idl: any, isAnon: boolean, isForced?: boolean): Promise<any>;
batchTransact(transactions: BatchTransactType): Promise<any>;
trxArray: [TransactionItem[]];
};

const BatchTransact = class BatchTransact {
state: 'idle' | 'running' | 'error' | 'done';
transactionLlist: BatchTransactType;
stepsList: string[];
pending: string[];
completed: string[];
previousStep: string;
activeStep: string;
nextStep: ()=>void;
failedSteps: string[];
transactionResults: {};
trxArray:[];
execute(): any;
retryExecute(): any;
constructor(transactionList: any, artemis: Artemis)
}
state: "idle" | "running" | "error" | "done";
transactionLlist: BatchTransactType;
stepsList: string[];
pending: string[];
completed: string[];
previousStep: string;
activeStep: string;
nextStep: () => void;
failedSteps: string[];
transactionResults: {};
trxArray: [];
execute(): any;
retryExecute(): any;
constructor(transactionList: any, artemis: Artemis);
};

const principalIdFromHex:(params:string)=> {};
declare module 'artemis-web3-adapter' {
export { Artemis , BatchTransact , principalIdFromHex , ArtemisAdapter , TransactionItem , BatchTransactType}
}
const principalIdFromHex: (params: string) => {};
declare module "artemis-web3-adapter" {
export {Artemis, BatchTransact, principalIdFromHex, ArtemisAdapter, TransactionItem, BatchTransactType};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "artemis-web3-adapter",
"version": "1.2.0",
"version": "1.2.4",
"description": "dfinity wallet adapter for connecting different wallets in IC",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,26 @@ export const Artemis = class Artemis {
let actor = false;
if (isAnon) {
if (isForced) {
const pubAgent = new HttpAgent({ AnonymousIdentity, host: this._connectObject.host });
const pubAgent = HttpAgent.createSync({ AnonymousIdentity, host: this._connectObject.host });
actor = await Actor.createActor(idl, { agent: pubAgent, canisterId: canisterId })
this.anoncanisterActors[canisterId] = actor;
if(actor) this.anoncanisterActors[canisterId] = actor;
} else if (this.anoncanisterActors[canisterId])
actor = this.anoncanisterActors[canisterId]
else {
const pubAgent = new HttpAgent({ AnonymousIdentity, host: this._connectObject.host });
const pubAgent = HttpAgent.createSync({ AnonymousIdentity, host: this._connectObject.host });
actor = await Actor.createActor(idl, { agent: pubAgent, canisterId: canisterId })
this.anoncanisterActors[canisterId] = actor;
if(actor)this.anoncanisterActors[canisterId] = actor;
}
} else {
if (isForced) {
actor = await this.provider.createActor({ canisterId: canisterId, interfaceFactory: idl });
this.canisterActors[canisterId] = actor;
if(actor) this.canisterActors[canisterId] = actor;
}
else if (this.canisterActors[canisterId]) {
actor = this.canisterActors[canisterId];
} else {
actor = await this.provider.createActor({ canisterId: canisterId, interfaceFactory: idl });
this.canisterActors[canisterId] = actor;
if(actor)this.canisterActors[canisterId] = actor;
}
}
return actor;
Expand Down
7 changes: 3 additions & 4 deletions src/libs/batchTransact.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export const BatchTransaction = class BatchTransaction {
const onSucessCall = el.onSuccess;
const onFailCall = el.onError;
const ErrorStat = data.err ? data.err : data.Err ? data.Err : data.ERR;



if (ErrorStat && (JSON.stringify(ErrorStat) != el?.skipCondition)) {
if (ErrorStat && !el?.skipCondition.includes((JSON.stringify(ErrorStat)))) {
self.failedSteps.push(self.stepsList[stepIndex]);
self.transactionResults[self.stepsList[stepIndex]] = ErrorStat;
self.state = 'error';
Expand All @@ -70,6 +67,7 @@ export const BatchTransaction = class BatchTransaction {
self.activeStep = self.stepsList[stepIndex];
self.state = 'error';
_this.state = 'error';
self._info = err;
if (onFailCall) await onFailCall(err)
return false;
}
Expand Down Expand Up @@ -136,6 +134,7 @@ export const BatchTransaction = class BatchTransaction {
await trxItem.onFailMain(resp, trxItem);
}
} catch (error) {
this._info = error;
await trxItem.onFailMain(false, trxItem);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/wallets/astroxme.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const astrox = {
}

var sid = window.icx.wallet.accountId;
self.agent = new HttpAgent({ identity: window.icx.identity, host: connectObj.host });
self.agent = HttpAgent.createSync({ identity: window.icx.identity, host: connectObj.host });

// self.createActor = async function (connObj = { canisterId: '', interfaceFactory: false }) {
// if (!connObj.canisterId || !connObj.interfaceFactory) return false;
Expand All @@ -75,7 +75,7 @@ export const astrox = {
}
var sid = await getAccountIdentifier(window.ic.astrox.principal.toString());

self.agent = new HttpAgent({ identity: window.ic.astrox.identity, host: connectObj.host });
self.agent = HttpAgent.createSync({ identity: window.ic.astrox.identity, host: connectObj.host });

self.createActor = async function (connObj = { canisterId: '', interfaceFactory: false }) {
if (!connObj.canisterId || !connObj.interfaceFactory) return false;
Expand Down
4 changes: 2 additions & 2 deletions src/wallets/dfinity.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export const dfinity = {
async function continueLogin() {
var identity = await self.authClient.getIdentity();
var principal = await identity?.getPrincipal();
self.agent = new HttpAgent({ identity: identity, host: connectObj.host });
self.agent = HttpAgent.createSync({ identity: identity, host: connectObj.host });
var sid = await getAccountIdentifier(identity?.getPrincipal().toString());

self.createActor = async function (connObj = { canisterId: '', interfaceFactory: false }) {
if (!connObj.canisterId || !connObj.interfaceFactory) return false;
return await Actor.createActor(connObj.interfaceFactory, { agent: this.agent, canisterId: connObj.canisterId });
};
self.createAgent = async function () {
return new HttpAgent({ identity: identity, host: connectObj.host });
return HttpAgent.createSync({ identity: identity, host: connectObj.host });
};
self.getPrincipal = async function () { return identity.getPrincipal() }
self.disConnectWallet = async function () { await self.authClient.logout() }
Expand Down
4 changes: 2 additions & 2 deletions src/wallets/msq.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export const metaMask = window?.ethereum?.isMetaMask ? {
const identity = await self.msq.requestLogin();

var principal = await identity?.getPrincipal();
self.agent = new HttpAgent({ identity: identity, host: connectObj.host });
self.agent = HttpAgent.createSync({ identity: identity, host: connectObj.host });
var sid = await getAccountIdentifier(identity?.getPrincipal().toString());

self.createActor = async function (connObj = { canisterId: '', interfaceFactory: false }) {
if (!connObj.canisterId || !connObj.interfaceFactory) return false;
return await Actor.createActor(connObj.interfaceFactory, { agent: this.agent, canisterId: connObj.canisterId });
};
self.createAgent = async function () {
return new HttpAgent({ identity: identity, host: connectObj.host });
return HttpAgent.createSync({ identity: identity, host: connectObj.host });
};
self.getPrincipal = async function () { return identity.getPrincipal() }
self.disConnectWallet = async function () { await self.msq.requestLogout() }
Expand Down
4 changes: 2 additions & 2 deletions src/wallets/nfid.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export const nfid = {
async function continueLogin() {
var identity = await self.authClient.getIdentity();
var principal = await identity?.getPrincipal();
self.agent = new HttpAgent({ identity: identity, host: connectObj.host });
self.agent = HttpAgent.createSync({ identity: identity, host: connectObj.host });
var sid = await getAccountIdentifier(identity?.getPrincipal().toString());

self.createActor = async function (connObj = { canisterId: '', interfaceFactory: false }) {
if (!connObj.canisterId || !connObj.interfaceFactory) return false;
return await Actor.createActor(connObj.interfaceFactory, { agent: this.agent, canisterId: connObj.canisterId });
};
self.createAgent = async function () {
return new HttpAgent({ identity: identity, host: connectObj.host });
return HttpAgent.createSync({ identity: identity, host: connectObj.host });
};
self.getPrincipal = async function () { return identity.getPrincipal() }
self.disConnectWallet = async function () { await self.authClient.logout() }
Expand Down
4 changes: 2 additions & 2 deletions src/wallets/stoic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export const stoic = {
let getAcnts = await identity.accounts();
getAcnts = JSON.parse(getAcnts);

this.agent = new HttpAgent({ identity, host: connectObj.host });
this.agent = HttpAgent.createSync({ identity, host: connectObj.host });

this.createActor = async function (connObj = { canisterId: '', interfaceFactory: false }) {
if (!connObj.canisterId || !connObj.interfaceFactory) return false;
return await Actor.createActor(connObj.interfaceFactory, { agent: this.agent, canisterId: connObj.canisterId });
};
this.createAgent = function () {
return new HttpAgent({ identity, host: connectObj.host });
return HttpAgent.createSync({ identity, host: connectObj.host });
};
this.getPrincipal = function () { return identity.getPrincipal() }
this.disConnectWallet = async function () {
Expand Down

0 comments on commit 616a060

Please sign in to comment.