Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Account wiper (#153)
Browse files Browse the repository at this point in the history
Add `DataProvider#getStripAndMergeAccountTransaction`, a
function that makes it easier to merge accounts with no balances but
trustlines, outstanding offers, etc. Returns a transaction to strip and merge
the account into another.

Right now, the function requires an account with zeroed non-native balances. 
In the future, it could auto-path-payment all the users funds.

Other changes:

- Upgraded `stellar-sdk` to 5.0.0.
- [DataProvider] Constructor now requires a `networkPassphrase` param.
  • Loading branch information
Morley Zhi authored May 4, 2020
1 parent e26c9be commit 35cb12b
Show file tree
Hide file tree
Showing 16 changed files with 847 additions and 81 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

## In master

## [v0.1.0-rc.1](https://github.com/stellar/js-stellar-wallets/compare/v0.0.9-rc.1...v0.1.0-rc.1)

**Breaking changes**:

- Upgraded `stellar-sdk` to 5.0.0.
- [DataProvider] Constructor now requires a `networkPassphrase` param.

Other changes:

- When parsing API responses, take extra care making sure that the responses are
valid JSON, and throw if not.
- [DataProvider] Add memo information to payments.
- [DataProvider] Add `DataProvider#getStripAndMergeAccountTransaction`, a
function that makes it easier to merge accounts with no balances but
trustlines, outstanding offers, etc. Returns a transaction to strip and merge
the account into another.
- [KeyManager] Correctly handle non-successful HTTP status codes when fetching
auth tokens.
- [KeyManager] fetchAuthToken now accepts another account, if you're trying to
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/wallet-sdk",
"version": "0.0.9-rc.9",
"version": "0.1.0-rc.1",
"description": "Libraries to help you write Stellar-enabled wallets in Javascript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -9,8 +9,8 @@
"license": "Apache-2.0",
"prettier": "@stellar/prettier-config",
"peerDependencies": {
"stellar-sdk": "^3.x.x",
"bignumber.js": "*"
"bignumber.js": "*",
"stellar-sdk": "^5.x.x"
},
"scripts": {
"prepare": "yarn build ; yarn build:commonjs",
Expand Down Expand Up @@ -63,25 +63,24 @@
"jest-mock-random": "^1.0.3",
"lint-staged": "^8.1.5",
"node-localstorage": "^2.1.5",
"path": "^0.12.7",
"prettier": "^1.17.0",
"regenerator-runtime": "^0.13.3",
"sinon": "^7.3.1",
"stellar-sdk": "^3.2.0",
"stellar-sdk": "^5.0.0",
"terser-webpack-plugin": "^2.3.0",
"ts-loader": "^6.2.1",
"tsc-watch": "^2.1.2",
"tslint": "^5.14.0",
"typedoc": "^0.14.2",
"typescript": "^3.3.3333",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"path": "^0.12.7"
"webpack-cli": "^3.3.10"
},
"dependencies": {
"@ledgerhq/hw-app-str": "^4.48.0",
"@ledgerhq/hw-transport-u2f": "^4.48.0",
"@types/jest": "^24.0.11",
"@types/stellar-base": "^0.10.2",
"change-case": "^3.1.0",
"lodash": "^4.17.14",
"query-string": "^6.4.2",
Expand Down
5 changes: 3 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"private": true,
"dependencies": {
"@stellar/elements": "^0.0.0",
"big.js": "^5.2.2",
"lodash": "^4.17.14",
"moment": "^2.24.0",
"react": "^16.8.5",
"react-dom": "^16.8.5",
"react-json-view": "^1.19.1",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.1.1",
"stellar-sdk": "^2.3.0"
"stellar-sdk": "^5.0.0"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -29,6 +30,6 @@
"not op_mini all"
],
"devDependencies": {
"styled-components": "^4.2.0"
"styled-components": "^5.1.0"
}
}
10 changes: 2 additions & 8 deletions playground/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { Component } from "react";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import styled from "styled-components";
import { GlobalStyle } from "@stellar/elements";
import * as WalletSdk from "@stellar/wallet-sdk";
import StellarSdk from "stellar-sdk";
import StellarSdk, { Networks } from "stellar-sdk";

import AccountDetails from "components/AccountDetails";
import KeyEntry from "components/KeyEntry";
Expand All @@ -12,12 +11,6 @@ import Trades from "components/Trades";
import Payments from "components/Payments";
import TransferProvider from "components/TransferProvider";

const El = styled.div`
display: flex;
font-size: 0.8em;
line-height: 1.2em;
`;

class App extends Component {
state = {
dataProvider: null,
Expand All @@ -36,6 +29,7 @@ class App extends Component {
? "https://horizon-testnet.stellar.org/"
: "https://horizon.stellar.org",
accountOrKey: publicKey,
networkPassphrase: isTestnet ? Networks.TESTNET : Networks.PUBLIC,
});

this.setState({
Expand Down
28 changes: 27 additions & 1 deletion playground/src/components/AccountDetails.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React, { Component } from "react";
import Json from "react-json-view";
import { Keypair } from "stellar-sdk";

import TransactionViewer from "components/TransactionViewer";

class AccountDetails extends Component {
state = {
Expand All @@ -8,6 +11,7 @@ class AccountDetails extends Component {
updateTimes: [],
streamEnder: null,
isAccountFunded: null,
mergeTransaction: null,
};

componentDidMount() {
Expand Down Expand Up @@ -71,11 +75,33 @@ class AccountDetails extends Component {
};

render() {
const { accountDetails, err, updateTimes, isAccountFunded } = this.state;
const {
accountDetails,
err,
updateTimes,
isAccountFunded,
mergeTransaction,
} = this.state;

const handleGetTransaction = async () => {
const trans = await this.props.dataProvider.getStripAndMergeAccountTransaction(
Keypair.random().publicKey(),
);
console.log("~!!!!!!!!!!! rans: ", trans);
debugger;
this.setState({ mergeTransaction: trans });
};

return (
<div>
<h2>Account Details</h2>

<button onClick={handleGetTransaction}>Run merge command</button>

{mergeTransaction && (
<TransactionViewer transaction={mergeTransaction} />
)}

{!isAccountFunded && <p>Account isn't funded yet.</p>}
{isAccountFunded && (
<>
Expand Down
Loading

0 comments on commit 35cb12b

Please sign in to comment.