Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
WalletConnect for xDAI (#1493)
Browse files Browse the repository at this point in the history
* provide rpc url for xDAI

* add xDAI rpc input

* hack to get around Invalid message on blockNumber calls
  • Loading branch information
Velenir authored Oct 12, 2020
1 parent c0696ec commit 193464a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/api/wallet/WalletApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export class WalletApiImpl implements WalletApi {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
provider.handleReadRequests = async function (payload: unknown): Promise<unknown> {
if (payload && typeof payload === 'object' && 'skipCache' in payload) delete payload['skipCache']
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (!this.http) {
Expand Down
16 changes: 15 additions & 1 deletion src/components/Settings/WalletConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ const WCSettingsSchema = Joi.object({
rpc: Joi.object({
mainnet: RPCSchema,
rinkeby: RPCSchema,
xDAI: RPCSchema,
}).empty({
mainnet: '',
rinkeby: '',
xDAI: '',
}),
})
.oxor('infuraId', 'rpc')
Expand Down Expand Up @@ -192,7 +194,7 @@ export const WCSettings: React.FC<WCSettingsProps> = ({ register, errors }) => {
<Disclaimer>
<p>
Here you can set the <strong>InfuraId</strong> or <strong>RPC URL</strong> that will be used for connecting
the WalletConnect provider to Mainnet and/or Rinkeby. It is also possible to set a custom WalletConnect{' '}
the WalletConnect provider to Mainnet, Rinkeby and/or xDAI. It is also possible to set a custom WalletConnect{' '}
<strong>Bridge URL</strong> to use instead of the default one.
</p>
</Disclaimer>
Expand Down Expand Up @@ -240,6 +242,18 @@ export const WCSettings: React.FC<WCSettingsProps> = ({ register, errors }) => {
<small className="inputLabel">RINKEBY </small>
</InputBox>
</InputContainer>
<InputContainer>
<InputBox>
<Input
type="text"
className="movingLabel"
name="walletconnect.rpc.xDAI"
ref={register}
placeholder="https://xdai.node_url"
/>
<small className="inputLabel">xDAI </small>
</InputBox>
</InputContainer>
</FormField>
<WCError errors={errors} name="rpc" />
</InnerFormSection>
Expand Down
13 changes: 11 additions & 2 deletions src/utils/walletconnectOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ export interface WCOptions {
rpc?: {
mainnet?: string
rinkeby?: string
xDAI?: string
}
}

const defaultRPC = {
[Network.xDAI]: 'https://rpc.xdaichain.com/',
}

export const setCustomWCOptions = (options: WCOptions): boolean => {
const optionsStr = JSON.stringify(options)
const oldStr = localStorage.getItem(STORAGE_KEY_CUSTOM_WC_OPTIONS)
Expand All @@ -32,11 +37,12 @@ export const getWCOptionsFromStorage = (): WCOptions => {
const mapStoredRpc = (rpc?: WCOptions['rpc']): IRPCMap | undefined => {
if (!rpc) return

const { mainnet, rinkeby } = rpc
const { mainnet, rinkeby, xDAI } = rpc

const rpcMap = {}
if (mainnet) rpcMap[Network.Mainnet] = mainnet
if (rinkeby) rpcMap[Network.Rinkeby] = rinkeby
if (xDAI) rpcMap[Network.xDAI] = xDAI

return rpcMap
}
Expand All @@ -46,6 +52,9 @@ export const generateWCOptions = (): IWalletConnectProviderOptions => {
return {
infuraId: infuraId || INFURA_ID,
bridge: bridge || WALLET_CONNECT_BRIDGE,
rpc: mapStoredRpc(rpc),
rpc: {
...defaultRPC,
...mapStoredRpc(rpc),
},
}
}

0 comments on commit 193464a

Please sign in to comment.