connect(
+ Constructor
new MyDogeWallet()
Methods
(async) connect(onSuccessopt, onErroropt) → {Promise.<{approved: boolean, address: string, publicKey: string, balance: number}>}
Initiates a connection request with the wallet.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successful connection. Receives an object containing the wallet address and balance. |
onError | function | <optional>
| Optional callback function to execute upon connection error. |
Returns:Promise object representing the outcome of the connection attempt, resolving to an object with the connected address information.
- Type:
- Promise.<{approved: boolean, address: string, publicKey: string, balance: number}>
Exampleconnect(
(result) => console.log(`Connected to wallet: ${result.address}`),
(error) => console.error(`Connection failed: ${error}`)
).then(result => console.log(result.address))
- .catch(error => console.error(error));
(async) disconnect(onSuccessopt, onErroropt) → {Promise.<void>}
Disconnects the current session with the wallet.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successful disconnection. |
onError | function | <optional>
| Optional callback function to execute upon error in disconnecting. |
Returns:Promise object representing the disconnection outcome.
- Type:
- Promise.<void>
Exampledisconnect(
+ .catch(error => console.error(error));
(async) disconnect(onSuccessopt, onErroropt) → {Promise.<void>}
Disconnects the current session with the wallet.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successful disconnection. |
onError | function | <optional>
| Optional callback function to execute upon error in disconnecting. |
Returns:Promise object representing the disconnection outcome.
- Type:
- Promise.<void>
Exampledisconnect(
() => console.log(`Disconnected from wallet`),
(error) => console.error(`Disconnection failed: ${error}`)
).then(() => console.log('Disconnected from wallet'))
- .catch(error => console.error(error));
(async) getBalance(onSuccessopt, onErroropt) → {Promise.<{address: string, balance: number}>}
Retrieves the balance from the connected wallet.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successful retrieval of balance. Receives an object containing the wallet address and balance. |
onError | function | <optional>
| Optional callback function to execute upon error in retrieving balance. |
Returns:Promise object representing the outcome of the balance retrieval, resolving to an object with the wallet address and balance.
- Type:
- Promise.<{address: string, balance: number}>
ExamplegetBalance(
+ .catch(error => console.error(error));
(async) getBalance(onSuccessopt, onErroropt) → {Promise.<{address: string, balance: number}>}
Retrieves the balance from the connected wallet.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successful retrieval of balance. Receives an object containing the wallet address and balance. |
onError | function | <optional>
| Optional callback function to execute upon error in retrieving balance. |
Returns:Promise object representing the outcome of the balance retrieval, resolving to an object with the wallet address and balance.
- Type:
- Promise.<{address: string, balance: number}>
ExamplegetBalance(
(result) => console.log(`Connected to wallet: ${result.balance}`),
(error) => console.error(`Connection failed: ${error}`)
).then(result => console.log(result.balance))
- .catch(error => console.error(error));
(async) getConnectionStatus(onSuccessopt, onErroropt) → {Promise.<{connected: boolean, address: string, selectedWalletAddress: string}>}
Retrieves the connection status with the wallet.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successfully retrieving the status. Receives an object containing the wallet address, selected wallet address, and connection status. |
onError | function | <optional>
| Optional callback function to execute upon error in retrieving the connection status. |
Returns:Promise object representing the outcome of the connection status retrieval, resolving to an object with the wallet address, selected wallet address, and connection status.
- Type:
- Promise.<{connected: boolean, address: string, selectedWalletAddress: string}>
ExamplegetConnectionStatus(
+ .catch(error => console.error(error));
(async) getConnectionStatus(onSuccessopt, onErroropt) → {Promise.<{connected: boolean, address: string, selectedWalletAddress: string}>}
Retrieves the connection status with the wallet.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successfully retrieving the status. Receives an object containing the wallet address, selected wallet address, and connection status. |
onError | function | <optional>
| Optional callback function to execute upon error in retrieving the connection status. |
Returns:Promise object representing the outcome of the connection status retrieval, resolving to an object with the wallet address, selected wallet address, and connection status.
- Type:
- Promise.<{connected: boolean, address: string, selectedWalletAddress: string}>
ExamplegetConnectionStatus(
(result) => console.log(`Connected to wallet: ${result.connected}`),
(error) => console.error(`Connection status retrieval failed: ${error}`)
).then(result => console.log(result.connected))
- .catch(error => console.error(error));
(async) getDRC20Balance(data, onSuccessopt, onErroropt) → {Promise.<{availableBalance: number, transferableBalance: number, ticker: string, address: string}>}
Retrieves the DRC20 token balance based on provided data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required to fetch the DRC20 balance, must contain 'ticker'.PropertiesName | Type | Description |
---|
ticker | string | The ticker symbol for the DRC20 token. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful retrieval. Receives an object containing the available balance, transferable balance, ticker symbol, and wallet address. |
onError | function | <optional>
| Optional callback function to execute upon error in retrieving balance. |
Returns:Promise object representing the outcome of the balance retrieval, resolving to an object with the wallet address, available balance, and transferable balance.
- Type:
- Promise.<{availableBalance: number, transferableBalance: number, ticker: string, address: string}>
ExamplegetDRC20Balance(
+ .catch(error => console.error(error));
(async) getDRC20Balance(data, onSuccessopt, onErroropt) → {Promise.<{availableBalance: number, transferableBalance: number, ticker: string, address: string}>}
Retrieves the DRC20 token balance based on provided data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required to fetch the DRC20 balance, must contain 'ticker'.PropertiesName | Type | Description |
---|
ticker | string | The ticker symbol for the DRC20 token. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful retrieval. Receives an object containing the available balance, transferable balance, ticker symbol, and wallet address. |
onError | function | <optional>
| Optional callback function to execute upon error in retrieving balance. |
Returns:Promise object representing the outcome of the balance retrieval, resolving to an object with the wallet address, available balance, and transferable balance.
- Type:
- Promise.<{availableBalance: number, transferableBalance: number, ticker: string, address: string}>
ExamplegetDRC20Balance(
(result) => console.log(`Available balance: ${result.availableBalance}, transferable balance: ${result.transferableBalance}`),
(error) => console.error(`Balance retrieval failed: ${error}`)
).then(result => console.log(result.availableBalance))
- .catch(error => console.error(error));
(async) getTransactionStatus(onSuccessopt, onErroropt) → {Promise.<{connected: boolean, address: string, connectedWalletAddress: string}>}
Retrieves the status of a specific transaction based on provided data.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successfully retrieving the status. Receives an object containing the wallet address, selected wallet address, and connection status. |
onError | function | <optional>
| Optional callback function to execute upon error in retrieving the connection status. |
Returns:Promise object representing the outcome of the connection status retrieval, resolving to an object with the wallet address, selected wallet address, and connection status.
- Type:
- Promise.<{connected: boolean, address: string, connectedWalletAddress: string}>
ExamplegetConnectionStatus(
+ .catch(error => console.error(error));
(async) getTransactionStatus(onSuccessopt, onErroropt) → {Promise.<{connected: boolean, address: string, connectedWalletAddress: string}>}
Retrieves the status of a specific transaction based on provided data.
Parameters:Name | Type | Attributes | Description |
---|
onSuccess | function | <optional>
| Optional callback function to execute upon successfully retrieving the status. Receives an object containing the wallet address, selected wallet address, and connection status. |
onError | function | <optional>
| Optional callback function to execute upon error in retrieving the connection status. |
Returns:Promise object representing the outcome of the connection status retrieval, resolving to an object with the wallet address, selected wallet address, and connection status.
- Type:
- Promise.<{connected: boolean, address: string, connectedWalletAddress: string}>
ExamplegetConnectionStatus(
(result) => console.log(`Connected to wallet: ${result.connected}`),
(error) => console.error(`Connection status retrieval failed: ${error}`)
).then(result => console.log(result.connected))
- .catch(error => console.error(error));
(async) getTransferableDRC20(data, onSuccessopt, onErroropt) → {Promise.<{inscriptions: Array.<{txid: string, vout: number, ticker: string, contentType: string, content: string, output: string, amount: number}>, ticker: string, address: string}>}
Retrieves transferable DRC20 inscriptions based on provided data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the query, must contain 'ticker'.PropertiesName | Type | Description |
---|
ticker | string | The ticker symbol for the DRC20 token. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful retrieval. Receives an object containing the transferable inscriptions, ticker symbol, and wallet address. |
onError | function | <optional>
| Optional callback function to execute upon error in fetching the transferable balance. |
Returns:Promise object representing the outcome of the balance retrieval, resolving to an object with the wallet address, transferable inscriptions, and ticker symbol.}
- Type:
- Promise.<{inscriptions: Array.<{txid: string, vout: number, ticker: string, contentType: string, content: string, output: string, amount: number}>, ticker: string, address: string}>
ExamplegetTransferableDRC20(
+ .catch(error => console.error(error));
(async) getTransferableDRC20(data, onSuccessopt, onErroropt) → {Promise.<{inscriptions: Array.<{txid: string, vout: number, ticker: string, contentType: string, content: string, output: string, amount: number}>, ticker: string, address: string}>}
Retrieves transferable DRC20 inscriptions based on provided data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the query, must contain 'ticker'.PropertiesName | Type | Description |
---|
ticker | string | The ticker symbol for the DRC20 token. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful retrieval. Receives an object containing the transferable inscriptions, ticker symbol, and wallet address. |
onError | function | <optional>
| Optional callback function to execute upon error in fetching the transferable balance. |
Returns:Promise object representing the outcome of the balance retrieval, resolving to an object with the wallet address, transferable inscriptions, and ticker symbol.}
- Type:
- Promise.<{inscriptions: Array.<{txid: string, vout: number, ticker: string, contentType: string, content: string, output: string, amount: number}>, ticker: string, address: string}>
ExamplegetTransferableDRC20(
(result) => console.log(`Transferable inscriptions: ${result.inscriptions}`),
(error) => console.error(`Balance retrieval failed: ${error}`)
).then(result => console.log(result.inscriptions))
- .catch(error => console.error(error));
(async) requestAvailableDRC20Transaction(data, onSuccessopt, onErroropt) → {Promise.<{txId: string, ticker: string, amount: number}>}
Requests a transaction for available DRC20 tokens based on specified data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the transaction, must contain 'ticker' and 'amount'.PropertiesName | Type | Description |
---|
ticker | string | The ticker symbol for the DRC20 token. | amount | string | The amount of DRC20 tokens to make available. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful transaction request. Receives an object containing the transaction ID, ticker symbol, and amount. |
onError | function | <optional>
| Optional callback function to execute upon error in processing the transaction request. |
Returns:Promise object representing the outcome of the transaction request, resolving to an object with the transaction ID, ticker symbol, and amount.
- Type:
- Promise.<{txId: string, ticker: string, amount: number}>
ExamplerequestInscriptionTransaction(
+ .catch(error => console.error(error));
(async) requestAvailableDRC20Transaction(data, onSuccessopt, onErroropt) → {Promise.<{txId: string, ticker: string, amount: number}>}
Requests a transaction for available DRC20 tokens based on specified data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the transaction, must contain 'ticker' and 'amount'.PropertiesName | Type | Description |
---|
ticker | string | The ticker symbol for the DRC20 token. | amount | string | The amount of DRC20 tokens to make available. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful transaction request. Receives an object containing the transaction ID, ticker symbol, and amount. |
onError | function | <optional>
| Optional callback function to execute upon error in processing the transaction request. |
Returns:Promise object representing the outcome of the transaction request, resolving to an object with the transaction ID, ticker symbol, and amount.
- Type:
- Promise.<{txId: string, ticker: string, amount: number}>
ExamplerequestInscriptionTransaction(
(result) => console.log(`Transaction ID: ${result.txId} `),
(error) => console.error(`Transaction request failed: ${error}`)
).then(result => console.log(result.txId))
- .catch(error => console.error(error));
(async) requestDecryptedMessage(data, onSuccessopt, onErroropt) → {Promise.<{decryptedMessage: string}>}
Requests the decrypting of an arbitrary message encrypted by the connected address public key.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the decryption, must contain 'message'.PropertiesName | Type | Description |
---|
message | string | The message to be decrypted. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful message signing. Receives an object containing the decrypted message. |
onError | function | <optional>
| Callback function to execute upon error in decrypting the message. |
Returns:Promise object representing the outcome of the request, resolving to an object with the decrypted message.
- Type:
- Promise.<{decryptedMessage: string}>
ExamplerequestDecryptedMessage(
+ .catch(error => console.error(error));
(async) requestDecryptedMessage(data, onSuccessopt, onErroropt) → {Promise.<{decryptedMessage: string}>}
Requests the decrypting of an arbitrary message encrypted by the connected address public key.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the decryption, must contain 'message'.PropertiesName | Type | Description |
---|
message | string | The message to be decrypted. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful message signing. Receives an object containing the decrypted message. |
onError | function | <optional>
| Callback function to execute upon error in decrypting the message. |
Returns:Promise object representing the outcome of the request, resolving to an object with the decrypted message.
- Type:
- Promise.<{decryptedMessage: string}>
ExamplerequestDecryptedMessage(
(result) => console.log(`Decrypted message: ${result.decryptedMessage}`),
(error) => console.error(`Message decryption failed: ${error}`)
).then(result => console.log(result.decryptedMessage))
- .catch(error => console.error(error));
(async) requestInscriptionTransaction(data, onSuccessopt, onErroropt) → {Promise.<{txId: string}>}
Requests an inscription transaction for Doginal/DRC-20 based on the specified data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the transaction, must contain 'recipientAddress' and 'output'.PropertiesName | Type | Description |
---|
recipientAddress | string | The recipient address. | location | string | The location of the inscription in the format txid:vout:offset. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful transaction request. Receives an object containing the transaction ID. |
onError | function | <optional>
| Optional function to execute upon error in processing the transaction request. |
Returns:Promise object representing the outcome of the transaction request, resolving to an object with the transaction ID.
- Type:
- Promise.<{txId: string}>
ExamplerequestInscriptionTransaction(
+ .catch(error => console.error(error));
(async) requestInscriptionTransaction(data, onSuccessopt, onErroropt) → {Promise.<{txId: string}>}
Requests an inscription transaction for Doginal/DRC-20 based on the specified data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the transaction, must contain 'recipientAddress' and 'output'.PropertiesName | Type | Description |
---|
recipientAddress | string | The recipient address. | location | string | The location of the inscription in the format txid:vout:offset. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful transaction request. Receives an object containing the transaction ID. |
onError | function | <optional>
| Optional function to execute upon error in processing the transaction request. |
Returns:Promise object representing the outcome of the transaction request, resolving to an object with the transaction ID.
- Type:
- Promise.<{txId: string}>
ExamplerequestInscriptionTransaction(
(result) => console.log(`Transaction ID: ${result.txId}`),
(error) => console.error(`Transaction request failed: ${error}`)
).then(result => console.log(result.txId))
@@ -44,11 +44,11 @@
(result) => console.log(`Transaction ID: ${result.txId}`),
(error) => console.error(`Transaction request failed: ${error}`)
).then(result => console.log(result.txId))
- .catch(error => console.error(error));
(async) requestSignedMessage(data, onSuccessopt, onErroropt) → {Promise.<{signedMessage: string}>}
Requests the signing of an arbitrary message based on provided data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the message signing, must contain 'message'.PropertiesName | Type | Description |
---|
message | string | The message to be signed. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful message signing. Receives an object containing the signed message. |
onError | function | <optional>
| Callback function to execute upon error in signing the message. |
Returns:Promise object representing the outcome of the request, resolving to an object with the base64 signed message.
- Type:
- Promise.<{signedMessage: string}>
ExamplerequestSignedMessage(
+ .catch(error => console.error(error));
(async) requestSignedMessage(data, onSuccessopt, onErroropt) → {Promise.<{signedMessage: string}>}
Requests the signing of an arbitrary message based on provided data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data required for the message signing, must contain 'message'.PropertiesName | Type | Description |
---|
message | string | The message to be signed. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful message signing. Receives an object containing the signed message. |
onError | function | <optional>
| Callback function to execute upon error in signing the message. |
Returns:Promise object representing the outcome of the request, resolving to an object with the base64 signed message.
- Type:
- Promise.<{signedMessage: string}>
ExamplerequestSignedMessage(
(result) => console.log(`Signed message: ${result.signedMessage}`),
(error) => console.error(`Message signing failed: ${error}`)
).then(result => console.log(result.signedMessage))
- .catch(error => console.error(error));
(async) requestTransaction(data, onSuccessopt, onErroropt) → {Promise.<{txId: string}>}
Requests a Dogecoin transaction based on the specified data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data needed for the transaction, must contain 'recipientAddress' and 'dogeAmount'.PropertiesName | Type | Description |
---|
recipientAddress | string | The recipient address. | dogeAmount | number | The amount of Dogecoin to send. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful transaction request. Receives an object containing the transaction ID. |
onError | function | <optional>
| Optional callback function to execute upon error in processing the transaction request. |
Returns:Promise object representing the outcome of the transaction request, resolving to an object with the transaction ID.
- Type:
- Promise.<{txId: string}>
ExamplerequestTransaction(
+ .catch(error => console.error(error));
(async) requestTransaction(data, onSuccessopt, onErroropt) → {Promise.<{txId: string}>}
Requests a Dogecoin transaction based on the specified data.
Parameters:Name | Type | Attributes | Description |
---|
data | Object | | Data needed for the transaction, must contain 'recipientAddress' and 'dogeAmount'.PropertiesName | Type | Description |
---|
recipientAddress | string | The recipient address. | dogeAmount | number | The amount of Dogecoin to send. |
|
onSuccess | function | <optional>
| Optional callback function to execute upon successful transaction request. Receives an object containing the transaction ID. |
onError | function | <optional>
| Optional callback function to execute upon error in processing the transaction request. |
Returns:Promise object representing the outcome of the transaction request, resolving to an object with the transaction ID.
- Type:
- Promise.<{txId: string}>
ExamplerequestTransaction(
(result) => console.log(`Transaction ID: ${result.txId}`),
(error) => console.error(`Transaction request failed: ${error}`)
).then(result => console.log(result.txId))
diff --git a/docs/inject-script.js.html b/docs/inject-script.js.html
index ec173bb..4046533 100644
--- a/docs/inject-script.js.html
+++ b/docs/inject-script.js.html
@@ -4,13 +4,11 @@
const createResponseHandler =
() =>
- ({ resolve, reject, onSuccess, onError, messageType, setRequestPending }) => {
+ ({ resolve, reject, onSuccess, onError, messageType }) => {
function listener({ data: { type, data, error }, origin }) {
// only accept messages from the same origin and message type of this context
if (origin !== window.location.origin || type !== messageType) return;
- setRequestPending?.(false);
-
if (error) {
onError?.(new Error(error));
reject(new Error(error));
@@ -18,8 +16,6 @@
onSuccess?.(data);
resolve(data);
} else {
- onError?.(new Error('Unable to connect to MyDoge'));
- reject(new Error('Unable to connect to MyDoge'));
}
window.removeEventListener('message', listener);
}
@@ -30,12 +26,98 @@
* Class representing the MyDoge API to interact with the Dogecoin wallet.
*/
class MyDogeWallet {
+ #requestQueue = [];
+ #isRequestPending = false;
constructor() {
this.isMyDoge = true;
- this.isRequestPending = false;
console.info('MyDoge API initialized');
}
+ #createPopupRequestHandler({ requestType, responseType, isDataValid }) {
+ return ({ data, onSuccess, onError }) => {
+ return new Promise((resolve, reject) => {
+ if (data && !isDataValid) {
+ onError?.(new Error('Invalid data'));
+ reject(new Error('Invalid data'));
+ return;
+ }
+ this.#requestQueue.push({
+ onSuccess,
+ onError,
+ requestType,
+ responseType,
+ resolve,
+ reject,
+ data,
+ });
+ if (!this.#isRequestPending) {
+ this.#processNextRequest();
+ }
+ });
+ };
+ }
+
+ #createPopupResponseHandler() {
+ return ({ resolve, reject, onSuccess, onError, responseType }) => {
+ const listener = ({ data: { type, data, error }, origin }) => {
+ // only accept messages from the same origin and message type of this context
+ if (origin !== window.location.origin || type !== responseType) return;
+
+ if (error) {
+ onError?.(new Error(error));
+ reject(new Error(error));
+ } else if (data) {
+ onSuccess?.(data);
+ resolve(data);
+ }
+ // process next request after popup has closed
+ setTimeout(() => {
+ this.#requestQueue.shift();
+ this.#processNextRequest();
+ window.removeEventListener('message', listener);
+ }, 500);
+ };
+ window.addEventListener('message', listener);
+ };
+ }
+
+ #handleRequest({ requestType, data }) {
+ window.postMessage({ type: requestType, data }, window.location.origin);
+ }
+
+ #handlePopupResponse({ resolve, reject, onSuccess, onError, responseType }) {
+ const popupResponseHandler = this.#createPopupResponseHandler();
+ popupResponseHandler({ resolve, reject, onSuccess, onError, responseType });
+ }
+
+ #processNextRequest() {
+ if (this.#requestQueue.length === 0) {
+ this.#isRequestPending = false;
+ return;
+ }
+ this.#isRequestPending = true;
+
+ const {
+ data,
+ resolve,
+ reject,
+ onSuccess,
+ onError,
+ requestType,
+ responseType,
+ } = this.#requestQueue[0];
+
+ this.#handleRequest({ requestType, data });
+
+ this.#handlePopupResponse({
+ resolve,
+ reject,
+ onSuccess,
+ onError,
+ responseType,
+ });
+ }
+
/**
* Initiates a connection request with the wallet.
* @function
@@ -53,20 +135,10 @@
* .catch(error => console.error(error));
*/
connect(onSuccess, onError) {
- return new Promise((resolve, reject) => {
- window.postMessage(
- { type: MESSAGE_TYPES.CLIENT_REQUEST_CONNECTION },
- window.location.origin
- );
-
- createResponseHandler()({
- resolve,
- reject,
- onSuccess,
- onError,
- messageType: MESSAGE_TYPES.CLIENT_REQUEST_CONNECTION_RESPONSE,
- });
- });
+ return this.#createPopupRequestHandler({
+ requestType: MESSAGE_TYPES.CLIENT_REQUEST_CONNECTION,
+ responseType: MESSAGE_TYPES.CLIENT_REQUEST_CONNECTION_RESPONSE,
+ })({ onSuccess, onError });
}
/**
@@ -92,7 +164,7 @@
window.location.origin
);
- createResponseHandler()({
+ this.#createPopupResponseHandler()({
resolve,
reject,
onSuccess,
@@ -205,34 +277,11 @@
* .catch(error => console.error(error));
*/
requestTransaction(data, onSuccess, onError) {
- return new Promise((resolve, reject) => {
- if (!data?.recipientAddress || !data?.dogeAmount) {
- onError?.(new Error('Invalid data'));
- reject(new Error('Invalid data'));
- return;
- }
- if (this.isRequestPending) {
- onError?.(new Error('There is a pending request'));
- reject(new Error('There is a pending request'));
- return;
- }
- this.isRequestPending = true;
- window.postMessage(
- { type: MESSAGE_TYPES.CLIENT_REQUEST_TRANSACTION, data },
- window.location.origin
- );
-
- createResponseHandler()({
- resolve,
- reject,
- onSuccess,
- onError,
- messageType: MESSAGE_TYPES.CLIENT_REQUEST_TRANSACTION_RESPONSE,
- setRequestPending: (isRequestPending) => {
- this.isRequestPending = isRequestPending;
- },
- });
- });
+ return this.#createPopupRequestHandler({
+ requestType: MESSAGE_TYPES.CLIENT_REQUEST_TRANSACTION,
+ responseType: MESSAGE_TYPES.CLIENT_REQUEST_TRANSACTION_RESPONSE,
+ isDataValid: data?.recipientAddress && data?.dogeAmount,
+ })({ data, onSuccess, onError });
}
/**
@@ -255,34 +304,11 @@
* .catch(error => console.error(error));
*/
requestInscriptionTransaction(data, onSuccess, onError) {
- return new Promise((resolve, reject) => {
- if (!data?.recipientAddress || !data?.location) {
- onError?.(new Error('Invalid data'));
- reject(new Error('Invalid data'));
- return;
- }
- if (this.isRequestPending) {
- onError?.(new Error('There is a pending request'));
- reject(new Error('There is a pending request'));
- return;
- }
- this.isRequestPending = true;
- window.postMessage(
- { type: MESSAGE_TYPES.CLIENT_REQUEST_DOGINAL_TRANSACTION, data },
- window.location.origin
- );
-
- createResponseHandler()({
- resolve,
- reject,
- onSuccess,
- onError,
- messageType: MESSAGE_TYPES.CLIENT_REQUEST_DOGINAL_TRANSACTION_RESPONSE,
- setRequestPending: (isRequestPending) => {
- this.isRequestPending = isRequestPending;
- },
- });
- });
+ return this.#createPopupRequestHandler({
+ requestType: MESSAGE_TYPES.CLIENT_REQUEST_DOGINAL_TRANSACTION,
+ responseType: MESSAGE_TYPES.CLIENT_REQUEST_DOGINAL_TRANSACTION_RESPONSE,
+ isDataValid: data?.recipientAddress && data?.location,
+ })({ data, onSuccess, onError });
}
/**
@@ -306,38 +332,12 @@
* .catch(error => console.error(error));
*/
requestAvailableDRC20Transaction(data, onSuccess, onError) {
- return new Promise((resolve, reject) => {
- if (!data?.ticker || !data?.amount) {
- onError?.(new Error('Invalid data'));
- reject(new Error('Invalid data'));
- return;
- }
- if (this.isRequestPending) {
- onError?.(new Error('There is a pending request'));
- reject(new Error('There is a pending request'));
- return;
- }
- this.isRequestPending = true;
- window.postMessage(
- {
- type: MESSAGE_TYPES.CLIENT_REQUEST_AVAILABLE_DRC20_TRANSACTION,
- data,
- },
- window.location.origin
- );
-
- createResponseHandler()({
- resolve,
- reject,
- onSuccess,
- onError,
- messageType:
- MESSAGE_TYPES.CLIENT_REQUEST_AVAILABLE_DRC20_TRANSACTION_RESPONSE,
- setRequestPending: (isRequestPending) => {
- this.isRequestPending = isRequestPending;
- },
- });
- });
+ return this.#createPopupRequestHandler({
+ requestType: MESSAGE_TYPES.CLIENT_REQUEST_AVAILABLE_DRC20_TRANSACTION,
+ responseType:
+ MESSAGE_TYPES.CLIENT_REQUEST_AVAILABLE_DRC20_TRANSACTION_RESPONSE,
+ isDataValid: data?.ticker && data?.amount,
+ })({ data, onSuccess, onError });
}
/**
@@ -361,37 +361,11 @@
* .catch(error => console.error(error));
*/
requestPsbt(data, onSuccess, onError) {
- return new Promise((resolve, reject) => {
- if (!data?.rawTx || !data?.indexes?.length) {
- onError?.(new Error('Invalid data'));
- reject(new Error('Invalid data'));
- return;
- }
- if (this.isRequestPending) {
- onError?.(new Error('There is a pending request'));
- reject(new Error('There is a pending request'));
- return;
- }
- this.isRequestPending = true;
- window.postMessage(
- {
- type: MESSAGE_TYPES.CLIENT_REQUEST_PSBT,
- data,
- },
- window.location.origin
- );
-
- createResponseHandler()({
- resolve,
- reject,
- onSuccess,
- onError,
- messageType: MESSAGE_TYPES.CLIENT_REQUEST_PSBT_RESPONSE,
- setRequestPending: (isRequestPending) => {
- this.isRequestPending = isRequestPending;
- },
- });
- });
+ return this.#createPopupRequestHandler({
+ requestType: MESSAGE_TYPES.CLIENT_REQUEST_PSBT,
+ responseType: MESSAGE_TYPES.CLIENT_REQUEST_PSBT_RESPONSE,
+ isDataValid: data?.rawTx && data?.indexes?.length,
+ })({ data, onSuccess, onError });
}
/**
@@ -413,34 +387,11 @@
* .catch(error => console.error(error));
*/
requestSignedMessage(data, onSuccess, onError) {
- return new Promise((resolve, reject) => {
- if (!data?.message) {
- onError?.(new Error('Invalid data'));
- reject(new Error('Invalid data'));
- return;
- }
- if (this.isRequestPending) {
- onError?.(new Error('There is a pending request'));
- reject(new Error('There is a pending request'));
- return;
- }
- this.isRequestPending = true;
- window.postMessage(
- { type: MESSAGE_TYPES.CLIENT_REQUEST_SIGNED_MESSAGE, data },
- window.location.origin
- );
-
- createResponseHandler()({
- resolve,
- reject,
- onSuccess,
- onError,
- messageType: MESSAGE_TYPES.CLIENT_REQUEST_SIGNED_MESSAGE_RESPONSE,
- setRequestPending: (isRequestPending) => {
- this.isRequestPending = isRequestPending;
- },
- });
- });
+ return this.#createPopupRequestHandler({
+ requestType: MESSAGE_TYPES.CLIENT_REQUEST_SIGNED_MESSAGE,
+ responseType: MESSAGE_TYPES.CLIENT_REQUEST_SIGNED_MESSAGE_RESPONSE,
+ isDataValid: !!data?.message,
+ })({ data, onSuccess, onError });
}
/**
@@ -462,34 +413,11 @@
* .catch(error => console.error(error));
*/
requestDecryptedMessage(data, onSuccess, onError) {
- return new Promise((resolve, reject) => {
- if (!data?.message) {
- onError?.(new Error('Invalid data'));
- reject(new Error('Invalid data'));
- return;
- }
- if (this.isRequestPending) {
- onError?.(new Error('There is a pending request'));
- reject(new Error('There is a pending request'));
- return;
- }
- this.isRequestPending = true;
- window.postMessage(
- { type: MESSAGE_TYPES.CLIENT_REQUEST_DECRYPTED_MESSAGE, data },
- window.location.origin
- );
-
- createResponseHandler()({
- resolve,
- reject,
- onSuccess,
- onError,
- messageType: MESSAGE_TYPES.CLIENT_REQUEST_DECRYPTED_MESSAGE_RESPONSE,
- setRequestPending: (isRequestPending) => {
- this.isRequestPending = isRequestPending;
- },
- });
- });
+ return this.#createPopupRequestHandler({
+ requestType: MESSAGE_TYPES.CLIENT_REQUEST_DECRYPTED_MESSAGE,
+ responseType: MESSAGE_TYPES.CLIENT_REQUEST_DECRYPTED_MESSAGE_RESPONSE,
+ isDataValid: !!data?.message,
+ })({ data, onSuccess, onError });
}
/**
diff --git a/public/manifest.json b/public/manifest.json
index 3a52319..35013e0 100644
--- a/public/manifest.json
+++ b/public/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "MyDoge - Dogecoin Wallet",
- "version": "1.1.2",
+ "version": "1.1.3",
"description": "Dogecoin wallet for Chrome browser",
"permissions": ["storage", "tabs", "notifications", "offscreen"],
"host_permissions": ["http://*/*", "https://*/*"],