Skip to content

Commit f64ec39

Browse files
committed
update
1 parent 6d2c599 commit f64ec39

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
build.zip

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "chrome-bybit-extension",
3+
"description": "A chrome extension to help with position sizing according to risk and reward. Takes your balance, stoploss, margin and risk, returns a the right leverage.",
34
"version": "0.1.0",
45
"private": true,
56
"homepage": ".",

public/logo128.png

4.97 KB
Loading

public/manifest.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"short_name": "Bybit R:R",
33
"name": "Bybit Risk:Reward Calculator",
4+
"description": "A chrome extension to help with position sizing according to risk and reward.",
45
"version": "1.0",
56
"manifest_version": 3,
67
"icons": {
@@ -12,7 +13,7 @@
1213
"default_popup": "index.html",
1314
"default_title": "Bybit Risk:Reward Calculator"
1415
},
15-
"permissions": ["activeTab", "storage"],
16+
"permissions": ["https://*.bybit.com/*", "storage"],
1617
"content_scripts": [
1718
{
1819
"matches": ["https://*.bybit.com/*"],

src/App.tsx

+24-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum PersistableSetting {
1414
MARGIN,
1515
STOPLOSS,
1616
RISK,
17+
DECIMALS,
1718
}
1819

1920
function App() {
@@ -33,6 +34,7 @@ function App() {
3334
const [stoplossStored, setStoplossStored] = useState(true);
3435
const [riskStored, setRiskStored] = useState(true);
3536
const [decimals, setDecimals] = useState(2);
37+
const [decimalsStored, setDecimalsStored] = useState(true);
3638

3739
useEffect(() => {
3840
if (stoplossRelative && marketPrice) {
@@ -168,6 +170,11 @@ function App() {
168170
if (risk) {
169171
setRiskRelative(risk);
170172
}
173+
174+
const decimals = await getSetting(PersistableSetting.DECIMALS);
175+
if (decimals) {
176+
setDecimals(decimals);
177+
}
171178
})();
172179
}, []);
173180

@@ -193,10 +200,25 @@ function App() {
193200
id="decimals"
194201
label="Decimals"
195202
type="number"
196-
append={<DecimalsIcon className="w-6 h-6" />}
197203
value={decimals}
198-
onChange={(e) => setDecimals(Number(e.target.value))}
204+
onChange={(e) => {
205+
setDecimals(Number(e.target.value));
206+
setDecimalsStored(false);
207+
}}
199208
showLabel
209+
append={
210+
!decimalsStored ? (
211+
<SaveIcon
212+
className="w-6 h-6 cursor-pointer"
213+
onClick={() => {
214+
storeSetting(PersistableSetting.DECIMALS, decimals);
215+
setDecimalsStored(true);
216+
}}
217+
/>
218+
) : (
219+
<DecimalsIcon className="w-6 h-6" />
220+
)
221+
}
200222
/>
201223
</div>
202224
<Input

src/content.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ const messagesFromReactAppListener = (msg: MessageRequest, sender: chrome.runtim
1818
const marginContent = $('.by-popover__el:contains("Order by")').closest('.oc__row-bottom--12').find('.by-input__inner').val()
1919
const margin = parseVal(String(marginContent));
2020

21-
console.log(marginContent, margin)
22-
2321
const response: MessageResponse[MessageType.GET_DOM] = {
2422
equity,
2523
marketPrice,
@@ -43,10 +41,9 @@ const messagesFromReactAppListener = (msg: MessageRequest, sender: chrome.runtim
4341

4442
sendResponse<MessageResponse[MessageType.SET_TRADE_TYPE]>({ success: true })
4543
} else if (msg.type === MessageType.SET_STOPLOSS) {
46-
const stoploss = $('.tpsl-modal-item__title:contains("Stop Loss")').closest('.oc__row-bottom--12').find('.profit-input .by-input__inner');
47-
console.log(stoploss, msg.payload.stoploss)
48-
stoploss.val(Number(msg.payload.stoploss))
49-
// stoploss.trigger($.Event('keypress', { keyCode: 49 }))
44+
// TODO Bybit reverts changes to the input.value, need to find another way.
45+
// const stoploss = $('.tpsl-modal-item__title:contains("Stop Loss")').closest('.oc__row-bottom--12').find('.profit-input .by-input__inner');
46+
// stoploss.val(Number(msg.payload.stoploss))
5047
}
5148
}
5249

0 commit comments

Comments
 (0)