Skip to content

Commit

Permalink
Merge pull request #21 from perpetual-protocol/main
Browse files Browse the repository at this point in the history
Merge from main
  • Loading branch information
lsps9150414 authored May 20, 2021
2 parents b56d2a4 + b66c566 commit f4ebcfd
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 169 deletions.
107 changes: 55 additions & 52 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,48 @@ jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2

- name: Set variables
id: set-variables
run: |
if [[ ${{ github.event.release.tag_name }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+-prod$ ]] \
&& [[ ${{ github.event.release.target_commitish }} =~ ^release\/[0-9]+\.[0-9]+\.[0-9x]+$ ]]
then
echo "::set-output name=release_env::production"
echo "::set-output name=xdai_rpc_url::${{ secrets.XDAI_RPC_URL_PROD }}"
echo "::set-output name=infura_api_key::${{ secrets.INFURA_API_KEY_PROD }}"
echo "::set-output name=segment_api_key::${{ secrets.SEGMENT_API_KEY_PROD }}"
echo "::set-output name=aws_s3_bucket::${{ secrets.AWS_BUCKET_NAME_PROD }}"
echo "::set-output name=aws_s3_bucket_region::${{ secrets.AWS_BUCKET_REGION_PROD }}"
echo "::set-output name=aws_access_key_id::${{ secrets.AWS_ACCESS_KEY_ID_PROD }}"
echo "::set-output name=aws_secret_access_key::${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }}"
elif [[ ${{ github.event.release.tag_name }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] \
&& [[ ${{ github.event.release.target_commitish }} =~ ^release\/[0-9]+\.[0-9]+\.[0-9x]+$ ]]
then
echo "::set-output name=release_env::staging"
echo "::set-output name=xdai_rpc_url::${{ secrets.XDAI_RPC_URL }}"
echo "::set-output name=infura_api_key::${{ secrets.INFURA_API_KEY }}"
echo "::set-output name=segment_api_key::${{ secrets.SEGMENT_API_KEY }}"
echo "::set-output name=aws_s3_bucket::${{ secrets.AWS_BUCKET_NAME }}"
echo "::set-output name=aws_s3_bucket_region::${{ secrets.AWS_BUCKET_REGION }}"
echo "::set-output name=aws_access_key_id::${{ secrets.AWS_ACCESS_KEY_ID }}"
echo "::set-output name=aws_secret_access_key::${{ secrets.AWS_SECRET_ACCESS_KEY }}"
else
echo "Your tag and branch are not matched."
exit 1
fi
echo "::set-output name=npm_cache_dir::$(npm config get cache)"
if [[ ${{ github.event.release.tag_name }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+-prod$ ]] \
&& [[ ${{ github.event.release.target_commitish }} =~ ^release\/[0-9]+\.[0-9]+\.[0-9x]+$ ]]
then
echo "::set-output name=release_env::production"
echo "::set-output name=xdai_rpc_url::${{ secrets.XDAI_RPC_URL_PROD }}"
echo "::set-output name=infura_api_key::${{ secrets.INFURA_API_KEY_PROD }}"
echo "::set-output name=segment_api_key::${{ secrets.SEGMENT_API_KEY_PROD }}"
echo "::set-output name=bugsnag_api_key::${{ secrets.BUGSNAG_API_KEY_PROD }}"
echo "::set-output name=aws_s3_bucket::${{ secrets.AWS_BUCKET_NAME_PROD }}"
echo "::set-output name=aws_s3_bucket_region::${{ secrets.AWS_BUCKET_REGION_PROD }}"
echo "::set-output name=aws_access_key_id::${{ secrets.AWS_ACCESS_KEY_ID_PROD }}"
echo "::set-output name=aws_secret_access_key::${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }}"
elif [[ ${{ github.event.release.tag_name }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] \
&& [[ ${{ github.event.release.target_commitish }} =~ ^release\/[0-9]+\.[0-9]+\.[0-9x]+$ ]]
then
echo "::set-output name=release_env::staging"
echo "::set-output name=xdai_rpc_url::${{ secrets.XDAI_RPC_URL }}"
echo "::set-output name=infura_api_key::${{ secrets.INFURA_API_KEY }}"
echo "::set-output name=segment_api_key::${{ secrets.SEGMENT_API_KEY }}"
echo "::set-output name=bugsnag_api_key::${{ secrets.BUGSNAG_API_KEY }}"
echo "::set-output name=aws_s3_bucket::${{ secrets.AWS_BUCKET_NAME }}"
echo "::set-output name=aws_s3_bucket_region::${{ secrets.AWS_BUCKET_REGION }}"
echo "::set-output name=aws_access_key_id::${{ secrets.AWS_ACCESS_KEY_ID }}"
echo "::set-output name=aws_secret_access_key::${{ secrets.AWS_SECRET_ACCESS_KEY }}"
else
echo "Your tag and branch are not matched."
exit 1
fi
echo "::set-output name=npm_cache_dir::$(npm config get cache)"
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ matrix.node-version }}

# See: https://github.com/actions/cache/blob/main/examples.md#node---yarn
- name: Get Yarn cache directory
Expand All @@ -58,21 +60,22 @@ jobs:
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}

- name: Install package dependencies
run: yarn install --prefer-offline --frozen-lockfile

- name: Build static website
run: yarn build
env:
CI: ''
REACT_APP_STAGE: ${{ steps.set-variables.outputs.release_env }}
REACT_APP_GITHUB_TAG: ${{ github.event.release.tag_name }}
REACT_APP_XDAI_RPC_URL: ${{ steps.set-variables.outputs.xdai_rpc_url }}
REACT_APP_INFURA_API_KEY: ${{ steps.set-variables.outputs.infura_api_key }}
REACT_APP_SEGMENT_API_KEY: ${{ steps.set-variables.outputs.segment_api_key }}
CI: ""
REACT_APP_STAGE: ${{ steps.set-variables.outputs.release_env }}
REACT_APP_GITHUB_TAG: ${{ github.event.release.tag_name }}
REACT_APP_XDAI_RPC_URL: ${{ steps.set-variables.outputs.xdai_rpc_url }}
REACT_APP_INFURA_API_KEY: ${{ steps.set-variables.outputs.infura_api_key }}
REACT_APP_SEGMENT_API_KEY: ${{ steps.set-variables.outputs.segment_api_key }}
REACT_APP_BUGSNAG_API_KEY: ${{ steps.set-variables.outputs.bugsnag_api_key }}

- name: Upload website to S3
uses: jakejarvis/s3-sync-action@master
Expand All @@ -88,30 +91,30 @@ jobs:
- name: Update metadata of index.html on S3
uses: prewk/[email protected]
with:
args: --metadata-directive REPLACE --cache-control no-cache --acl public-read
args: --metadata-directive REPLACE --cache-control no-cache --acl public-read
env:
AWS_ACCESS_KEY_ID: ${{ steps.set-variables.outputs.aws_access_key_id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.set-variables.outputs.aws_secret_access_key }}
AWS_REGION: ${{ steps.set-variables.outputs.aws_s3_bucket_region }}
SOURCE: "s3://${{ steps.set-variables.outputs.aws_s3_bucket }}/index.html"
DEST: "s3://${{ steps.set-variables.outputs.aws_s3_bucket }}/index.html"
AWS_ACCESS_KEY_ID: ${{ steps.set-variables.outputs.aws_access_key_id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.set-variables.outputs.aws_secret_access_key }}
AWS_REGION: ${{ steps.set-variables.outputs.aws_s3_bucket_region }}
SOURCE: "s3://${{ steps.set-variables.outputs.aws_s3_bucket }}/index.html"
DEST: "s3://${{ steps.set-variables.outputs.aws_s3_bucket }}/index.html"

- name: Update metadata of static/ on S3
uses: prewk/[email protected]
with:
args: --recursive --metadata-directive REPLACE --cache-control max-age=1209600,must-revalidate --acl public-read
args: --recursive --metadata-directive REPLACE --cache-control max-age=1209600,must-revalidate --acl public-read
env:
AWS_ACCESS_KEY_ID: ${{ steps.set-variables.outputs.aws_access_key_id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.set-variables.outputs.aws_secret_access_key }}
AWS_REGION: ${{ steps.set-variables.outputs.aws_s3_bucket_region }}
SOURCE: "s3://${{ steps.set-variables.outputs.aws_s3_bucket }}/static/"
DEST: "s3://${{ steps.set-variables.outputs.aws_s3_bucket }}/static/"
AWS_ACCESS_KEY_ID: ${{ steps.set-variables.outputs.aws_access_key_id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.set-variables.outputs.aws_secret_access_key }}
AWS_REGION: ${{ steps.set-variables.outputs.aws_s3_bucket_region }}
SOURCE: "s3://${{ steps.set-variables.outputs.aws_s3_bucket }}/static/"
DEST: "s3://${{ steps.set-variables.outputs.aws_s3_bucket }}/static/"

- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "**[${{ steps.set-variables.outputs.release_env }}]** perp-lite deployed.
Tag: **${{ github.event.release.tag_name }}** (${{ github.event.release.html_url }})
${{ github.event.release.body }}"
Tag: **${{ github.event.release.tag_name }}** (${{ github.event.release.html_url }})
${{ github.event.release.body }}"
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@


## Perp Lite

<img width="256px" style="margin: 0 auto; float: right" src="https://github.com/perpetual-protocol/perp-lite/raw/main/public/lite-banner.png" />


This is a lite version of Perpetual Protocol UI with essential features. Note that you need to manually switch to xDai network to trade.

- 👉🏻 [Official Site](https://perp.exchange)
Expand Down
Binary file added public/lite-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 22 additions & 21 deletions src/container/transaction/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { BiconomyError, TxRejectError } from "../../util/error"
import React, { useEffect } from "react"
import { createContainer } from "unstated-next"
import { TransactionReceipt } from "@ethersproject/providers"
import { useState, useCallback } from "react"
import { useNotification } from "../../hook/useNotification"
import { getEtherscanTxLink } from "util/link"
import { ExternalLink } from "component/ExternalLink"
import { useCallback, useState } from "react"

import { BigNumber } from "ethers"
import { CHAIN_ID } from "connector"
import { Connection } from "container/connection"
import { ContractTransaction } from "@ethersproject/contracts"
import { ExternalLink } from "component/ExternalLink"
import { STORAGE_KEY } from "constant/storage"
import { TransactionReceipt } from "@ethersproject/providers"
import { User } from "../user"
import { BigNumber } from "ethers"
import { createContainer } from "unstated-next"
import { getEtherscanTxLink } from "util/link"
import { logger } from "lib/bugsnag/logger"
import { useLocalStorage } from "hook/useLocalStorage"
import { STORAGE_KEY } from "constant/storage"
import { Connection } from "container/connection"
import { CHAIN_ID } from "connector"
import { BiconomyError, TxRejectError } from "../../util/error"
import { useNotification } from "../../hook/useNotification"

export const Transaction = createContainer(useTransaction)

Expand Down Expand Up @@ -68,7 +70,6 @@ function useTransaction() {
const provider = chainId === CHAIN_ID.XDai ? xDaiProvider : ethProvider

const resetTxStatus = useCallback(() => {
console.log("debug:", "in reset")
setIsLoading(false)
setLatestTxData("")
}, [setLatestTxData])
Expand All @@ -87,7 +88,7 @@ function useTransaction() {
description: successDesc,
})
} else if (triedTimes < MAX_RETRY_TIMES) {
console.log("triedTimes", triedTimes)
logger.info("triedTimes", triedTimes)
setTimeout(() => {
checkReceipt(triedTimes + 1)
}, 2000)
Expand All @@ -100,7 +101,7 @@ function useTransaction() {
}
} catch (err) {
resetTxStatus()
console.log("debug:", "err", err)
logger.error(err)
}
}
if (!isInitialized) {
Expand Down Expand Up @@ -183,7 +184,7 @@ function useTransaction() {
})
setError(err)
}
console.log(err)
logger.error(err)
resetTxStatus()
}
return {
Expand Down Expand Up @@ -217,9 +218,9 @@ function useTransaction() {
title: <ExternalLink href={getEtherscanTxLink(txHash)}>{successTitle}</ExternalLink>,
description: successDesc,
})
} catch (e) {
console.log(e)
setError(e)
} catch (err) {
logger.error(err)
setError(err)
notifyError({
title: <ExternalLink href={getEtherscanTxLink(txHash)}>{errorTitle}</ExternalLink>,
description: errorDesc,
Expand All @@ -244,9 +245,9 @@ function useTransaction() {
contract[funcName](...args, { ...overrides, gasLimit: gasLimitRatio.mul(gasLimit) }),
option,
)
} catch (e) {
setError(e)
console.log(e)
} catch (err) {
logger.error(err)
setError(err)
}
return receipt
},
Expand Down
9 changes: 5 additions & 4 deletions src/container/user/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CHAIN_ID } from "../../connector"
import { STORAGE_KEY } from "../../constant"
import { SUPPORTED_WALLETS } from "constant/wallet"
import { createContainer } from "unstated-next"
import { logger } from "lib/bugsnag/logger"
import { useLocalStorage } from "../../hook/useLocalStorage"
import { useNotification } from "../../hook/useNotification"
import { usePrevious } from "../../hook/usePrevious"
Expand Down Expand Up @@ -68,12 +69,12 @@ function useUser() {
if (onActivate) {
onActivate()
}
console.log("connect success")
logger.info("connect success")
})
.catch(e => {
.catch(err => {
setConnectorId("")
dispatch({ type: ACTIONS.LOGIN_FAIL })
console.error("connect failed", e)
logger.error(err)
})
},
[dispatch, setConnectorId, activate],
Expand Down Expand Up @@ -110,7 +111,7 @@ function useUser() {
useEffect(() => {
const connector = SUPPORTED_WALLETS.find(walletInfo => walletInfo.id === connectorId)?.connector
if (!isTried && connector) {
console.log("auto login...")
logger.info("auto login...")
login(connector, connectorId)
setIsTried(true)
}
Expand Down
7 changes: 4 additions & 3 deletions src/container/web3/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React, { ReactNode } from "react"

import { Web3ReactProvider } from "@web3-react/core"
import { useInactiveListener } from "../../hook/useActiveWeb3React"
import { getLibrary } from "../../util/getLibrary"
import { useInactiveListener } from "../../hook/useActiveWeb3React"

interface ProviderProps {
children: ReactNode | JSX.Element
}

function Web3ReactManager({ children }: ProviderProps) {
// try to eagerly connect to an injected provider, if it exists and has granted access already
// NOTE: try to eagerly connect to an injected provider, if it exists and has granted access already.
// const triedEager = useEagerConnect()

// when there's no account connected, react to logins (broadly speaking) on the injected provider, if it exists
// NOTE: when there's no account connected, react to logins (broadly speaking) on the injected provider, if it exists
// useInactiveListener(!triedEager)
useInactiveListener()

Expand Down
25 changes: 8 additions & 17 deletions src/hook/useActiveWeb3React.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useState, useEffect } from "react"
import { useEffect, useState } from "react"

import { injected } from "../connector"
import { logger } from "lib/bugsnag/logger"
import { useWeb3React as useWeb3ReactCore } from "@web3-react/core"

export function useEagerConnect() {
Expand Down Expand Up @@ -29,8 +31,8 @@ export function useEagerConnect() {
}

/**
* Use for network and injected - logs user in
* and out after checking what network theyre on
* Used for network and injected -
* logs user in and out after checking what network they are on.
*/
export function useInactiveListener(suppress = false) {
const { active, error, activate } = useWeb3ReactCore() // specifically using useWeb3React because of what this hook does
Expand All @@ -40,27 +42,16 @@ export function useInactiveListener(suppress = false) {

if (ethereum && ethereum.on && !active && !error && !suppress) {
const handleConnect = () => {
console.log("connect...")
// activate(injected, undefined, true).catch(error => {
// console.error("Failed to connect metamask")
// })
logger.info("connect...")
}

const handleChainChanged = () => {
// eat errors
console.log("chain changed...")
// activate(injected, undefined, true).catch(error => {
// console.error("Failed to activate after chain changed", error)
// })
logger.info("chain changed...")
}

const handleAccountsChanged = (accounts: string[]) => {
if (accounts.length > 0) {
// eat errors
console.log("account changed...")
// activate(injected, undefined, true).catch(error => {
// console.error("Failed to activate after accounts changed", error)
// })
logger.info("account changed...")
}
}

Expand Down
Loading

0 comments on commit f4ebcfd

Please sign in to comment.