@unilogin/sdk
Version:
SDK is a JS library, that communicates with relayer. SDK allows managing contract, by creating basic contract-calling messages.
80 lines • 3.31 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var __1 = require("../..");
var ConnectingWallet_1 = require("../../api/wallet/ConnectingWallet");
var DeployingWallet_1 = require("../../api/wallet/DeployingWallet");
var WalletSerializer = /** @class */ (function () {
function WalletSerializer(sdk) {
this.sdk = sdk;
}
WalletSerializer.prototype.serialize = function (state) {
switch (state.kind) {
case 'None':
return { kind: 'None' };
case 'Future':
return {
kind: 'Future',
name: state.name,
wallet: {
contractAddress: state.wallet.contractAddress,
privateKey: state.wallet.privateKey,
ensName: state.wallet.ensName,
gasPrice: state.wallet.gasPrice,
gasToken: state.wallet.gasToken,
},
};
case 'Deploying':
var _a = state.wallet, name_1 = _a.name, privateKey = _a.privateKey, contractAddress = _a.contractAddress, deploymentHash = _a.deploymentHash;
return {
kind: 'Deploying',
wallet: { name: name_1, privateKey: privateKey, contractAddress: contractAddress, deploymentHash: deploymentHash },
};
case 'Connecting':
return {
kind: 'Connecting',
wallet: {
contractAddress: state.wallet.contractAddress,
privateKey: state.wallet.privateKey,
name: state.wallet.name,
},
};
case 'Deployed':
return {
kind: 'Deployed',
wallet: state.wallet.asApplicationWallet,
};
}
};
WalletSerializer.prototype.deserialize = function (state) {
switch (state.kind) {
case 'None':
return { kind: 'None' };
case 'Future':
return {
kind: 'Future',
name: state.name,
wallet: this.sdk.getFutureWalletFactory().createFrom(state.wallet),
};
case 'Deploying':
return {
kind: 'Deploying',
wallet: new DeployingWallet_1.DeployingWallet(state.wallet, this.sdk),
};
case 'Connecting':
return {
kind: 'Connecting',
wallet: new ConnectingWallet_1.ConnectingWallet(state.wallet.contractAddress, state.wallet.name, state.wallet.privateKey, this.sdk),
};
case 'Deployed':
return {
kind: 'Deployed',
wallet: new __1.DeployedWallet(state.wallet.contractAddress, state.wallet.name, state.wallet.privateKey, this.sdk),
};
default:
throw new TypeError('Invalid saved wallet state');
}
};
return WalletSerializer;
}());
exports.WalletSerializer = WalletSerializer;
//# sourceMappingURL=WalletSerializer.js.map
;