Skip to content

Commit

Permalink
Merge pull request #14 from sonicdex/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
joegeorge-git authored Aug 19, 2024
2 parents 6e5d974 + a7a949f commit 22f7583
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 99 deletions.
2 changes: 1 addition & 1 deletion dist/bundle.js

Large diffs are not rendered by default.

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

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

const Artemis = class Artemis {
constructor(connectObj?: { host: string; whitelist: string[] });
constructor(connectObj?: ConnectObjType);
accountId: string;
principalId: string;
walletActive: string;
Expand All @@ -20,14 +24,14 @@ const Artemis = class Artemis {
wallets: [];
canisterActors: {};
connectedWalletInfo: { id: string, icon: string, name: string };
connect(wallet: string, connectObj?: any): string;
autoConnect(connectObj?: any): any;
disconnect(): any;
isLoaded(): any;
getWalletBalance(returnType: string): number;
requestICPTransfer(transferRequest: any): any;
getCanisterActor(canisterId: string, idl: any, isAnon: boolean , isForced:boolean): any;
batchTransact(transactions: BatchTransactType): any;
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[]]
}

Expand All @@ -39,7 +43,7 @@ const BatchTransact = class BatchTransact {
completed: string[];
previousStep: string;
activeStep: string;
nextStep: string;
nextStep: ()=>void;
failedSteps: string[];
transactionResults: {};
trxArray:[];
Expand All @@ -50,8 +54,5 @@ const BatchTransact = class BatchTransact {

const principalIdFromHex:(params:string)=> {};
declare module 'artemis-web3-adapter' {
export { Artemis }
export { BatchTransact };
export{ principalIdFromHex };
export { ArtemisAdapter};
export { Artemis , BatchTransact , principalIdFromHex , ArtemisAdapter , TransactionItem , BatchTransactType}
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "artemis-web3-adapter",
"version": "1.1.5",
"version": "1.2.0",
"description": "dfinity wallet adapter for connecting different wallets in IC",
"main": "index.js",
"scripts": {
Expand All @@ -11,11 +11,11 @@
"dependencies": {
"@astrox/sdk-web": "^0.1.41",
"@astrox/sdk-webview": "^0.1.41",
"@dfinity/agent": "^1.2.0",
"@dfinity/auth-client": "^1.2.0",
"@dfinity/candid": "^1.2.0",
"@dfinity/identity": "^1.2.0",
"@dfinity/principal": "^1.2.0",
"@dfinity/agent": "^2.0.0",
"@dfinity/auth-client": "^2.0.0",
"@dfinity/candid": "^2.0.0",
"@dfinity/identity": "^2.0.0",
"@dfinity/principal": "^2.0.0",
"@fort-major/msq-client": "^0.3.4",
"@fort-major/msq-shared": "^0.3.3",
"buffer": "^6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const Artemis = class Artemis {
}
return this.principalId;
} catch (error) {
return false;
throw error;
}
};
async disconnect() {
Expand Down
50 changes: 31 additions & 19 deletions src/libs/batchTransact.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,38 @@ export const BatchTransaction = class BatchTransaction {
var trxIndex = 0;
self.trxArray.forEach((subArray, i) => {
subArray.forEach((el, j) => {

self.trxArray[i][j].stepIndex = trxIndex;
self.trxArray[i][j].state = 'idle';

self.trxArray[i][j].onSuccessMain = async (data, _this) => {
const stepIndex = _this.stepIndex;
const onSucessCall = el.onSuccess;
const onFailCall = el.onFail
const onFailCall = el.onError;
const ErrorStat = data.err ? data.err : data.Err ? data.Err : data.ERR;


if (data.err || data.Err || data.ERR) {

if (ErrorStat && (JSON.stringify(ErrorStat) != el?.skipCondition)) {
self.failedSteps.push(self.stepsList[stepIndex]);
self.transactionResults[self.stepsList[stepIndex]] = data;
self.transactionResults[self.stepsList[stepIndex]] = ErrorStat;
self.state = 'error';
_this.state = 'error';
if (onFailCall) await onFailCall(data)
if (onFailCall) await onFailCall(ErrorStat)
return false;
} else {
self.completed.push(self.stepsList[stepIndex]);
self.activeStep = self.stepsList[stepIndex + 1];
self.transactionResults[self.stepsList[stepIndex]] = data;
self.transactionResults[self.stepsList[stepIndex]] = ErrorStat ? ErrorStat : data;
_this.state = 'done';
}
if (_this.updateNextStep && self.trxArray[(i + 1)]) {
await _this.updateNextStep(data, self.trxArray[(i + 1)][0]);
await _this.updateNextStep(data, self.trxArray[(i + 1)]);
}
if (onSucessCall) await onSucessCall(data)
if (onSucessCall) await onSucessCall(ErrorStat ? ErrorStat : data)
};

self.trxArray[i][j].onFailMain = async (err, _this) => {
const onFailCall = el.onFail
const stepIndex = _this.stepIndex;;
const onFailCall = el.onFailCall;
const stepIndex = _this.stepIndex;
console.error(`error in ${self.stepsList[stepIndex]} `, self.trxArray[i][j])
console.error(err);
self.failedSteps.push(self.stepsList[stepIndex]);
Expand Down Expand Up @@ -118,14 +120,24 @@ export const BatchTransaction = class BatchTransaction {
if (trxStepItem.length) {
for (const trxItem of trxStepItem) {
if (self.state == 'error' || self.state == 'done') break;
var actor = await self._adapterObj.getCanisterActor(trxItem.canisterId, trxItem.idl, false, true);
var resp = false;
if (trxItem.methodName) {
if (trxItem.args) { resp = await actor[trxItem.methodName](...trxItem.args); }
else { resp = await actor[trxItem.methodName](); }
} else { await trxItem.onFailMain(resp); }
if (resp) { await trxItem.onSuccessMain(resp, trxItem); }
else { await trxItem.onFailMain(resp, trxItem); }
try {
var actor = await self._adapterObj.getCanisterActor(trxItem.canisterId, trxItem.idl, false, true);
var resp = false;
if (trxItem.methodName) {
if (trxItem.args) {
resp = await actor[trxItem.methodName](...trxItem.args);
}
else { resp = await actor[trxItem.methodName](); }
} else {
await trxItem.onFailMain(resp);
}
if (resp) { await trxItem.onSuccessMain(resp, trxItem); }
else {
await trxItem.onFailMain(resp, trxItem);
}
} catch (error) {
await trxItem.onFailMain(false, trxItem);
}
}
}
}
Expand Down
57 changes: 1 addition & 56 deletions src/wallets/nfid.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const nfid = {
onSuccess: async () => {
returnData = await continueLogin();
resolve(returnData);
}
},
});
} else {
returnData = await continueLogin();
Expand All @@ -40,61 +40,6 @@ export const nfid = {
self.disConnectWallet = async function () { await self.authClient.logout() }
return { accountId: sid, principalId: principal.toString() }
}

// var isConnected = await self.authClient.isAuthenticated();

// var identity = await self.authClient.getIdentity();
// var principal = await identity?.getPrincipal();

// console.log(identity ,principal )
// await new Promise((resolve, reject) => {

// self.authClient.login({
// identityProvider:'https://nfid.one/authenticate/?applicationName='+window.location.hostname,
// windowOpenerFeatures: `left=${window.screen.width / 2 - 525 / 2}, top=${window.screen.height / 2 - 705 / 2}, toolbar=0,location=0,menubar=0,width=525,height=705`,
// onSuccess: resolve,
// onError: reject,
// })
// })
// var identity = self.authClient.getIdentity();
// var principal = identity.getPrincipal().toString();



// // console.log(identity , identity);


// // if (!isConnected) {
// // await authClient.login({
// // identityProvider: 'https://nfid.one/authenticate',
// // windowOpenerFeatures:
// // `left=${window.screen.width / 2 - 525 / 2}, `+
// // `top=${window.screen.height / 2 - 705 / 2},` +
// // `toolbar=0,location=0,menubar=0,width=525,height=705`,
// // onSuccess: async (data) => {


// // var identity = authClient.getIdentity();
// // var authClient = await AuthClient.create({});
// // console.log(data);

// // // returnData = await continueLogin();
// // // resolve(returnData);
// // }
// // });
// // }

// // var identity = authClient.getIdentity();

// // var isConnected = await authClient.isAuthenticated();

// // console.log(identity , isConnected);
// // authClient.login({
// // // TODO: local
// // identityProvider: 'https://nfid.one' + `/authenticate/?applicationName=sonic`,
// // onSuccess: resolve,
// // onError: reject,
// // })
})
}
}
5 changes: 4 additions & 1 deletion src/wallets/plug.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export const plug = {
};

return { accountId: sess.accountId, principalId: prinObj.toString() }
} catch (e) { return false; }
} catch (e) {
console.error(e);
throw e;
}
},
disConnectWallet: async function () {
await window.ic.plug.disconnect();
Expand Down

0 comments on commit 22f7583

Please sign in to comment.