Skip to content

Commit e250c83

Browse files
authored
Merge pull request #84 from valory-xyz/feat/safe-transactions
Safe transactions
2 parents b716642 + 8872e5c commit e250c83

21 files changed

+1295
-194
lines changed

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
env:
4343
NODE_ENV: production
4444
DEV_RPC: http://localhost:8545
45-
FORK_URL: https://gnosis-pokt.nodies.app
45+
FORK_URL: https://rpc-gate.autonolas.tech/gnosis-rpc/
4646

4747
- run: rm -rf /dist
4848

@@ -55,7 +55,7 @@ jobs:
5555
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
5656
CSC_LINK: ${{ secrets.CSC_LINK }}
5757
DEV_RPC: http://localhost:8545
58-
FORK_URL: https://gnosis-pokt.nodies.app
58+
FORK_URL: https://rpc-gate.autonolas.tech/gnosis-rpc/
5959
GH_TOKEN: ${{ secrets.github_token}}
6060
NODE_ENV: production
6161
#PUBLISH_FOR_PULL_REQUEST: true #required during testing

frontend/components/Main/MainAddFunds.tsx

+25-19
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import styled from 'styled-components';
2020
import { copyToClipboard, truncateAddress } from '@/common-util';
2121
import { COLOR, COW_SWAP_GNOSIS_XDAI_OLAS_URL } from '@/constants';
2222
import { UNICODE_SYMBOLS } from '@/constants/unicode';
23-
import { useBalance } from '@/hooks';
23+
import { useWallet } from '@/hooks/useWallet';
2424
import { Address } from '@/types';
2525

2626
import { CardSection } from '../styled/CardSection';
@@ -34,22 +34,24 @@ const CustomizedCardSection = styled(CardSection)<{ border?: boolean }>`
3434
`;
3535

3636
export const MainAddFunds = () => {
37-
const { wallets } = useBalance();
37+
const { masterSafeAddress, masterEoaAddress } = useWallet();
3838
const [isAddFundsVisible, setIsAddFundsVisible] = useState(false);
3939

40-
const walletAddress = useMemo(() => wallets[0]?.address, [wallets]);
40+
const fundingAddress: Address | undefined =
41+
masterSafeAddress ?? masterEoaAddress;
4142

42-
const truncatedWalletAddress = useMemo(
43-
() => truncateAddress(walletAddress),
44-
[walletAddress],
43+
const truncatedFundingAddress: string | undefined = useMemo(
44+
() => fundingAddress && truncateAddress(fundingAddress),
45+
[fundingAddress],
4546
);
4647

47-
const handleCopyWalletAddress = useCallback(
48+
const handleCopyAddress = useCallback(
4849
() =>
49-
copyToClipboard(walletAddress).then(() =>
50+
fundingAddress &&
51+
copyToClipboard(fundingAddress).then(() =>
5052
message.success('Copied successfully!'),
5153
),
52-
[walletAddress],
54+
[fundingAddress],
5355
);
5456

5557
return (
@@ -78,9 +80,9 @@ export const MainAddFunds = () => {
7880
<>
7981
<AddFundsWarningAlertSection />
8082
<AddFundsAddressSection
81-
truncatedWalletAddress={truncatedWalletAddress}
82-
walletAddress={walletAddress}
83-
handleCopy={handleCopyWalletAddress}
83+
truncatedFundingAddress={truncatedFundingAddress}
84+
fundingAddress={masterSafeAddress}
85+
handleCopy={handleCopyAddress}
8486
/>
8587
<AddFundsGetTokensSection />
8688
</>
@@ -111,19 +113,23 @@ const AddFundsWarningAlertSection = () => (
111113
);
112114

113115
const AddFundsAddressSection = ({
114-
walletAddress,
115-
truncatedWalletAddress,
116+
fundingAddress,
117+
truncatedFundingAddress,
116118
handleCopy,
117119
}: {
118-
walletAddress: Address;
119-
truncatedWalletAddress: string;
120+
fundingAddress?: string;
121+
truncatedFundingAddress?: string;
120122
handleCopy: () => void;
121123
}) => (
122124
<CardSection gap={10} justify="center" align="center">
123125
<Tooltip
124-
title={<span className="can-select-text flex">{walletAddress}</span>}
126+
title={
127+
<span className="can-select-text flex">
128+
{fundingAddress ?? 'Error loading address'}
129+
</span>
130+
}
125131
>
126-
<Text title={walletAddress}>GNO: {truncatedWalletAddress}</Text>
132+
<Text title={fundingAddress}>GNO: {truncatedFundingAddress ?? '--'}</Text>
127133
</Tooltip>
128134
<Button onClick={handleCopy}>
129135
<CopyOutlined />
@@ -133,7 +139,7 @@ const AddFundsAddressSection = ({
133139
content={
134140
<QRCode
135141
size={250}
136-
value={`https://metamask.app.link/send/${walletAddress}@${100}`}
142+
value={`https://metamask.app.link/send/${fundingAddress}@${100}`}
137143
/>
138144
}
139145
>

frontend/components/Main/MainGasBalance.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styled from 'styled-components';
55

66
import { COLOR } from '@/constants';
77
import { useBalance } from '@/hooks';
8+
import { useWallet } from '@/hooks/useWallet';
89

910
import { CardSection } from '../styled/CardSection';
1011

@@ -65,22 +66,22 @@ const TooltipContent = styled.div`
6566
`;
6667

6768
export const MainGasBalance = () => {
68-
const { isBalanceLoaded, wallets } = useBalance();
69-
const walletAddress = wallets?.[0]?.safe;
69+
const { masterSafeAddress } = useWallet();
70+
const { isBalanceLoaded } = useBalance();
7071

7172
return (
7273
<CardSection justify="space-between" borderTop borderBottom>
7374
<Text>
7475
Gas and trading balance&nbsp;
75-
{walletAddress && (
76+
{masterSafeAddress && (
7677
<Tooltip
7778
title={
7879
<TooltipContent>
7980
Your agent uses this balance to pay for transactions and other
8081
trading activity on-chain.
8182
<br />
8283
<a
83-
href={'https://gnosisscan.io/address/0x' + walletAddress}
84+
href={'https://gnosisscan.io/address/' + masterSafeAddress}
8485
target="_blank"
8586
>
8687
Track activity on blockchain explorer{' '}

frontend/components/Main/MainHeader.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Chain, DeploymentStatus } from '@/client';
88
import { COLOR, SERVICE_TEMPLATES } from '@/constants';
99
import { useBalance, useServiceTemplates } from '@/hooks';
1010
import { useServices } from '@/hooks/useServices';
11+
import { useWallet } from '@/hooks/useWallet';
1112
import { ServicesService } from '@/service';
1213
import { WalletService } from '@/service/Wallet';
1314

@@ -19,10 +20,10 @@ const LOADING_MESSAGE =
1920
export const MainHeader = () => {
2021
const { services, serviceStatus, setServiceStatus } = useServices();
2122
const { getServiceTemplates } = useServiceTemplates();
23+
const { wallets, masterSafeAddress } = useWallet();
2224
const {
2325
totalOlasBalance,
2426
totalEthBalance,
25-
wallets,
2627
setIsPaused: setIsBalancePollingPaused,
2728
} = useBalance();
2829

@@ -61,7 +62,7 @@ export const MainHeader = () => {
6162
setIsBalancePollingPaused(true);
6263

6364
try {
64-
if (!wallets?.[0].safe) {
65+
if (!masterSafeAddress) {
6566
await WalletService.createSafe(Chain.GNOSIS);
6667
}
6768
// TODO: Replace with proper upload logic
@@ -86,7 +87,13 @@ export const MainHeader = () => {
8687
setIsBalancePollingPaused(false);
8788
setServiceButtonState({ isLoading: false });
8889
}
89-
}, [serviceTemplate, setIsBalancePollingPaused, setServiceStatus, wallets]);
90+
}, [
91+
masterSafeAddress,
92+
serviceTemplate,
93+
setIsBalancePollingPaused,
94+
setServiceStatus,
95+
wallets,
96+
]);
9097

9198
const handleStop = useCallback(() => {
9299
if (services.length === 0) return;
@@ -122,7 +129,7 @@ export const MainHeader = () => {
122129

123130
if (serviceStatus === DeploymentStatus.DEPLOYED) {
124131
return (
125-
<Flex gap={5} align="center">
132+
<Flex gap={10} align="center">
126133
<Button type="default" size="large" onClick={handleStop}>
127134
Pause
128135
</Button>

frontend/components/Settings/Settings.tsx

+64-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { CloseOutlined, SettingOutlined } from '@ant-design/icons';
2-
import { Button, Card, Flex, Input, message, Typography } from 'antd';
2+
import { Alert, Button, Card, Flex, Input, message, Typography } from 'antd';
3+
import Link from 'next/link';
34
import { useMemo, useState } from 'react';
45

6+
import { truncateAddress } from '@/common-util';
7+
import { COLOR } from '@/constants';
8+
import { UNICODE_SYMBOLS } from '@/constants/unicode';
59
import { PageState, SettingsScreen } from '@/enums';
610
import { usePageState } from '@/hooks';
11+
import { useMasterSafe } from '@/hooks/useMasterSafe';
712
import { useSettings } from '@/hooks/useSettings';
813

914
import { CardTitle } from '../common/CardTitle';
@@ -27,13 +32,17 @@ export const Settings = () => {
2732
};
2833

2934
const SettingsMain = () => {
35+
const { backupSafeAddress } = useMasterSafe();
3036
const { goto } = usePageState();
31-
const { goto: gotoSettings } = useSettings();
32-
33-
// TODO: implement safe owners count
3437

3538
const [isUpdating, setIsUpdating] = useState(false);
3639

40+
const truncatedBackupSafeAddress: string | undefined = useMemo(() => {
41+
if (backupSafeAddress) {
42+
return truncateAddress(backupSafeAddress);
43+
}
44+
}, [backupSafeAddress]);
45+
3746
const handleClick = () => {
3847
if (isUpdating) handleSave();
3948
setIsUpdating((prev) => !prev);
@@ -77,17 +86,58 @@ const SettingsMain = () => {
7786
</Button>
7887
</CardSection>
7988

80-
<CardSection vertical gap={10}>
81-
<Typography.Paragraph strong>Backup wallet</Typography.Paragraph>
82-
<Button
83-
type="primary"
84-
size="large"
85-
disabled={true} // not in this iteration?
86-
onClick={() => gotoSettings(SettingsScreen.AddBackupWallet)}
87-
>
88-
Add backup wallet
89-
</Button>
89+
<CardSection vertical gap={24}>
90+
<Typography.Text strong>Backup wallet</Typography.Text>
91+
{backupSafeAddress ? (
92+
<Link
93+
type="link"
94+
target="_blank"
95+
href={`https://gnosisscan.io/address/${backupSafeAddress}`}
96+
>
97+
{truncatedBackupSafeAddress} {UNICODE_SYMBOLS.EXTERNAL_LINK}
98+
</Link>
99+
) : (
100+
<NoBackupWallet />
101+
)}
90102
</CardSection>
91103
</Card>
92104
);
93105
};
106+
107+
const NoBackupWallet = () => {
108+
const { goto: gotoSettings } = useSettings();
109+
return (
110+
<>
111+
<Typography.Text type="secondary">
112+
No backup wallet added.
113+
</Typography.Text>
114+
<CardSection>
115+
<Alert
116+
type="warning"
117+
className="card-section-alert"
118+
showIcon
119+
message={
120+
<>
121+
<Flex vertical gap={5}>
122+
<Typography.Text strong style={{ color: COLOR.BROWN }}>
123+
Your funds are at risk!
124+
</Typography.Text>
125+
<Typography.Text style={{ color: COLOR.BROWN }}>
126+
You will lose any assets you send on other chains.
127+
</Typography.Text>
128+
</Flex>
129+
</>
130+
}
131+
/>
132+
</CardSection>
133+
<Button
134+
type="primary"
135+
size="large"
136+
disabled={true} // not in this iteration?
137+
onClick={() => gotoSettings(SettingsScreen.AddBackupWallet)}
138+
>
139+
Add backup wallet
140+
</Button>
141+
</>
142+
);
143+
};

0 commit comments

Comments
 (0)