on master help sign in
Ensure wallet object always has an .address
b42c62fFang
src/bridge/Bridge.js+12−1
@@ -12,7 +12,12 @@ import { Container, Row, Col } from './components/Base'
12
12
13import { ROUTE_NAMES, router } from './lib/router'
13import { ROUTE_NAMES, router } from './lib/router'
14import { NETWORK_NAMES } from './lib/network'
14import { NETWORK_NAMES } from './lib/network'
15+import {
16+ WALLET_NAMES,
17+ DEFAULT_HD_PATH,
15−import { WALLET_NAMES, DEFAULT_HD_PATH, walletFromMnemonic } from './lib/wallet'
18+ walletFromMnemonic,
19+ addressFromSecp256k1Public
20+} from './lib/wallet'
16import { BRIDGE_ERROR } from './lib/error'
21import { BRIDGE_ERROR } from './lib/error'
17
22
18const initWeb3 = (networkType) => {
23const initWeb3 = (networkType) => {
@@ -212,6 +217,11 @@ class Bridge extends React.Component {
212 }
217 }
213
218
214 setWallet(wallet) {
219 setWallet(wallet) {
220+ if (Just.hasInstance(wallet) &&
221+ wallet.value.publicKey &&
222+ typeof wallet.value.address === 'undefined') {
223+ wallet.value.address = addressFromSecp256k1Public(wallet.value.publicKey);
224+ }
215 this.setState({ wallet })
225 this.setState({ wallet })
216 }
226 }
217
227
@@ -229,6 +239,7 @@ class Bridge extends React.Component {
229 DEFAULT_HD_PATH,
239 DEFAULT_HD_PATH,
230 urbitWallet.value.meta.passphrase
240 urbitWallet.value.meta.passphrase
231 );
241 );
242+ wallet.value.address = urbitWallet.value.ownership.keys.address;
232 }
243 }
233 this.setState({ urbitWallet, wallet })
244 this.setState({ urbitWallet, wallet })
234 }
245 }
src/bridge/components/StatelessTransaction.js+2−2
@@ -66,7 +66,7 @@ class StatelessTransaction extends React.Component {
66 const { props } = this
66 const { props } = this
67
67
68 const addr = props.wallet.matchWith({
68 const addr = props.wallet.matchWith({
69− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
69+ Just: wal => wal.value.address,
70 Nothing: () => {
70 Nothing: () => {
71 throw BRIDGE_ERROR.MISSING_WALLET
71 throw BRIDGE_ERROR.MISSING_WALLET
72 }
72 }
@@ -212,7 +212,7 @@ class StatelessTransaction extends React.Component {
212
212
213 //TODO need a lib function or something for address=, it's everywhere
213 //TODO need a lib function or something for address=, it's everywhere
214 const address = props.wallet.matchWith({
214 const address = props.wallet.matchWith({
215− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
215+ Just: wal => wal.value.address,
216 Nothing: () => {
216 Nothing: () => {
217 throw BRIDGE_ERROR.MISSING_WALLET
217 throw BRIDGE_ERROR.MISSING_WALLET
218 }
218 }
src/bridge/lib/invite.js+1−1
@@ -147,7 +147,7 @@ async function startTransactions(args) {
147 }
147 }
148 const point = realPointM.value;
148 const point = realPointM.value;
149
149
150− const inviteAddress = addressFromSecp256k1Public(inviteWallet.publicKey);
150+ const inviteAddress = inviteWallet.address;
151 console.log('working as', inviteAddress);
151 console.log('working as', inviteAddress);
152
152
153 // transfer from invite wallet to new wallet
153 // transfer from invite wallet to new wallet
src/bridge/lib/keys.js+1−1
@@ -105,7 +105,7 @@ const attemptSeedDerivation = async (next, args) => {
105 } else if (walletType === WALLET_NAMES.MNEMONIC) {
105 } else if (walletType === WALLET_NAMES.MNEMONIC) {
106
106
107 const walProxy = wallet.matchWith({
107 const walProxy = wallet.matchWith({
108− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
108+ Just: wal => wal.value.address,
109 Nothing: _ => {
109 Nothing: _ => {
110 throw BRIDGE_ERROR.MISSING_WALLET
110 throw BRIDGE_ERROR.MISSING_WALLET
111 }
111 }
src/bridge/lib/router.js+1−1
@@ -137,7 +137,7 @@ const renderRoute = (props, route) => {
137 Just: (wal) =>
137 Just: (wal) =>
138 wal.value instanceof EthereumWallet
138 wal.value instanceof EthereumWallet
139 ? (<span className="text-mono">{wal.value.address}</span>)
139 ? (<span className="text-mono">{wal.value.address}</span>)
140− : (<span className="text-mono">{addressFromSecp256k1Public(wal.value.publicKey)}</span>)
140+ : (<span className="text-mono">{wal.value.address}</span>)
141 })
141 })
142
142
143 : route === ROUTE_NAMES.MNEMONIC
143 : route === ROUTE_NAMES.MNEMONIC
src/bridge/lib/wallet.js+3−1
@@ -122,7 +122,9 @@ const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
122 let wal
122 let wal
123 try {
123 try {
124 const hd = bip32.fromSeed(sd)
124 const hd = bip32.fromSeed(sd)
125− wal = Maybe.Just(hd.derivePath(path))
125+ wal = hd.derivePath(path);
126+ wal.address = addressFromSecp256k1Public(wal.publicKey);
127+ wal = Maybe.Just(wal);
126 } catch (_) {
128 } catch (_) {
127 wal = Maybe.Nothing()
129 wal = Maybe.Nothing()
128 }
130 }
src/bridge/views/AcceptTransfer.js+1−1
@@ -15,7 +15,7 @@ class AcceptTransfer extends React.Component {
15 super(props)
15 super(props)
16
16
17 const receivingAddress = props.wallet.matchWith({
17 const receivingAddress = props.wallet.matchWith({
18− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
18+ Just: (wal) => wal.value.address,
19 Nothing: () => {
19 Nothing: () => {
20 throw BRIDGE_ERROR.MISSING_WALLET
20 throw BRIDGE_ERROR.MISSING_WALLET
21 }
21 }
src/bridge/views/CreateGalaxy.js+1−1
@@ -43,7 +43,7 @@ class CreateGalaxy extends React.Component {
43 super(props)
43 super(props)
44
44
45 const galaxyOwner = props.wallet.matchWith({
45 const galaxyOwner = props.wallet.matchWith({
46− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
46+ Just: (wal) => wal.value.address,
47 Nothing: () => {
47 Nothing: () => {
48 throw BRIDGE_ERROR.MISSING_WALLET
48 throw BRIDGE_ERROR.MISSING_WALLET
49 }
49 }
src/bridge/views/InviteTicket.js+1−1
@@ -84,7 +84,7 @@ class InviteTicket extends React.Component {
84 }
84 }
85 });
85 });
86
86
87− const addr = addressFromSecp256k1Public(inviteWallet.publicKey);
87+ const addr = inviteWallet.address;
88
88
89 const ctrcs = this.props.contracts.matchWith({
89 const ctrcs = this.props.contracts.matchWith({
90 Just: ctrcs => ctrcs.value,
90 Just: ctrcs => ctrcs.value,
src/bridge/views/InvitesSend.js+1−1
@@ -78,7 +78,7 @@ class InvitesSend extends React.Component {
78 });
78 });
79 //TODO why are we doing this locally, instead of made global on sign-in?
79 //TODO why are we doing this locally, instead of made global on sign-in?
80 this.address = this.props.wallet.matchWith({
80 this.address = this.props.wallet.matchWith({
81− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
81+ Just: (wal) => wal.value.address,
82 Nothing: () => {
82 Nothing: () => {
83 throw BRIDGE_ERROR.MISSING_WALLET;
83 throw BRIDGE_ERROR.MISSING_WALLET;
84 }
84 }
src/bridge/views/Point/Actions.js+1−1
@@ -23,7 +23,7 @@ const Actions = (props) => {
23 } = props
23 } = props
24
24
25 const addr = wallet.matchWith({
25 const addr = wallet.matchWith({
26− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
26+ Just: (wal) => wal.value.address,
27 Nothing: () => {
27 Nothing: () => {
28 throw BRIDGE_ERROR.MISSING_WALLET
28 throw BRIDGE_ERROR.MISSING_WALLET
29 }
29 }
src/bridge/views/Points.js+1−2
@@ -42,8 +42,7 @@ class Points extends React.Component {
42 web3.chain(_ =>
42 web3.chain(_ =>
43 contracts.chain(ctrcs =>
43 contracts.chain(ctrcs =>
44 wallet.chain(async wal => {
44 wallet.chain(async wal => {
45− const pub = wal.publicKey
45+ const addr = wal.address
46− const addr = addressFromSecp256k1Public(pub)
47
46
48 const points =
47 const points =
49 await azimuth.azimuth.getOwnedPoints(ctrcs, addr)
48 await azimuth.azimuth.getOwnedPoints(ctrcs, addr)
src/bridge/views/SetKeys.js+1−1
@@ -52,7 +52,7 @@ class SetKeys extends React.Component {
52 this.deriveSeed()
52 this.deriveSeed()
53
53
54 const addr = props.wallet.matchWith({
54 const addr = props.wallet.matchWith({
55− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
55+ Just: wal => wal.value.address,
56 Nothing: () => {
56 Nothing: () => {
57 throw BRIDGE_ERROR.MISSING_WALLET
57 throw BRIDGE_ERROR.MISSING_WALLET
58 }
58 }