Skip to content

Commit 758ce4d

Browse files
author
Itzik Grossman
committed
Add new token
1 parent ba7cf1c commit 758ce4d

33 files changed

+649
-747
lines changed

.prettierrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 80,
2+
"printWidth": 120,
33
"singleQuote": true,
44
"trailingComma": "all"
55
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { TokenDisplay } from '../../pages/Swap';
2+
3+
const LOCAL_STORAGE_KEY = 'SwapLocalStorageTokens';
4+
5+
const setLocalStorage = item => localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(item));
6+
const getLocalStorage = () => JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY));
7+
8+
class LocalStorageTokens {
9+
static store(token: TokenDisplay) {
10+
let tokens: Record<string, TokenDisplay> | null = getLocalStorage();
11+
12+
// todo: handle overwriting tokens with the same symbol
13+
if (!tokens) {
14+
tokens = {};
15+
}
16+
tokens[token.symbol] = token;
17+
18+
setLocalStorage(tokens);
19+
window.dispatchEvent(new Event('storage'));
20+
}
21+
22+
static get(): Record<string, TokenDisplay> | null {
23+
try {
24+
return getLocalStorage();
25+
} catch {
26+
return null;
27+
}
28+
}
29+
}
30+
31+
export default LocalStorageTokens;

src/blockchain-bridge/scrt/snip20.ts

+67-31
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
import { ExecuteResult, SigningCosmWasmClient } from 'secretjs';
22
import { divDecimals, unlockToken } from '../../utils';
33

4-
export const Snip20SwapHash = (params: { tx_id: string, address: string }): string => {
4+
export const Snip20SwapHash = (params: { tx_id: string; address: string }): string => {
55
return `${params.tx_id}|${params.address}`;
6+
};
7+
8+
export interface Snip20TokenInfo {
9+
name: string;
10+
symbol: string;
11+
decimals: number;
12+
total_supply?: string;
613
}
714

15+
export const GetSnip20Params = async (params: {
16+
secretjs: SigningCosmWasmClient;
17+
address: string;
18+
}): Promise<Snip20TokenInfo> => {
19+
const { secretjs, address } = params;
20+
21+
try {
22+
const paramsResponse = await secretjs.queryContractSmart(address, { token_info: {} });
823

9-
export const Snip20GetBalance = async (params: { secretjs: SigningCosmWasmClient, token: string, address: string, key: string, decimals: number }) => {
24+
return {
25+
name: paramsResponse.token_info.name,
26+
symbol: paramsResponse.token_info.symbol,
27+
decimals: paramsResponse.token_info.decimals,
28+
total_supply: paramsResponse.token_info?.total_supply,
29+
};
30+
} catch (e) {
31+
throw Error('Failed to get info');
32+
}
33+
};
1034

11-
const {secretjs, address, token, key, decimals } = params;
35+
export const Snip20GetBalance = async (params: {
36+
secretjs: SigningCosmWasmClient;
37+
token: string;
38+
address: string;
39+
key: string;
40+
decimals: number;
41+
}) => {
42+
const { secretjs, address, token, key, decimals } = params;
1243

1344
let balanceResponse;
1445
try {
@@ -19,7 +50,7 @@ export const Snip20GetBalance = async (params: { secretjs: SigningCosmWasmClient
1950
},
2051
});
2152
} catch (e) {
22-
console.log(e)
53+
console.log(e);
2354
return unlockToken;
2455
}
2556

@@ -30,42 +61,47 @@ export const Snip20GetBalance = async (params: { secretjs: SigningCosmWasmClient
3061
if (Number(balanceResponse.balance.amount) === 0) {
3162
return '0';
3263
}
33-
return divDecimals(
34-
balanceResponse.balance.amount,
35-
decimals,
36-
);
37-
}
64+
return divDecimals(balanceResponse.balance.amount, decimals);
65+
};
3866

39-
export const Snip20SendToBridge = async (params: { secretjs: SigningCosmWasmClient, address: string, amount: string, msg: string, recipient?: string }): Promise<string> => {
40-
const tx = await Snip20Send({recipient: params.recipient || process.env.SCRT_SWAP_CONTRACT, ...params});
67+
export const Snip20SendToBridge = async (params: {
68+
secretjs: SigningCosmWasmClient;
69+
address: string;
70+
amount: string;
71+
msg: string;
72+
recipient?: string;
73+
}): Promise<string> => {
74+
const tx = await Snip20Send({
75+
recipient: params.recipient || process.env.SCRT_SWAP_CONTRACT,
76+
...params,
77+
});
4178

42-
const txIdKvp = tx.logs[0].events[1].attributes.find(
43-
kv => kv.key === 'tx_id',
44-
);
79+
const txIdKvp = tx.logs[0].events[1].attributes.find(kv => kv.key === 'tx_id');
4580

4681
let tx_id: string;
4782
if (txIdKvp && txIdKvp.value) {
4883
tx_id = txIdKvp.value;
4984
} else {
50-
throw new Error("Failed to get tx_id")
85+
throw new Error('Failed to get tx_id');
5186
}
5287

53-
return tx_id
54-
}
55-
56-
export const Snip20Send = async (params: { secretjs: SigningCosmWasmClient, address: string, amount: string, msg: string, recipient: string }): Promise<ExecuteResult> => {
88+
return tx_id;
89+
};
5790

58-
const {secretjs, address, amount, msg, recipient } = params;
91+
export const Snip20Send = async (params: {
92+
secretjs: SigningCosmWasmClient;
93+
address: string;
94+
amount: string;
95+
msg: string;
96+
recipient: string;
97+
}): Promise<ExecuteResult> => {
98+
const { secretjs, address, amount, msg, recipient } = params;
5999

60-
return await secretjs.execute(
61-
address,
62-
{
63-
send: {
64-
amount,
65-
recipient,
66-
msg,
67-
},
100+
return await secretjs.execute(address, {
101+
send: {
102+
amount,
103+
recipient,
104+
msg,
68105
},
69-
);
70-
71-
}
106+
});
107+
};

src/blockchain-bridge/scrt/utils.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { decode } from 'bech32';
22

3-
const HRP = "secret";
3+
const HRP = 'secret';
44

5-
export const getScrtAddress = address => {
5+
export const getScrtAddress = (address: string): string => {
66
try {
77
const decoded = decode(address, 46);
88
return decoded.prefix === HRP ? address : '';
99
} catch {
1010
return '';
1111
}
12-
}
12+
};
1313

14+
export const validateBech32Address = (address: string): boolean => {
15+
return getScrtAddress(address) !== '';
16+
};
1417
// getAddress(address).bech32;

src/components/Earn/SoftTitleValue/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import React from 'react';
22
import * as styles from './styles.styl';
33
import cn from 'classnames';
44

5-
const SoftTitleValue = props => {
5+
const SoftTitleValue = (props: {
6+
title: string | JSX.Element;
7+
subTitle?: string | JSX.Element;
8+
}) => {
69
if (props.subTitle) {
710
return (
811
<div>

src/components/Swap/Buttons/AddLiquidityButton.tsx

-6
This file was deleted.

src/components/Swap/Buttons/Button.tsx

-17
This file was deleted.

src/components/Swap/Buttons/CreateAPairButton.tsx

-6
This file was deleted.

src/components/Swap/ErrorToast.tsx

Whitespace-only changes.

src/components/Swap/Header.tsx

-41
This file was deleted.

src/components/Swap/InfoBox.tsx

-5
This file was deleted.

src/components/Swap/PairIcons/PairIcons.tsx

-26
This file was deleted.

src/components/Swap/PairIcons/styles.styl

-6
This file was deleted.

src/components/Swap/PairInfoRow.tsx

-10
This file was deleted.

0 commit comments

Comments
 (0)