-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathindex.tsx
More file actions
150 lines (142 loc) · 4.3 KB
/
Copy pathindex.tsx
File metadata and controls
150 lines (142 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React from "react";
import { useDispatch } from "react-redux";
import { useNavigate } from "react-router-dom";
import { Asset, Badge, Button, Icon, Text } from "@stellar/design-system";
import { Networks } from "stellar-sdk";
import { KeyIdenticon } from "popup/components/identicons/KeyIdenticon";
import { AppDispatch } from "popup/App";
import { NetworkDetails, NETWORKS } from "@shared/constants/stellar";
import { addTokenId } from "popup/ducks/accountServices";
import { removeTokenId } from "popup/ducks/transactionSubmission";
import { navigateTo } from "popup/helpers/navigate";
import { ROUTES } from "popup/constants/routes";
import "./styles.scss";
import { isSacContract } from "popup/helpers/soroban";
import { truncateString } from "helpers/stellar";
interface ToggleTokenInternalProps {
asset: {
code: string;
issuer: string;
image: string;
isTrustlineActive: boolean;
domain: string;
contract?: string;
name?: string;
};
networkDetails: NetworkDetails;
onCancel: () => void;
publicKey: string;
}
export const ToggleTokenInternal = ({
asset,
networkDetails,
onCancel,
publicKey,
}: ToggleTokenInternalProps) => {
const dispatch: AppDispatch = useDispatch();
const nav = useNavigate();
const onConfirm = async () => {
if (!asset.isTrustlineActive) {
await dispatch(
addTokenId({
publicKey,
tokenId: asset.contract!,
network: networkDetails.network as Networks,
}),
);
} else {
await dispatch(
removeTokenId({
contractId: asset.contract!,
network: networkDetails.network as NETWORKS,
}),
);
}
navigateTo(ROUTES.account, nav);
};
const isSac =
!!asset.name &&
!!asset.contract &&
isSacContract(asset.name, asset.contract, networkDetails.networkPassphrase);
return (
<div className="ToggleToken__wrapper">
<div className="ToggleToken__wrapper__body">
<div className="ToggleToken__wrapper__header">
{asset.image && (
<div className="ToggleToken__wrapper__icon-logo">
<Asset
size="lg"
variant="single"
sourceOne={{
altText: "Token logo",
image: asset.image,
}}
/>
</div>
)}
{!asset.image && asset.code && (
<div className="ToggleToken__wrapper__code-logo">
<Text
as="div"
size="sm"
weight="bold"
addlClassName="ToggleToken__wrapper--logo-label"
>
{asset.code.slice(0, 2)}
</Text>
</div>
)}
<Text as="div" size="sm" weight="medium">
{isSac ? asset.code : asset.name || truncateString(asset.contract!)}
</Text>
<div className="ToggleToken__wrapper__badge">
<Badge
size="sm"
variant="secondary"
icon={<Icon.PlusCircle />}
iconPosition="left"
>
{asset.isTrustlineActive ? "Remove Token" : "Add Token"}
</Badge>
</div>
</div>
<div className="ToggleToken__Description">
{asset.isTrustlineActive
? "Remove token from your account balance view"
: "Allow token to be displayed and used with this wallet address"}
</div>
<div className="ToggleToken__Metadata">
<div className="ToggleToken__Metadata__Row">
<div className="ToggleToken__Metadata__Label">
<Icon.Wallet01 />
<span>Wallet</span>
</div>
<div className="ToggleToken__Metadata__Value">
<KeyIdenticon publicKey={publicKey} />
</div>
</div>
</div>
<div className="ToggleToken__Actions">
<Button
isRounded
isFullWidth
size="lg"
variant="tertiary"
onClick={onCancel}
>
Cancel
</Button>
<Button
variant="secondary"
isFullWidth
isRounded
size="lg"
onClick={onConfirm}
>
Confirm
</Button>
</div>
</div>
</div>
);
};