Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: connect core backend #102

Merged
merged 33 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e04feaf
Generalise script for reading from production repo
dib542 Jul 28, 2022
239cb33
Fix autogenerated code files with update script
dib542 Jul 29, 2022
92b7e58
Add auto-generated code from production repo
dib542 Jul 28, 2022
57bde17
Add local dev coins from backend repo
dib542 Jul 29, 2022
84b6b13
Swap cosmos mock backend logic with cosmos core logic
dib542 Jul 29, 2022
779aaba
Fix searching of state for tick pairs: frontend has no sorting context
dib542 Jul 30, 2022
0441b66
Remove cosmos-mock generated (and semi-generated code)
dib542 Aug 1, 2022
7c27498
Add sorted Tick arrays and keyed Ticks by ID structures both:
dib542 Aug 2, 2022
e037fb7
Stop storing TickInfo indexes as they need to be updated on new info
dib542 Aug 2, 2022
c2c50b1
Optimise finding state pairs without knowing the sorting order
dib542 Aug 2, 2022
8041d6f
Subscribe to core backend NewDeposit and NewWithdraw shapes
dib542 Aug 2, 2022
af473d4
Make event new totalShares calculation more understandable
dib542 Aug 2, 2022
bcf2cc5
Fix Query transformation of tick pools to be transformed independently
dib542 Aug 3, 2022
2052a69
Ensure Msg requests in token are rounded to minimum denom integers
dib542 Aug 3, 2022
ffdf815
Add note about unhandled pool arrays
dib542 Aug 3, 2022
f3f443d
Handle sorting of new tick pools
dib542 Aug 3, 2022
e1df047
Remove unused mock data of outdated format
dib542 Aug 3, 2022
8dd6452
Add JSDoc types to helper script
dib542 Aug 4, 2022
ae9c689
Add note about price type
dib542 Aug 4, 2022
ddee213
Remove explicit \n chars from autogenerated code changes
dib542 Aug 4, 2022
cc08afe
Update generated code with new changes
dib542 Aug 4, 2022
3c914c6
Do not check for pool length in one direction:
dib542 Aug 5, 2022
dc8e7e0
Fix tickState sorted pools shape on handling Events
dib542 Aug 5, 2022
4f29ff7
Revert "Update generated code with new changes"
dib542 Aug 5, 2022
ec2655b
Abstract out combining old tick state new tick data
dib542 Aug 5, 2022
0869e6c
Abstract out combining old tick state new tick data, part 2: move
dib542 Aug 5, 2022
0de4947
Rename message handler for dex module messages
dib542 Aug 5, 2022
6789648
Add update to tick state from NewSwap messages
dib542 Aug 5, 2022
ab87f64
Fix unsurfaced possible value is undefined error
dib542 Aug 5, 2022
301156a
Remove previous commit issue by replacing tick objects completely
dib542 Aug 5, 2022
5ac7a1a
Add PoolTicks type
dib542 Aug 5, 2022
0c90a49
Add note about possible future backend provision of totalShares
dib542 Aug 22, 2022
40c6729
Add note about tick state optimization
dib542 Aug 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ REACT_APP__CHAIN_ID=duality
REACT_APP__CHAIN_NAME=Duality testnet
REACT_APP__COIN_DENOM=COSMOS
REACT_APP__COIN_MIN_DENOM=token
REACT_APP__COIN_MIN_DENOM_EXP=18
REACT_APP__REST_API=http://localhost:1317
REACT_APP__RPC_API=http://localhost:26657
REACT_APP__WEBSOCKET_URL=ws://localhost:26657/websocket
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@

# ignore change log, it is auto-formatted by semantic release
CHANGELOG.md

# autogenerated code
/src/lib/web3/generated
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
"typescript": "^4.6.3"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx,json,css,scss,html,md,yaml,yml}": [
"**/*.{mjs,js,jsx,ts,tsx,json,css,scss,html,md,yaml,yml}": [
"prettier --write"
],
"**/*.{js,jsx,ts,tsx}": [
"**/*.{mjs,js,jsx,ts,tsx}": [
"eslint --max-warnings 0"
]
},
Expand Down
90 changes: 90 additions & 0 deletions scripts/update-generated-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import fs from 'fs';

/**
* @param {string} directory
* @param {{ recursive: boolean }} opts
*/
function getDirFilenames(directory, opts = {}) {
dib542 marked this conversation as resolved.
Show resolved Hide resolved
return fs
.readdirSync(directory, { withFileTypes: true })
.reduce((result, file) => {
const path = `${directory}/${file.name}`;
if (opts.recursive && file.isDirectory()) {
result.push(...getDirFilenames(path, opts));
} else {
result.push(path);
}
return result;
}, []);
}

const files = getDirFilenames('./src/lib/web3/generated', { recursive: true });

// fix ESLint and TypeScript warnings
files
.filter((file) => file.endsWith('/index.ts'))
.forEach((file) => {
const data = fs.readFileSync(file, { encoding: 'utf8' });
fs.writeFileSync(
file,
`
/* eslint-disable */
/* tslint:disable */
${data}`.trimStart()
);
});

// fix TypeScript error
files
.filter((file) => file.endsWith('/index.ts'))
.forEach((file) => {
const data = fs.readFileSync(file, { encoding: 'utf8' });
const get = `
let client;
if (addr) {
client = await SigningStargateClient.connectWithSigner(addr, wallet, { registry });
}else{
client = await SigningStargateClient.offline( wallet, { registry });
}
`;
const set = `
const client = addr
? await SigningStargateClient.connectWithSigner(addr, wallet, { registry })
: await SigningStargateClient.offline( wallet, { registry });
`;
const replaced = data.replace(get, set);
fs.writeFileSync(file, replaced);
});

// fix hardcoded URLs
files
.filter((file) => file.endsWith('/index.ts'))
.forEach((file) => {
const replaced = fs
.readFileSync(file, { encoding: 'utf8' })
.replace(
'"http://localhost:26657"',
'process.env.REACT_APP__RPC_API || ""'
)
.replace(
'"http://localhost:1317"',
'process.env.REACT_APP__REST_API || ""'
);
fs.writeFileSync(file, replaced);
});

// remove non-module index files (eg. vuex index.ts files)
files
.filter(
(file) => file.endsWith('/index.ts') && !file.endsWith('/module/index.ts')
)
.forEach((file) => {
fs.rmSync(file);
});

// remove vuex-root files
files
.filter((file) => file.endsWith('/vuex-root'))
.forEach((file) => {
fs.rmSync(file);
});
23 changes: 11 additions & 12 deletions scripts/update-generated-files.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/bin/sh

# use provided source path or a default
DUALITY_CORE_DIRECTORY="${1:-"../duality"}"
CHAIN_REPO="${1:-"duality"}"
CHAIN_REPO_USER_NAME=$(echo $CHAIN_REPO | cut -d '/' -f 1) # get name part
CHAIN_REPO_PROJECT_NAME=$(echo "$CHAIN_REPO" | cut -d '/' -f 2) # get name part
CHAIN_REPO_PROJECT_NAME="${CHAIN_REPO_PROJECT_NAME:-$CHAIN_REPO_USER_NAME}" # default project name to copy of username if not specified
CHAIN_REPO_MODULE_NAME=$(echo $CHAIN_REPO_USER_NAME | tr '[:upper:]' '[:lower:]') # get name part as lowercase of username
DUALITY_CORE_DIRECTORY="${2:-"../duality"}"

# copy type files
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/module/types" \
"src/lib/web3/generated/duality/duality.duality/module"

# copy REST API file
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/module/rest.ts" \
"src/lib/web3/generated/duality/duality.duality/module/rest.ts"

# copy version info
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/package.json" \
"src/lib/web3/generated/duality/duality.duality/package.json"
# copy module files
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/$CHAIN_REPO" \
"src/lib/web3/generated"

# copy readme info
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/readme.md" \
"src/lib/web3/generated/readme.md"

node ./scripts/update-generated-files.mjs
2 changes: 2 additions & 0 deletions src/components/TokenPicker/mockHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface SwapRequest {
}

const tokens: Array<Token> = [
{ logo: null, symbol: 'TKN', name: 'TokenCoin', address: 'token' },
{ logo: null, symbol: 'STK', name: 'StakeCoin', address: 'stake' },
{ logo: null, symbol: 'Eth', name: 'Ether', address: 'ETH' },
{
logo: null,
Expand Down
79 changes: 0 additions & 79 deletions src/lib/web3/api.ts

This file was deleted.

Loading