Skip to content

Commit

Permalink
Merge pull request #188 from alephium/fix-argent-action-conflict-issue
Browse files Browse the repository at this point in the history
Use ALPH Specific Action Queue
  • Loading branch information
h0ngcha0 authored Apr 7, 2024
2 parents f79e9fc + d2a5255 commit 69b0a80
Show file tree
Hide file tree
Showing 44 changed files with 303 additions and 303 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["packages/*"],
"version": "0.8.16",
"version": "0.8.17",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.8.16",
"version": "0.8.17",
"private": true,
"name": "alephium-browser-extension-wallet",
"repository": "github:alephium/extension-wallet",
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alephium/dapp",
"version": "0.8.16",
"version": "0.8.17",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/manifest/v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/chrome-manifest.json",
"name": "Alephium Extension Wallet",
"description": "Alephium's official extension wallet with powerful features and a clean UI.",
"version": "0.8.16",
"version": "0.8.17",
"manifest_version": 2,
"browser_action": {
"default_icon": {
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/manifest/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/chrome-manifest.json",
"name": "Alephium Extension Wallet",
"description": "Alephium's official extension wallet with powerful features and a clean UI.",
"version": "0.8.16",
"version": "0.8.17",
"manifest_version": 3,
"action": {
"default_icon": {
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alephium/extension",
"version": "0.8.16",
"version": "0.8.17",
"main": "index.js",
"license": "MIT",
"devDependencies": {
Expand Down
50 changes: 25 additions & 25 deletions packages/extension/src/background/accountMessaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,42 @@ export const handleAccountMessage: HandleMessage<AccountMessage> = async ({
respond,
}) => {
switch (msg.type) {
case "GET_ACCOUNTS": {
case "ALPH_GET_ACCOUNTS": {
return sendMessageToUi({
type: "GET_ACCOUNTS_RES",
type: "ALPH_GET_ACCOUNTS_RES",
data: await getAccounts(msg.data?.showHidden ? () => true : undefined),
})
}

case "CONNECT_ACCOUNT": {
case "ALPH_CONNECT_ACCOUNT": {
// Select an Account of BaseWalletAccount type
const selectedAccount = await wallet.getSelectedAccount()

return respond({
type: "CONNECT_ACCOUNT_RES",
type: "ALPH_CONNECT_ACCOUNT_RES",
data: selectedAccount,
})
}

case "DISCOVER_ACCOUNTS": {
case "ALPH_DISCOVER_ACCOUNTS": {
const { networkId } = msg.data
try {
const discoveredAccounts = await wallet.discoverActiveAccounts(networkId)
return respond({
type: "DISCOVER_ACCOUNTS_RES",
type: "ALPH_DISCOVER_ACCOUNTS_RES",
data: { accounts: discoveredAccounts }
})
} catch (exception) {
console.error("Failed to discover accounts", exception)
return respond({
type: "DISCOVER_ACCOUNTS_REJ",
type: "ALPH_DISCOVER_ACCOUNTS_REJ",
data: { error: `${exception}` },
})
}

}

case "NEW_ACCOUNT": {
case "ALPH_NEW_ACCOUNT": {
if (!(await wallet.isSessionOpen())) {
throw Error("you need an open session")
}
Expand All @@ -64,7 +64,7 @@ export const handleAccountMessage: HandleMessage<AccountMessage> = async ({
const accounts = await getAccounts()

return sendMessageToUi({
type: "NEW_ACCOUNT_RES",
type: "ALPH_NEW_ACCOUNT_RES",
data: {
account,
accounts,
Expand All @@ -80,13 +80,13 @@ export const handleAccountMessage: HandleMessage<AccountMessage> = async ({
})

return sendMessageToUi({
type: "NEW_ACCOUNT_REJ",
type: "ALPH_NEW_ACCOUNT_REJ",
data: { error },
})
}
}

case "NEW_LEDGER_ACCOUNT": {
case "ALPH_NEW_LEDGER_ACCOUNT": {
if (!(await wallet.isSessionOpen())) {
throw Error("you need an open session")
}
Expand All @@ -95,7 +95,7 @@ export const handleAccountMessage: HandleMessage<AccountMessage> = async ({
try {
const baseAccount = await wallet.importLedgerAccount(account, hdIndex, networkId)
return sendMessageToUi({
type: "NEW_LEDGER_ACCOUNT_RES",
type: "ALPH_NEW_LEDGER_ACCOUNT_RES",
data: {
account: baseAccount
}
Expand All @@ -110,38 +110,38 @@ export const handleAccountMessage: HandleMessage<AccountMessage> = async ({
})

return sendMessageToUi({
type: "NEW_LEDGER_ACCOUNT_REJ",
type: "ALPH_NEW_LEDGER_ACCOUNT_REJ",
data: { error },
})
}
}

case "GET_SELECTED_ACCOUNT": {
case "ALPH_GET_SELECTED_ACCOUNT": {
const selectedAccount = await wallet.getSelectedAccount()
return sendMessageToUi({
type: "GET_SELECTED_ACCOUNT_RES",
type: "ALPH_GET_SELECTED_ACCOUNT_RES",
data: selectedAccount,
})
}

case "UPGRADE_ACCOUNT": {
case "ALPH_UPGRADE_ACCOUNT": {
try {
return sendMessageToUi({ type: "UPGRADE_ACCOUNT_RES" })
return sendMessageToUi({ type: "ALPH_UPGRADE_ACCOUNT_RES" })
} catch {
return sendMessageToUi({ type: "UPGRADE_ACCOUNT_REJ" })
return sendMessageToUi({ type: "ALPH_UPGRADE_ACCOUNT_REJ" })
}
}

case "DELETE_ACCOUNT": {
case "ALPH_DELETE_ACCOUNT": {
try {
await removeAccount(msg.data)
return sendMessageToUi({ type: "DELETE_ACCOUNT_RES" })
return sendMessageToUi({ type: "ALPH_DELETE_ACCOUNT_RES" })
} catch {
return sendMessageToUi({ type: "DELETE_ACCOUNT_REJ" })
return sendMessageToUi({ type: "ALPH_DELETE_ACCOUNT_REJ" })
}
}

case "GET_ENCRYPTED_PRIVATE_KEY": {
case "ALPH_GET_ENCRYPTED_PRIVATE_KEY": {
if (!(await wallet.isSessionOpen())) {
throw Error("you need an open session")
}
Expand All @@ -153,12 +153,12 @@ export const handleAccountMessage: HandleMessage<AccountMessage> = async ({
)

return sendMessageToUi({
type: "GET_ENCRYPTED_PRIVATE_KEY_RES",
type: "ALPH_GET_ENCRYPTED_PRIVATE_KEY_RES",
data: { encryptedPrivateKey },
})
}

case "GET_ENCRYPTED_SEED_PHRASE": {
case "ALPH_GET_ENCRYPTED_SEED_PHRASE": {
if (!(await wallet.isSessionOpen())) {
throw Error("you need an open session")
}
Expand All @@ -170,7 +170,7 @@ export const handleAccountMessage: HandleMessage<AccountMessage> = async ({
)

return sendMessageToUi({
type: "GET_ENCRYPTED_SEED_PHRASE_RES",
type: "ALPH_GET_ENCRYPTED_SEED_PHRASE_RES",
data: { encryptedSeedPhrase },
})
}
Expand Down
46 changes: 23 additions & 23 deletions packages/extension/src/background/actionHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const handleActionApproval = async (
const actionHash = action.meta.hash

switch (action.type) {
case "CONNECT_DAPP": {
case "ALPH_CONNECT_DAPP": {
const { host, networkId, group, keyType } = action.payload
const selectedAccount = await wallet.getAlephiumSelectedAddress(
networkId,
Expand All @@ -48,7 +48,7 @@ export const handleActionApproval = async (
return { type: "ALPH_CONNECT_DAPP_RES", data: walletAccountWithNetwork }
}

case "TRANSACTION": {
case "ALPH_TRANSACTION": {
const { signature: signatureOpt, ...transaction } =
additionalData as ReviewTransactionResult & { signature?: string }
try {
Expand All @@ -63,7 +63,7 @@ export const handleActionApproval = async (

return {
type: "ALPH_TRANSACTION_SUBMITTED",
data: { result: { ...transaction.result, signature } , actionHash },
data: { result: { ...transaction.result, signature }, actionHash },
}
} catch (error: unknown) {
return {
Expand All @@ -73,7 +73,7 @@ export const handleActionApproval = async (
}
}

case "SIGN_MESSAGE": {
case "ALPH_SIGN_MESSAGE": {
const account = await wallet.getAccount({
address: action.payload.signerAddress,
networkId: action.payload.networkId,
Expand All @@ -93,7 +93,7 @@ export const handleActionApproval = async (
}
}

case "SIGN_UNSIGNED_TX": {
case "ALPH_SIGN_UNSIGNED_TX": {
try {
const account = await wallet.getAccount({
address: action.payload.signerAddress,
Expand All @@ -117,29 +117,29 @@ export const handleActionApproval = async (
}
}

case "REQUEST_ADD_TOKEN": {
case "ALPH_REQUEST_ADD_TOKEN": {
return {
type: "APPROVE_REQUEST_ADD_TOKEN",
type: "ALPH_APPROVE_REQUEST_ADD_TOKEN",
data: { actionHash },
}
}

case "REQUEST_ADD_CUSTOM_NETWORK": {
case "ALPH_REQUEST_ADD_CUSTOM_NETWORK": {
try {
await addNetwork(action.payload)
return {
type: "APPROVE_REQUEST_ADD_CUSTOM_NETWORK",
type: "ALPH_APPROVE_REQUEST_ADD_CUSTOM_NETWORK",
data: { actionHash },
}
} catch (error) {
return {
type: "REJECT_REQUEST_ADD_CUSTOM_NETWORK",
type: "ALPH_REJECT_REQUEST_ADD_CUSTOM_NETWORK",
data: { actionHash },
}
}
}

case "REQUEST_SWITCH_CUSTOM_NETWORK": {
case "ALPH_REQUEST_SWITCH_CUSTOM_NETWORK": {
try {
const networks = await getNetworks()

Expand Down Expand Up @@ -176,12 +176,12 @@ export const handleActionApproval = async (
}

return {
type: "APPROVE_REQUEST_SWITCH_CUSTOM_NETWORK",
type: "ALPH_APPROVE_REQUEST_SWITCH_CUSTOM_NETWORK",
data: { actionHash, selectedAccount },
}
} catch (error) {
return {
type: "REJECT_REQUEST_SWITCH_CUSTOM_NETWORK",
type: "ALPH_REJECT_REQUEST_SWITCH_CUSTOM_NETWORK",
data: { actionHash },
}
}
Expand All @@ -199,7 +199,7 @@ export const handleActionRejection = async (
const actionHash = action.meta.hash

switch (action.type) {
case "CONNECT_DAPP": {
case "ALPH_CONNECT_DAPP": {
return {
type: "ALPH_REJECT_PREAUTHORIZATION",
data: {
Expand All @@ -209,44 +209,44 @@ export const handleActionRejection = async (
}
}

case "TRANSACTION": {
case "ALPH_TRANSACTION": {
return {
type: "ALPH_TRANSACTION_FAILED",
data: { actionHash },
}
}

case "SIGN_MESSAGE": {
case "ALPH_SIGN_MESSAGE": {
return {
type: "ALPH_SIGN_MESSAGE_FAILURE",
data: { actionHash },
}
}

case "SIGN_UNSIGNED_TX": {
case "ALPH_SIGN_UNSIGNED_TX": {
return {
type: "ALPH_SIGN_UNSIGNED_TX_FAILURE",
data: { actionHash },
}
}

case "REQUEST_ADD_TOKEN": {
case "ALPH_REQUEST_ADD_TOKEN": {
return {
type: "REJECT_REQUEST_ADD_TOKEN",
type: "ALPH_REJECT_REQUEST_ADD_TOKEN",
data: { actionHash },
}
}

case "REQUEST_ADD_CUSTOM_NETWORK": {
case "ALPH_REQUEST_ADD_CUSTOM_NETWORK": {
return {
type: "REJECT_REQUEST_ADD_CUSTOM_NETWORK",
type: "ALPH_REJECT_REQUEST_ADD_CUSTOM_NETWORK",
data: { actionHash },
}
}

case "REQUEST_SWITCH_CUSTOM_NETWORK": {
case "ALPH_REQUEST_SWITCH_CUSTOM_NETWORK": {
return {
type: "REJECT_REQUEST_SWITCH_CUSTOM_NETWORK",
type: "ALPH_REJECT_REQUEST_SWITCH_CUSTOM_NETWORK",
data: { actionHash },
}
}
Expand Down
Loading

0 comments on commit 69b0a80

Please sign in to comment.