Skip to content

Commit

Permalink
Merge pull request #604 from arconnectio/development
Browse files Browse the repository at this point in the history
ArConnect BETA 1.23.0
  • Loading branch information
pawanpaudel93 authored Jan 3, 2025
2 parents 955f7a3 + 78cecea commit 35f73de
Show file tree
Hide file tree
Showing 21 changed files with 411 additions and 268 deletions.
18 changes: 11 additions & 7 deletions assets/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,17 @@
"message": "Sign notification",
"description": "Sign notification settings title"
},
"setting_sign_settings": {
"message": "Sign settings",
"description": "Sign settings title"
"setting_transfer_settings": {
"message": "Transfer settings",
"description": "Transfer settings title"
},
"setting_transfer_settings_description": {
"message": "Allowance for requiring password when transferring",
"description": "Transfer settings description"
},
"enable_transfer_settings": {
"message": "Enable Transfer Settings",
"description": "Enable transfer settings title"
},
"setting_display_theme": {
"message": "Theme",
Expand Down Expand Up @@ -543,10 +551,6 @@
"message": "Show animation on wallet usage",
"description": "ArConfetti settings description"
},
"setting_sign_notification_description": {
"message": "Notify when signing a transaction",
"description": "Sign notification settings description"
},
"setting_display_theme_description": {
"message": "The theme of the extension UI",
"description": "Display theme settings description"
Expand Down
18 changes: 11 additions & 7 deletions assets/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,17 @@
"message": "签署通知",
"description": "Sign notification settings title"
},
"setting_sign_settings": {
"message": "签名设置",
"description": "Sign settings title"
"setting_transfer_settings": {
"message": "转账设置",
"description": "Transfer settings title"
},
"setting_transfer_settings_description": {
"message": "转账时需要密码的额度",
"description": "Transfer settings description"
},
"enable_transfer_settings": {
"message": "启用转账设置",
"description": "Enable transfer settings title"
},
"setting_display_theme": {
"message": "主题",
Expand Down Expand Up @@ -539,10 +547,6 @@
"message": "在使用钱包时显示动画",
"description": "ArConfetti settings description"
},
"setting_sign_notification_description": {
"message": "签署交易时通知",
"description": "Sign notification settings description"
},
"setting_display_theme_description": {
"message": "扩展 UI 的主题",
"description": "Display theme settings description"
Expand Down
4 changes: 2 additions & 2 deletions src/api/modules/dispatch/dispatch.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const background: BackgroundModuleFunction<ReturnType> = async (
// await updateAllowance(appData.url, price);

// show notification
await signNotification(0, dataEntry.id, appData.url, "dispatch");
// await signNotification(0, dataEntry.id, appData.url, "dispatch");

// remove wallet from memory
freeDecryptedWallet(keyfile);
Expand Down Expand Up @@ -157,7 +157,7 @@ const background: BackgroundModuleFunction<ReturnType> = async (
// await updateAllowance(appData.url, price);

// show notification
await signNotification(price, transaction.id, appData.url);
// await signNotification(price, transaction.id, appData.url);

// remove wallet from memory
freeDecryptedWallet(keyfile);
Expand Down
2 changes: 1 addition & 1 deletion src/api/modules/sign/sign.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const background: BackgroundModuleFunction<BackgroundResult> = async (
}

// notify the user of the signing
await signNotification(price, transaction.id, appData.url);
// await signNotification(price, transaction.id, appData.url);

// update allowance spent amount (in winstons)
// await updateAllowance(appData.url, price);
Expand Down
123 changes: 58 additions & 65 deletions src/components/dashboard/SignSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,82 +1,68 @@
import { useState, useEffect } from "react";
import PermissionCheckbox from "~components/auth/PermissionCheckbox";
import { InputV2, Spacer, Text } from "@arconnect/components";
import { useCallback, useEffect, useRef, useState } from "react";
import { InputV2, Text } from "@arconnect/components";
import browser from "webextension-polyfill";
import styled from "styled-components";
import { ExtensionStorage } from "~utils/storage";
import { useStorage } from "@plasmohq/storage/hook";
import { EventType, trackEvent } from "~utils/analytics";
import { ToggleSwitch } from "~routes/popup/subscriptions/subscriptionDetails";

export function SignSettingsDashboardView() {
const [signSettingsState, setSignSettingsState] = useState(false);

const [signatureAllowance, setSignatureAllowance] = useStorage({
key: "signatureAllowance",
instance: ExtensionStorage
});

export const SignSettingsDashboardView = () => {
const valueChanged = useRef(false);
const [editingValue, setEditingValue] = useState(null);

useEffect(() => {
async function initializeSettings() {
const currentSetting = await ExtensionStorage.get<boolean>(
"setting_sign_notification"
);
setSignSettingsState(currentSetting);
const [signatureAllowance, setSignatureAllowance] = useStorage(
{
key: "signatureAllowance",
instance: ExtensionStorage
},
10
);

// Check if signatureAllowance is set, if not, initialize to 10
let allowance = await ExtensionStorage.get("signatureAllowance");
if (allowance === undefined || allowance === null) {
await ExtensionStorage.set("signatureAllowance", 10);
setEditingValue(10);
} else {
setEditingValue(allowance);
}
}
const [signatureAllowanceEnabled, setSignatureAllowanceEnabled] = useStorage(
{
key: "signatureAllowanceEnabled",
instance: ExtensionStorage
},
true
);

initializeSettings();
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
valueChanged.current = true;
setEditingValue(e.target.value);
}, []);

const toggleSignSettings = async () => {
const newSetting = !signSettingsState;
setSignSettingsState(newSetting);
await ExtensionStorage.set("setting_sign_notification", newSetting);
};
const handleBlur = useCallback(
(e: React.FocusEvent<HTMLInputElement>) => {
const newAllowance = Number(e.target.value);

const handleBlur = async (e) => {
const newAllowance = Number(e.target.value);
if (newAllowance !== signatureAllowance) {
trackEvent(EventType.SEND_ALLOWANCE_CHANGE, {
before: signatureAllowance,
after: newAllowance
});
setSignatureAllowance(newAllowance);
if (newAllowance !== signatureAllowance) {
trackEvent(EventType.SEND_ALLOWANCE_CHANGE, {
before: signatureAllowance,
after: newAllowance
});
setSignatureAllowance(newAllowance);
}
},
[signatureAllowance]
);

// Save the updated allowance to the extension storage
await ExtensionStorage.set("signatureAllowance", newAllowance);
useEffect(() => {
if (!valueChanged.current) {
setEditingValue(signatureAllowance);
}
};

const handleChange = (e) => {
setEditingValue(e.target.value);
};
}, [signatureAllowance]);

return (
<>
<Wrapper>
<PermissionCheckbox
checked={signSettingsState}
onChange={toggleSignSettings}
>
{browser.i18n.getMessage(
!!signSettingsState ? "enabled" : "disabled"
)}
<br />
<Text noMargin>
{browser.i18n.getMessage("setting_sign_notification_description")}
</Text>
</PermissionCheckbox>
<Spacer y={1.7} />
<Wrapper>
<ToggleSwitchWrapper>
<Text>{browser.i18n.getMessage("enable_transfer_settings")}</Text>
<ToggleSwitch
checked={signatureAllowanceEnabled}
setChecked={setSignatureAllowanceEnabled}
/>
</ToggleSwitchWrapper>
{signatureAllowanceEnabled && (
<InputV2
label={browser.i18n.getMessage("password_allowance")}
type="number"
Expand All @@ -85,11 +71,18 @@ export function SignSettingsDashboardView() {
onBlur={handleBlur}
fullWidth
/>
</Wrapper>
</>
)}
</Wrapper>
);
}
};

const Wrapper = styled.div`
position: relative;
`;

const ToggleSwitchWrapper = styled.div`
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: baseline;
`;
11 changes: 6 additions & 5 deletions src/components/popup/HeadV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ export default function HeadV2({
</BackButton>
) : null}

<PageTitle>{title}</PageTitle>
<PageTitle showLeftMargin={showBack && !showOptions && !!appName}>
{title}
</PageTitle>

{appName ? (
{!showOptions && appName ? (
<TooltipV2 content={appName} position="bottomEnd">
<SquircleWrapper>
<SquircleImg
Expand Down Expand Up @@ -192,8 +194,6 @@ const HeadWrapper = styled(Section)<{
width: full;
transition: padding 0.07s ease-in-out, border-color 0.23s ease-in-out;
padding: ${(props) => (props.padding ? props.padding : "15px")};
padding-left: ${(props) =>
props.hasBackButton ? "32px" : props.padding || "15px"};
justify-content: ${(props) => (props.center ? "center" : "space-between")};
align-items: center;
background-color: rgba(${(props) => props.theme.background}, 0.75);
Expand Down Expand Up @@ -256,9 +256,10 @@ const BackButtonIcon = styled(ArrowNarrowLeft)`
const PageTitle = styled(Text).attrs({
subtitle: true,
noMargin: true
})`
})<{ showLeftMargin: boolean }>`
font-size: 1.3rem;
font-weight: 500;
${(props) => props.showLeftMargin && `margin-left: 28px;`}
`;

const AvatarButton = styled.button`
Expand Down
44 changes: 22 additions & 22 deletions src/gateways/wayfinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ export const STAKED_GQL_FULL_HISTORY: Requirements = {
export async function findGateway(
requirements: Requirements
): Promise<Gateway> {
// Get if the Wayfinder feature is enabled:
const wayfinderEnabled = await getSetting("wayfinder").getValue();
try {
// Get if the Wayfinder feature is enabled:
const wayfinderEnabled = await getSetting("wayfinder").getValue();

// This should have been loaded into the cache by handleGatewayUpdateAlarm, but sometimes this function might run
// before that, so in that case we fall back to the same behavior has having the Wayfinder disabled:
const procData = await getGatewayCache();
// This should have been loaded into the cache by handleGatewayUpdateAlarm, but sometimes this function might run
// before that, so in that case we fall back to the same behavior has having the Wayfinder disabled:
const procData = await getGatewayCache();

if (!wayfinderEnabled || !procData) {
if (requirements.arns) {
return {
host: "arweave.dev",
port: 443,
protocol: "https"
};
}
if (!wayfinderEnabled || !procData) {
if (requirements.arns) {
return {
host: "arweave.dev",
port: 443,
protocol: "https"
};
}

// wayfinder disabled or all the chain is needed
if (requirements.startBlock === 0) {
return defaultGateway;
}
// wayfinder disabled or all the chain is needed
if (requirements.startBlock === 0) {
return defaultGateway;
}

throw new Error(
wayfinderEnabled ? "Missing gateway cache" : "Wayfinder disabled"
);
}
throw new Error(
wayfinderEnabled ? "Missing gateway cache" : "Wayfinder disabled"
);
}

try {
// this could probably be filtered out during the caching process
const filteredGateways = procData.filter((gateway) => {
return (
Expand Down
Loading

0 comments on commit 35f73de

Please sign in to comment.